Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Red Hat / CentOS / Fedora – Apache – Prometheus Metrics

Posted on April 1, 2021August 17, 2024 By David Kittell

Guides followed:

  1. https://machineperson.github.io/monitoring/2016/01/04/exporting-apache-metrics-to-prometheus.html
  2. https://www.shellhacks.com/prometheus-apache-exporter-install-config-ubuntu-centos/

Apache Server Status
Apache Server Status
Prometheus Endpoint
Prometheus Endpoint

# Guides followed:
#      https://machineperson.github.io/monitoring/2016/01/04/exporting-apache-metrics-to-prometheus.html
#      https://www.shellhacks.com/prometheus-apache-exporter-install-config-ubuntu-centos/

# Install the needed packages
sudo yum install golang git httpd

# Create the needed environment for GOLang
mkdir ~/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

# Refresh your bash
source ~/.bashrc

# Create apache_exporter user
sudo useradd apache_exporter -s /sbin/nologin

# Create Apache Location
declare apache_exporter=$(cat <<EOF
ExtendedStatus on
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
EOF
)
echo "$apache_exporter"
echo -e "$apache_exporter"|sudo tee /etc/httpd/conf.d/server-status.conf

# Restart Apache
sudo systemctl restart httpd

# Validate Page
curl http://127.0.0.1/server-status

# Install the Apache exporter
go get -v github.com/Lusitaniae/apache_exporter

# sudo ln -s ~/go/bin/apache_exporter /usr/bin
sudo cp ~/go/bin/apache_exporter /usr/sbin/

# Create the service file
declare apache_exporter_service=$(cat <<EOF
[Unit]
Description=Apache Exporter

[Service]
User=apache_exporter
EnvironmentFile=/etc/sysconfig/apache_exporter
ExecStart=/usr/sbin/apache_exporter $OPTIONS

[Install]
WantedBy=multi-user.target
EOF
)
echo "$apache_exporter_service"
echo -e "$apache_exporter_service"|sudo tee /etc/systemd/system/apache_exporter.service

# Create sysconfig
sudo mkdir -p /etc/sysconfig
echo "OPTIONS=\"-scrape_uri='http://127.0.0.1/server-status/?auto'\"" | sudo tee /etc/sysconfig/apache_exporter

# OPTIONAL: Get all available options of the apache_exporter
# /usr/sbin/apache_exporter --help

# Reload the systemd
sudo systemctl daemon-reload

# Enable the new service
sudo systemctl enable apache_exporter.service

# Start the new service
sudo systemctl start apache_exporter.service

# Get status of the new service
sudo systemctl status apache_exporter.service

# View raw Prometheus metrics
curl http://localhost:9117/metrics

Originally Posted on April 1, 2021
Last Updated on August 17, 2024
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

CentOS Code Fedora Prometheus Red Hat UNIX UNIX Shell Scripts

Post navigation

Previous post
Next post

Related Posts

PowerShell – Azure – Get Certificate List

Posted on April 8, 2016April 8, 2016

Working in Azure creating VMs with certificates it’s helpful to know what you have. function Get-AzureCertificates { $i = 1 $array= @() foreach ( $item in (Get-AzureService | Select ServiceName) ) { $Certs = Get-AzureCertificate -ServiceName $item.ServiceName foreach($Cert in $Certs) { $Object = New-Object System.Object $Object | Add-Member -Type NoteProperty…

Read More

LDIF Help

Posted on July 25, 2013October 26, 2015

LDIF Directory Exchange General Parameters ================== -i Turn on Import Mode (The default is Export) -f filename Input or Output filename -s servername The server to bind to (Default to DC of computer’s domain) -c FromDN ToDN Replace occurences of FromDN to ToDN -v Turn on Verbose Mode -j path…

Read More

Compare Number Array Against Column

Posted on February 23, 2015October 26, 2015

I recently needed to see what zip codes in Michigan were missing from a table of zip codes that I have in a database. First I had to get an official list of zip codes for Michigan then came up with this script to figure out which of the official…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes
 

Loading Comments...
 

You must be logged in to post a comment.