A comprehensive Bash script that monitors websites and VM hosts, collecting metrics in Prometheus format for integration with Node Exporter's textfile collector. It can also run as a standalone CLI health checker without any Prometheus setup. 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
- YAML Configuration: External config file support - no script edits needed to add/remove targets
- Parallel Execution: All checks run concurrently with configurable job limits
- CLI-Only Mode: Use
--clifor quick health checks without Prometheus - no textfile collector required - Prometheus-Compatible: Outputs metrics in standard Prometheus textfile format
- Atomic Writes: Uses temporary files for safe metric updates
- Error Handling: Strict mode (
set -Eeuo pipefail), error traps, 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)
Create a config.yaml alongside the script:
# Path where Prometheus metrics are written
textfile_path: "/opt/node_exporter/textfile_collector/combined_monitor.prom"
# Websites to monitor
websites:
- "https://example.com"
- "https://api.example.com/health"
- "http://internal.example.com:8080"
# VM hosts to monitor
vm_hosts:
- "server1.example.com"
- "192.168.1.100"
# Parallel execution settings
parallel:
max_jobs: 5Then run with:
./monitor.sh --config config.yamlIf no --config flag is provided, the script uses the built-in arrays as a fallback. Edit the DEFAULT_WEBSITES and DEFAULT_VM_HOSTS arrays directly in the script:
DEFAULT_WEBSITES=(
"https://example.com"
"https://api.example.com"
)
DEFAULT_VM_HOSTS=(
"server1.example.com"
"192.168.1.100"
)monitor.sh v2.0.0 - Prometheus website & VM host monitor
Usage:
monitor.sh [options]
Options:
-c, --config <file> Path to YAML config file
--cli CLI-only mode (skip Prometheus file output)
-h, --help Show this help
Examples:
./monitor.sh # Use hardcoded defaults
./monitor.sh --config config.yaml # Load targets from config
./monitor.sh --cli # Quick CLI health check
./monitor.sh --config config.yaml --cli # Config + CLI-only
./monitor.sh # Hardcoded defaults → Prometheus output
./monitor.sh --config config.yaml # YAML config → Prometheus output
./monitor.sh --cli # Hardcoded defaults → CLI only
./monitor.sh --config config.yaml --cli # YAML config → CLI onlyAdd to crontab for automated monitoring (runs every 5 minutes):
crontab -eAdd the following line:
*/5 * * * * /path/to/monitor.sh --config /path/to/config.yaml >/dev/null 2>&1Or for more frequent monitoring (every minute):
* * * * * /path/to/monitor.sh --config /path/to/config.yaml >/dev/null 2>&1Use --cli to run the script as a standalone health checker without any Prometheus setup:
./monitor.sh --cli
./monitor.sh --config config.yaml --cliIn this mode the script:
- Runs all website and VM host checks in parallel
- Displays UP/DOWN results on the terminal
- Skips writing the
.prommetrics file - Skips the textfile collector directory check
This makes it usable by anyone - no Prometheus or Node Exporter required.
All website and VM host checks run in parallel by default. The number of concurrent jobs is controlled by:
| Source | Setting | Default |
|---|---|---|
| Config file | parallel.max_jobs |
5 |
| Script default | MAX_PARALLEL_JOBS |
5 |
Each check runs in a background subshell with isolated output files. Console results are replayed in order after all jobs complete, so the output remains deterministic.
- 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.
