diff --git a/README.md b/README.md index 2d5dc732824f2f8cc1e9700fbdf910bb0dbe8e23..77052723f2a5a3f6502016a085625c8a9771ccf3 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 65deb5d2201dcfa9391c4e492e6af938612f132d..3568f474fe99b20851a21e1bd6b8c507725615e2 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)