From 0a1e5eb67c761634bb0cab46ceac04517c6db99b Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Wed, 9 Feb 2022 09:03:42 +0100 Subject: [PATCH] Use coded name for exporter names --- web/services/hosts.go | 8 +++++++- web/services/prometheus.go | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web/services/hosts.go b/web/services/hosts.go index 4032b35a6..4027b52b6 100644 --- a/web/services/hosts.go +++ b/web/services/hosts.go @@ -243,7 +243,13 @@ func (s *hostsService) GetExportersState(hostname string) (map[string]bool, erro } for _, r := range resultVector { - jobsState[string(r.Metric["job"])] = (int(r.Value) == 1) + var name string + if _, ok := r.Metric["exporter_name"]; ok { + name = string(r.Metric["exporter_name"]) + } else { + name = string(r.Metric["job"]) + } + jobsState[name] = (int(r.Value) == 1) } return jobsState, nil diff --git a/web/services/prometheus.go b/web/services/prometheus.go index b6a14921a..cb9a57f42 100644 --- a/web/services/prometheus.go +++ b/web/services/prometheus.go @@ -14,7 +14,10 @@ import ( prometheusModel "github.com/prometheus/common/model" ) -const nodeExporterPort = 9100 +const ( + nodeExporterPort = 9100 + nodeExporterName = "Node Exporter" +) //go:generate mockery --name=PrometheusService --inpackage --filename=prometheus_mock.go type PrometheusService interface { @@ -46,6 +49,7 @@ func (p *prometheusService) GetHttpSDTargets() (models.PrometheusTargetsList, er Labels: map[string]string{ "agentID": host.AgentID, "hostname": host.Name, + "exporter_name": nodeExporterName, }, } targetsList = append(targetsList, targets)