You want your script's results on Grafana dashboards without running a new service. How?
AdvancedScenarioScenarios: health checks, monitoring and alerts
Answer
Situation read → If node_exporter runs on the host, its textfile collector exposes metrics from .prom files.
What I'd do →
dir=/var/lib/node_exporter/textfile_collector
tmp=$(mktemp "$dir/.backup.prom.XXXXXX")
cat > "$tmp" <<EOF
# HELP opskit_backup_last_success_timestamp_seconds Last successful backup.
# TYPE opskit_backup_last_success_timestamp_seconds gauge
opskit_backup_last_success_timestamp_seconds $(date +%s)
# HELP opskit_backup_size_bytes Size of the last backup.
# TYPE opskit_backup_size_bytes gauge
opskit_backup_size_bytes $size
EOF
chmod 0644 "$tmp"
mv -f -- "$tmp" "$dir/opskit_backup.prom"
- Start node_exporter with
--collector.textfile.directory=/var/lib/node_exporter/textfile_collector. - Write atomically (temp file +
mv) so the exporter never reads half a file. - Alert in Prometheus:
time() - opskit_backup_last_success_timestamp_seconds > 93600.
Why → You reuse existing scraping, dashboards and alerting with a few lines of shell.
Interview tip → Mention the atomic write; partially written .prom files cause scrape errors.
More on Scenarios: health checks, monitoring and alerts
You are asked for a host health-check script covering disk, memory, systemd services and an HTTP endpoint. How do you design it?IntermediateYour disk alert fires and clears every few minutes around 80%, spamming Slack. How do you fix the alerting?AdvancedA server reports `No space left on device` but `df -h` shows 40% free. What would you add to the health checks?BeginnerAlert when any certificate under `/etc/letsencrypt/live` expires within 21 days.IntermediateA developer wrote a Bash loop that restarts the app whenever its process disappears. What do you suggest instead?IntermediateYou suspect a memory leak in a service. How do you collect evidence with a script before involving developers?Advanced