From e6c25ab28805263e8e8585e0766c07c6302869e8 Mon Sep 17 00:00:00 2001 From: Manabu Matsuzaki Date: Thu, 9 Mar 2017 14:25:47 +0900 Subject: [PATCH] Add nginx_up gauge --- nginx_exporter.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nginx_exporter.go b/nginx_exporter.go index 429b407..bdf7afb 100644 --- a/nginx_exporter.go +++ b/nginx_exporter.go @@ -35,6 +35,7 @@ type Exporter struct { scrapeFailures prometheus.Counter processedConnections *prometheus.Desc currentConnections *prometheus.GaugeVec + nginxUp prometheus.Gauge } // NewExporter returns an initialized Exporter. @@ -59,6 +60,11 @@ func NewExporter(uri string) *Exporter { }, []string{"state"}, ), + nginxUp: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "up", + Help: "Whether the nginx is up.", + }), client: &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: *insecure}, @@ -72,14 +78,17 @@ func NewExporter(uri string) *Exporter { func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { ch <- e.processedConnections e.currentConnections.Describe(ch) + e.nginxUp.Describe(ch) e.scrapeFailures.Describe(ch) } func (e *Exporter) collect(ch chan<- prometheus.Metric) error { resp, err := e.client.Get(e.URI) if err != nil { + e.nginxUp.Set(0) return fmt.Errorf("Error scraping nginx: %v", err) } + e.nginxUp.Set(1) data, err := ioutil.ReadAll(resp.Body) resp.Body.Close() @@ -163,6 +172,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { e.scrapeFailures.Collect(ch) } e.currentConnections.Collect(ch) + e.nginxUp.Collect(ch) return }