From f8d075620c452e6d454611e950610fd75ba0f4e3 Mon Sep 17 00:00:00 2001 From: dborysenko <borysenus@gmail.com> Date: Wed, 1 Nov 2017 05:19:58 -0700 Subject: [PATCH] Added cpuload metric from ExtendedStatus option Added cpuload metric. Updated readme with changes made. --- README.md | 9 ++++++--- apache_exporter.go | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2d5dc73..7705272 100644 --- a/README.md +++ b/README.md @@ -48,15 +48,17 @@ docker run -d -p 9117:9117 apache_exporter \ The exporter collects a number of statistics from the server: ``` -# HELP apache_accesses_total Current total apache accesses +# HELP apache_accesses_total Current total apache accesses (*) # TYPE apache_accesses_total counter # HELP apache_scoreboard Apache scoreboard statuses # TYPE apache_scoreboard gauge -# HELP apache_sent_kilobytes_total Current total kbytes sent +# HELP apache_sent_kilobytes_total Current total kbytes sent (*) # TYPE apache_sent_kilobytes_total counter +# HELP apache_cpu_load CPU Load (*) +# TYPE apache_cpu_load gauge # HELP apache_up Could the apache server be reached # TYPE apache_up gauge -# HELP apache_uptime_seconds_total Current uptime in seconds +# HELP apache_uptime_seconds_total Current uptime in seconds (*) # TYPE apache_uptime_seconds_total counter # HELP apache_workers Apache worker statuses # TYPE apache_workers gauge @@ -90,6 +92,7 @@ Process metrics: # TYPE process_virtual_memory_bytes gauge ``` +Metrics marked '(*)' are only available if ExtendedStatus is On in apache webserver configuration. In version 2.3.6, loading mod_status will toggle ExtendedStatus On by default. ## Author diff --git a/apache_exporter.go b/apache_exporter.go index 65deb5d..3568f47 100644 --- a/apache_exporter.go +++ b/apache_exporter.go @@ -37,6 +37,7 @@ type Exporter struct { scrapeFailures prometheus.Counter accessesTotal *prometheus.Desc kBytesTotal *prometheus.Desc + cpuload prometheus.Gauge uptime *prometheus.Desc workers *prometheus.GaugeVec scoreboard *prometheus.GaugeVec @@ -58,17 +59,22 @@ func NewExporter(uri string) *Exporter { }), accessesTotal: prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "accesses_total"), - "Current total apache accesses", + "Current total apache accesses (*)", nil, nil), kBytesTotal: prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "sent_kilobytes_total"), - "Current total kbytes sent", + "Current total kbytes sent (*)", nil, nil), + cpuload: prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: namespace, + Name: "cpuload", + Help: "The current percentage CPU used by each worker and in total by all workers combined (*)", + }), uptime: prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "uptime_seconds_total"), - "Current uptime in seconds", + "Current uptime in seconds (*)", nil, nil), workers: prometheus.NewGaugeVec(prometheus.GaugeOpts{ @@ -105,6 +111,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) { ch <- e.accessesTotal ch <- e.kBytesTotal ch <- e.uptime + e.cpuload.Describe(ch) e.scrapeFailures.Describe(ch) e.workers.Describe(ch) e.scoreboard.Describe(ch) @@ -200,6 +207,13 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error { } ch <- prometheus.MustNewConstMetric(e.kBytesTotal, prometheus.CounterValue, val) + case key == "CPULoad": + val, err := strconv.ParseFloat(v, 64) + if err != nil { + return err + } + + e.cpuload.Set(val) case key == "Uptime": val, err := strconv.ParseFloat(v, 64) if err != nil { @@ -258,6 +272,7 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error { } + e.cpuload.Collect(ch) e.workers.Collect(ch) if connectionInfo { e.connections.Collect(ch) -- GitLab