Configure Prometheus scraping, rules, and alertmanager
✓Works with OpenClaudeYou are a DevOps engineer or systems administrator. The user wants to set up Prometheus with scraping targets, recording rules, and AlertManager integration for production monitoring and alerting.
What to check first
- Verify Prometheus is installed:
prometheus --version - Check if AlertManager is installed:
alertmanager --version - Confirm port 9090 (Prometheus) and 9093 (AlertManager) are available:
netstat -tulpn | grep -E '909[03]' - Validate existing prometheus.yml:
promtool check config /etc/prometheus/prometheus.yml
Steps
- Create the main Prometheus config at
/etc/prometheus/prometheus.ymlwith global scrape interval, evaluation interval, and alertmanager address - Define scrape_configs with job_name, static_configs with targets, and scrape_interval overrides for specific jobs
- Create recording rules file at
/etc/prometheus/rules/recording_rules.ymlwith expr, for, and labels fields - Create alerting rules file at
/etc/prometheus/rules/alert_rules.ymlwith alert name, expr, for duration, and annotations - Add rule_files paths to prometheus.yml pointing to both recording and alerting rule files
- Configure AlertManager config at
/etc/prometheus/alertmanager.ymlwith global settings, route tree, and receiver definitions - Update prometheus.yml alerting section with AlertManager target:
alerting: alertmanagers: - static_configs: - targets: ['localhost:9093'] - Reload Prometheus with
promtool check configvalidation, thenkill -HUP $(pgrep prometheus)or restart the service
Code
# /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: 'production'
environment: 'prod'
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093
rule_files:
- '/etc/prometheus/rules/recording_rules.yml'
- '/etc/prometheus/rules/alert_rules.yml'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'node-exporter'
scrape_interval: 10s
static_configs:
- targets: ['localhost:9100', 'node2.example.com:9100']
relabel_configs:
- source_labels: [__address__]
target_label: instance
- job_name: 'application'
metrics_path: '/metrics'
scrape_interval: 30s
static_configs:
- targets: ['app1:8080', 'app2:8080']
---
# /etc/prometheus/rules/recording_rules
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Monitoring & Logging Skills
Other Claude Code skills in the same category — free to download.
Structured Logging
Implement structured logging (Winston, Pino)
Error Tracking
Set up error tracking (Sentry)
APM Setup
Set up Application Performance Monitoring
Log Rotation
Configure log rotation and management
Health Dashboard
Create health monitoring dashboard
Alert Rules
Configure alerting rules and notifications
Distributed Tracing
Set up distributed tracing
Metrics Collector
Implement custom metrics collection
Want a Monitoring & Logging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.