In this blog, I’ll Walk you through how I set up a custom monitoring system for Supervisor-managed processes like Nginx and Apache2, this setup will allow you to track the health and performance of processes running under Supervisor in real time.
Table of Contents
What Is Supervisor?
Supervisor is a process control system that allows users to manage and monitor numerous processes.
Step 1 Install Supervisor
- you can install it using this command:
Step 2 Configure Supervisor for Nginx and Apache
- Once Supervisor is installed, you’ll need to create configuration files for Nginx and Apache.
For Nginx
- Create a file in this path in this format /etc/supervisor/conf.d/nginx.conf/.
One-line Summary for NGINX (Supervisor Configuration)
-
- This Supervisor configuration enables effective management of the NGINX service by running it in the foreground, ensuring automatic startup, handling unexpected failures through automatic restarts, and directing logs to specified output and error files.
For Apache
- Create another file on this path in this format /etc/supervisor/conf.d/apache2.conf.
One-line Summary for Apache (Supervisor Configuration):
- This Supervisor configuration enables effective management of the Apache service by running it in the foreground, ensuring automatic startup, handling failures through automatic restarts, and storing standard output and error logs in specified files.
Step 3 Reload Supervisor and Start Services
-
-
- Once the configurations are created, updated, we need to reload Supervisor to apply these changes and start both services.
-
Step 4 Check the Status of Nginx and Apache.
-
-
- Now check if the Supervisor is managing Nginx and Apache or not. If it does you will see the output like below.
-
-
-
- You should see output like:
-
Step 5 Create a Python Script for Monitoring with Open Telemetry and Prometheus.
-
-
- I have created a Python script to gather performance metrics of the processes under Supervisor.
-
What does this Script do?
-
-
- Monitors the status of nginx and apache2 processes.
- Collects metrics like CPU usage, memory usage, uptime, and the number of threads.
- Exposes the data in Prometheus-compatible format at http://{server_ip}:9876/metrics.
- This script automatically monitors critical processes (like nginx, apache2) using Open Telemetry.
- It collects real-time metrics such as:
-
Python Script to Export Supervisor Metrics:
I’ve developed a Python script that uses Open Telemetry to collect custom metrics from a supervisor-managed application, including:
-
-
- Process status (up/down)
- Uptime in seconds
- CPU usage in percent
-
These metrics are exposed over an HTTP endpoint in a Prometheus-compatible format.
You can find the complete script hosted on GitHub:
https://github.com/kumaribhanu/supervisor-python-script
Step 6 Install Required Libraries for Python Script.
-
-
- Now to run the script, you’ll need to install a few Python libraries.
-
Step 7 Run the Python Script
-
-
- Once the libraries are installed, run the script.
-
Step 8 Access Prometheus Metrics
-
-
- In your browser to view the live metrics of your Nginx and Apache processes.
- open the following URL in your browser.
-
http://localhost:9001/metrics .
-
-
- Replace <localhost> with the actual server IP or domain name.
- You should see output like
-
Step 9: Visualize Supervisor Metrics in Grafana
Here are some recommended metrics to visualize in Grafana, along with their explanation and benefits.
Conclusion
This Blog helps us to create a comprehensive monitoring system for Supervisor-managed processes like Nginx and Apache2 using Open Telemetry and Prometheus. By visualizing key metrics in Grafana, you can easily track the health and performance of your services in real time. This proactive monitoring helps identify and address issues such as high CPU usage, memory leaks, or downtime, ensuring that your system remains reliable and performs optimally.