Prometheus Metrics exporter for HTTP daemons (Apache, nginx, ...) based on access log file scraping.
- Description
- Status
- Installation
- Configuration
- Running
- Docker Image
- Metrics Exposed
- Contribution
- Further Readings
httpd-exporter was written because there were no Prometheus exporters that were able to expose information from arbitrary HTTPD log files and able to handle multiple logfiles within the same instance and able to discover these log files automatically while running.
The emphasis of httpd-exporter is to expose the number of requests that returned with a certain status. Most of current exporters for Apache et al. cannot deliver this kind of metrics.
This is especially required when a Kubernetes cluster or other major Docker installations exist in production. httpd-exporter will provide an insight into the health of single HTTPD instances (aka microservices).
httpd-exporter is in Beta phase. It is running stable in a commercial Kubernetes environment. However, it cannot be regarded as mature because the project was initiated for and tested in that very specific environment only.
htppd-exporter is written in Perl. The following prerequisites apply:
- Perl V5.22 or higher (available at
/usr/bin/perl
) - Perl module JSON
- Perl module JSON::XS
- Perl module FindBin
- Perl module Cwd
- Perl module File::Basename
- Perl module Sys::Hostname
- Perl module Socket
Most of these modules shall be already installed with a default Perl installation. Please follow the links above if this is not the case.
Install httpd-exporter by cloning the Git repository:
git clone https://github.com/technicalguru/httpd-exporter
Test your installation by invoking:
<path-to-installation>/exporterd.pl --test
A successful test will produce an output similar to this:
1/12...OK
2/12...OK
3/12...OK
4/12...OK
5/12...OK
6/12...OK
7/12...OK
8/12...OK
9/12...OK
10/12...OK
11/12...OK
12/12...OK
Test Summary: 12 total, 0 failed, 12 passed
httpd-exporter requires a configuration file describing the log files to scrape and the metrics to be produced. A default configuration file
is part of the installation (exporter.conf) which you should install in directory /etc/httpd-exporter
. Edit the file then to reflect
your installation.
See the Configuration page for more details.
The following command invokes the httpd-exporter:
<path-to-installation>/exporterd.pl
The httpd-exporter will try to find your configuration file in the following order:
- The path to the file was given as argument to the script (
exporterd.pl exporter.conf
). - The path to the file is passed by environment variable
HTTPD_EXPORTER_CONFIG_FILE
. - Default location is assumed:
/etc/httpd-exporter/exporter.conf
.
httpd-exporter will fail to start when the file was not found or is not readable.
Please notice that you will need an additional HTTPD product (Apache, nginx, ...) that needs to serve the metrics file produced by the httpd-exporter at the following URL:
http://<your-host-name>:9386/metrics
Prometheus requires the following configuration to scrape the metrics:
TBD
There is a Docker image available:
The Prometheus Operator YAML for Kubernetes is available here. Install it via:
kubectl apply -f https://github.com/technicalguru/httpd-exporter/master/contrib/kubernetes/exporter.yaml
The httpd-exporter exposes the following metrics:
# TYPE http_requests_total counter
# HELP http_requests_total Counts the requests that were logged by HTTP daemon
http_requests_total{method="GET",status="2xx"} 5432 1512397393000
http_requests_total{method="GET",status="4xx"} 32 1512397393000
http_requests_total{method="GET",status="5xx"} 5 1512397393000
# TYPE http_sent_bytes counter
# HELP http_sent_bytes Number of bytes transferred as logged by HTTP daemon
http_sent_bytes{method="GET",status="2xx"} 235432 1512397393000
http_sent_bytes{method="GET",status="4xx"} 3782 1512397393000
http_sent_bytes{method="GET",status="5xx"} 4375 1512397393000
Metrics are attributed with appropriate labels as defined by the configuration file. You might require the following Prometheus expressions to query your HTTPD status:
delta(http_requests_total{status!="200"}[5m]) - returns number of requests in the last 5 minutes for each label combination that were not successful
sum(delta(http_requests_total{status!="200"}[5m])) - returns the total count of requests in the last 5 minutes that failed
Please contact @technicalguru if you want to contribute. Any improvement is highly welcome.