A comprehensive Bash script that monitors websites and VM hosts, collecting metrics in Prometheus format for integration with Node Exporter's textfile collector. This tool provides real-time monitoring of website availability, SSL certificate health, response times, and VM host connectivity.
- Availability Check: Monitors website uptime with HTTP status code validation
- Response Time: Measures website response time in seconds
- SSL Certificate Monitoring:
- Validates SSL certificate validity
- Tracks days until certificate expiration
- Detects TLS version in use
- HTTP Status Codes: Captures and reports HTTP response codes
- Follow Redirects: Automatically follows HTTP redirects (3xx)
- Ping Connectivity: Tests host reachability using ICMP ping
- Response Time: Measures average ping response time
- Prometheus-Compatible: Outputs metrics in standard Prometheus textfile format
- Atomic Writes: Uses temporary files for safe metric updates
- Error Handling: Graceful error handling and dependency checking
- Metadata Metrics: Includes monitoring run timestamps and target counts
The script automatically checks for and requires the following tools:
- curl: For HTTP/HTTPS website checks
- openssl: For SSL certificate validation and TLS version detection
- ping: For VM host connectivity testing
- bc: For mathematical calculations (response time conversions)
Edit the WEBSITES array in the script
WEBSITES=(
"https://example.com"
"https://api.example.com"
"http://internal.example.com"
"https://example.com/specific/endpoint"
)Edit the VM_HOSTS array in the script (lines 21-39):
VM_HOSTS=(
"server1.example.com"
"192.168.1.100"
"api-server.internal"
)Modify the TEXTFILE_PATH variable (line 7) to match your Node Exporter configuration:
TEXTFILE_PATH="/opt/node_exporter/textfile_collector/combined_monitor.prom"Run the script manually:
./monitor.shAdd to crontab for automated monitoring (runs every 5 minutes):
crontab -eAdd the following line:
*/5 * * * * /path/to/monitor.sh >/dev/null 2>&1Or for more frequent monitoring (every minute):
* * * * * /path/to/monitor.sh >/dev/null 2>&1- Install Node Exporter (if not already installed)
- Configure Node Exporter to use the textfile collector:
Edit
/etc/systemd/system/node_exporter.serviceor your Node Exporter configuration:
[Service]
ExecStart=/usr/local/bin/node_exporter \
--collector.textfile.directory=/opt/node_exporter/textfile_collector \
--collector.textfile- Verify metrics are being collected:
curl http://localhost:9100/metrics | grep website_
curl http://localhost:9100/metrics | grep vm_host_Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
