mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
perf: change monitor
This commit is contained in:
parent
15eefd4ce0
commit
aebdf832d9
@ -120,7 +120,7 @@ jobs:
|
||||
DOMESTIC_NAMESPACE: ${{ secrets.DOMESTIC_NAMESPACE }}
|
||||
VERSION: ${{ github.event.client_payload.version }}
|
||||
run: |
|
||||
git clone -b release-2.1 ${{ github.event.client_payload.clone_url }}/rainbond-operator.git
|
||||
git clone -b ${{ secrets.OPERATOR_BRANCH }} ${{ github.event.client_payload.clone_url }}/rainbond-operator.git
|
||||
cd rainbond-operator
|
||||
chmod +x ./release.sh
|
||||
./release.sh
|
||||
|
70
node/monitor/monitor.go
Normal file
70
node/monitor/monitor.go
Normal file
@ -0,0 +1,70 @@
|
||||
package monitor
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var healthStatus float64
|
||||
|
||||
// Metric name parts.
|
||||
const (
|
||||
// Namespace for all metrics.
|
||||
namespace = "node"
|
||||
// Subsystem(s).
|
||||
exporter = "exporter"
|
||||
)
|
||||
|
||||
//Exporter collects builder metrics. It implements prometheus.Collector.
|
||||
type Exporter struct {
|
||||
test prometheus.Counter
|
||||
}
|
||||
|
||||
var healthDesc = prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, exporter, "health_status"),
|
||||
"node service health status.",
|
||||
[]string{"service_name"}, nil,
|
||||
)
|
||||
|
||||
//NewExporter new a exporter
|
||||
func NewExporter() *Exporter {
|
||||
return &Exporter{
|
||||
test: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "test",
|
||||
Subsystem: "test",
|
||||
Name: "test",
|
||||
Help: "get and counter",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
//Describe implements prometheus.Collector.
|
||||
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
||||
e.test.Describe(ch)
|
||||
metricCh := make(chan prometheus.Metric)
|
||||
doneCh := make(chan struct{})
|
||||
go func() {
|
||||
for m := range metricCh {
|
||||
ch <- m.Desc()
|
||||
}
|
||||
close(doneCh)
|
||||
}()
|
||||
|
||||
e.Collect(metricCh)
|
||||
close(metricCh)
|
||||
<-doneCh
|
||||
}
|
||||
|
||||
// Collect implements prometheus.Collector.
|
||||
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
e.scrape(ch)
|
||||
}
|
||||
|
||||
func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
|
||||
e.test.Add(1)
|
||||
e.test.Collect(ch)
|
||||
ch <- prometheus.MustNewConstMetric(healthDesc, prometheus.GaugeValue, healthStatus, "node")
|
||||
}
|
||||
|
||||
func ChangeHealthStatus(isStatus float64) {
|
||||
healthStatus = isStatus
|
||||
}
|
Loading…
Reference in New Issue
Block a user