diff --git a/apache_exporter.go b/apache_exporter.go index 76f6dade688f4d54f56756c870121a4da3d3a852..65deb5d2201dcfa9391c4e492e6af938612f132d 100644 --- a/apache_exporter.go +++ b/apache_exporter.go @@ -47,30 +47,30 @@ func NewExporter(uri string) *Exporter { return &Exporter{ URI: uri, up: prometheus.NewDesc( - prometheus.BuildFQName(namespace, "", "up"), - "Could the apache server be reached", - nil, + prometheus.BuildFQName(namespace, "", "up"), + "Could the apache server be reached", + nil, + nil), + scrapeFailures: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Name: "exporter_scrape_failures_total", + Help: "Number of errors while scraping apache.", + }), + accessesTotal: prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "accesses_total"), + "Current total apache accesses", + nil, + nil), + kBytesTotal: prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "sent_kilobytes_total"), + "Current total kbytes sent", + nil, + nil), + uptime: prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "uptime_seconds_total"), + "Current uptime in seconds", + nil, nil), - scrapeFailures: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "exporter_scrape_failures_total", - Help: "Number of errors while scraping apache.", - }), - accessesTotal: prometheus.NewDesc( - prometheus.BuildFQName(namespace, "", "accesses_total"), - "Current total apache accesses", - nil, - nil), - kBytesTotal: prometheus.NewDesc( - prometheus.BuildFQName(namespace, "", "sent_kilobytes_total"), - "Current total kbytes sent", - nil, - nil), - uptime: prometheus.NewDesc( - prometheus.BuildFQName(namespace, "", "uptime_seconds_total"), - "Current uptime in seconds", - nil, - nil), workers: prometheus.NewGaugeVec(prometheus.GaugeOpts{ Namespace: namespace, Name: "workers", @@ -101,14 +101,14 @@ func NewExporter(uri string) *Exporter { } func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { - ch <- e.up - ch <- e.accessesTotal - ch <- e.kBytesTotal - ch <- e.uptime - e.scrapeFailures.Describe(ch) - e.workers.Describe(ch) - e.scoreboard.Describe(ch) - e.connections.Describe(ch) + ch <- e.up + ch <- e.accessesTotal + ch <- e.kBytesTotal + ch <- e.uptime + e.scrapeFailures.Describe(ch) + e.workers.Describe(ch) + e.scoreboard.Describe(ch) + e.connections.Describe(ch) } // Split colon separated string into two fields @@ -161,10 +161,10 @@ func (e *Exporter) updateScoreboard(scoreboard string) { func (e *Exporter) collect(ch chan<- prometheus.Metric) error { resp, err := e.client.Get(e.URI) if err != nil { - ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0) + ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0) return fmt.Errorf("Error scraping apache: %v", err) } - ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1) + ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1) data, err := ioutil.ReadAll(resp.Body) resp.Body.Close() @@ -192,21 +192,21 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error { return err } - ch <- prometheus.MustNewConstMetric(e.accessesTotal, prometheus.CounterValue, val) + ch <- prometheus.MustNewConstMetric(e.accessesTotal, prometheus.CounterValue, val) case key == "Total kBytes": val, err := strconv.ParseFloat(v, 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(e.kBytesTotal, prometheus.CounterValue, val) + ch <- prometheus.MustNewConstMetric(e.kBytesTotal, prometheus.CounterValue, val) case key == "Uptime": val, err := strconv.ParseFloat(v, 64) if err != nil { return err } - ch <- prometheus.MustNewConstMetric(e.uptime, prometheus.CounterValue, val) + ch <- prometheus.MustNewConstMetric(e.uptime, prometheus.CounterValue, val) case key == "BusyWorkers": val, err := strconv.ParseFloat(v, 64) if err != nil { diff --git a/apache_exporter_test.go b/apache_exporter_test.go index 420156bacc795cc9e02373c40f21e6ca588f8494..0eef057230d37b8d1e7872fde9183f0a74bdf798 100644 --- a/apache_exporter_test.go +++ b/apache_exporter_test.go @@ -99,10 +99,9 @@ IdleWorkers: 8 Scoreboard: _W_______K...................................................................................................................................................................................................................................................... ` - metricCountApache22 = 10 - metricCountApache24 = 12 - metricCountApache24Worker = 10 - + metricCountApache22 = 10 + metricCountApache24 = 12 + metricCountApache24Worker = 10 ) func checkApacheStatus(t *testing.T, status string, metricCount int) {