From cfa56bcfabaefd966f1f46a9aff789842da726c7 Mon Sep 17 00:00:00 2001 From: zhoujunhao <18853925545@163.com> Date: Fri, 13 Jul 2018 15:58:41 +0800 Subject: [PATCH] [REV] optimization function implementation --- node/nodem/healthy/health_manager.go | 7 +++++-- worker/monitor/collector/collector.go | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/node/nodem/healthy/health_manager.go b/node/nodem/healthy/health_manager.go index b9250d2d3..fabb92d87 100644 --- a/node/nodem/healthy/health_manager.go +++ b/node/nodem/healthy/health_manager.go @@ -22,8 +22,8 @@ import "github.com/goodrain/rainbond/node/nodem/controller" //Manager Manager type Manager interface { - GetServiceHeadthy(serviceName string) *ServiceHealth - WatchServiceHeadthy() <-chan *ServiceHealth + GetServiceHealthy(serviceName string) *ServiceHealth + WatchServiceHealthy() <-chan *ServiceHealth Start() error AddServices([]*controller.Service) error Stop() error @@ -31,4 +31,7 @@ type Manager interface { //ServiceHealth ServiceHealth type ServiceHealth struct { + + } + diff --git a/worker/monitor/collector/collector.go b/worker/monitor/collector/collector.go index 02fa07ebe..d708ccdc0 100644 --- a/worker/monitor/collector/collector.go +++ b/worker/monitor/collector/collector.go @@ -43,9 +43,9 @@ type Exporter struct { workerUp prometheus.Gauge dbmanager db.Manager statusManager *status.AppRuntimeSyncClient - healthStatus prometheus.Gauge - taskNum prometheus.Gauge - taskError prometheus.Gauge + healthStatus *prometheus.GaugeVec + taskNum prometheus.Counter + taskError prometheus.Counter } var scrapeDurationDesc = prometheus.NewDesc( @@ -54,6 +54,12 @@ var scrapeDurationDesc = prometheus.NewDesc( []string{"collector"}, nil, ) +var healthDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "exporter", "health_status"), + "health status.", + []string{"service_name"}, nil, +) + //Describe Describe func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { metricCh := make(chan prometheus.Metric) @@ -132,9 +138,9 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) { } else { val = 0 } - ch <- prometheus.MustNewConstMetric(e.healthStatus.Desc(), prometheus.GaugeValue, val) - ch <- prometheus.MustNewConstMetric(e.taskNum.Desc(), prometheus.GaugeValue, discover.TaskNum) - ch <- prometheus.MustNewConstMetric(e.taskError.Desc(), prometheus.GaugeValue, discover.TaskError) + ch <- prometheus.MustNewConstMetric(healthDesc, prometheus.GaugeValue, val, "service_name.worker") + ch <- prometheus.MustNewConstMetric(e.taskNum.Desc(), prometheus.CounterValue, discover.TaskNum) + ch <- prometheus.MustNewConstMetric(e.taskError.Desc(), prometheus.CounterValue, discover.TaskError) } var namespace = "app_resource" @@ -175,19 +181,19 @@ func New(statusManager *status.AppRuntimeSyncClient) *Exporter { Name: "appfs", Help: "tenant service fs used.", }, []string{"tenant_id", "service_id", "volume_type"}), - healthStatus: prometheus.NewGauge(prometheus.GaugeOpts{ + healthStatus: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Subsystem: "exporter", Name: "worker_health_status", Help: "worker component health status.", - }), - taskNum: prometheus.NewGauge(prometheus.GaugeOpts{ + }, []string{"service_name"}), + taskNum: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Subsystem: "exporter", Name: "worker_task_number", Help: "worker total number of tasks.", }), - taskError: prometheus.NewGauge(prometheus.GaugeOpts{ + taskError: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, Subsystem: "exporter", Name: "worker_task_error",