Skip to content

Commit

Permalink
Add nginx_up gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
matsumana committed Mar 9, 2017
1 parent 2d7dfd1 commit e6c25ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nginx_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Exporter struct {
scrapeFailures prometheus.Counter
processedConnections *prometheus.Desc
currentConnections *prometheus.GaugeVec
nginxUp prometheus.Gauge
}

// NewExporter returns an initialized Exporter.
Expand All @@ -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},
Expand All @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit e6c25ab

Please sign in to comment.