[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M73C38F0RFRRV2FECTE5QTNC":3,"skill-same:01M73C38F0RFRRV2FECTE5QTNC":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":6,"updatedAt":44,"install":45,"resources":58},"01M73C38F0RFRRV2FECTE5QTNC","setup-prometheus-monitoring",null,"Configure Prometheus for time-series metrics collection, including scrape configurations, service discovery, recording rules, and federation patterns for multi-cluster deployments. Use when setting up centralized metrics collection for microservices, implementing time-series monitoring for application and infrastructure, establishing a foundation for SLO\u002FSLI tracking and alerting, or migrating from legacy monitoring solutions to a modern observability stack.","roohe\u002Fagentic-super-skills","roohe","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F99054084?v=4","01M734WCDFP6RZVT5CNM00QR26","01M734WCE4BD0T4NZS5PCV9V5F",10,"MIT","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fsetup-prometheus-monitoring\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: setup-prometheus-monitoring\nlocale: caveman-lite\nsource_locale: en\nsource_commit: 82c77053\ntranslator: \"Julius Brussee homage — caveman\"\ntranslation_date: \"2026-05-03\"\ndescription: >\n  Configure Prometheus for time-series metrics collection, including scrape\n  configurations, service discovery, recording rules, and federation patterns\n  for multi-cluster deployments. Use when setting up centralized metrics\n  collection for microservices, implementing time-series monitoring for\n  application and infrastructure, establishing a foundation for SLO\u002FSLI\n  tracking and alerting, or migrating from legacy monitoring solutions to a\n  modern observability stack.\nlicense: MIT\nallowed-tools: Read Write Edit Bash Grep Glob\nmetadata:\n  author: Philipp Thoss\n  version: \"1.0\"\n  domain: observability\n  complexity: intermediate\n  language: multi\n  tags: prometheus, monitoring, metrics, scrape, recording-rules\n---\n\n# Setup Prometheus Monitoring\n\nConfigure a production-ready Prometheus deployment with scrape targets, recording rules, and federation.\n\n## When to Use\n\n- Setting up centralized metrics collection for microservices or distributed systems\n- Implementing time-series monitoring for application and infrastructure metrics\n- Establishing a foundation for SLO\u002FSLI tracking and alerting\n- Consolidating metrics from multiple Prometheus instances via federation\n- Migrating from legacy monitoring solutions to a modern observability stack\n\n## Inputs\n\n- **Required**: List of scrape targets (services, exporters, endpoints)\n- **Required**: Retention period and storage requirements\n- **Optional**: Existing service discovery mechanism (Kubernetes, Consul, EC2)\n- **Optional**: Recording rules for pre-aggregated metrics\n- **Optional**: Federation hierarchy for multi-cluster setups\n\n## Procedure\n\n### Step 1: Install and Configure Prometheus\n\nCreate the base Prometheus configuration with global settings and scrape intervals.\n\n```bash\n# Create Prometheus directory structure\nmkdir -p \u002Fetc\u002Fprometheus\u002F{rules,file_sd}\nmkdir -p \u002Fvar\u002Flib\u002Fprometheus\n\n# Download Prometheus (adjust version as needed)\ncd \u002Ftmp\nwget https:\u002F\u002Fgithub.com\u002Fprometheus\u002Fprometheus\u002Freleases\u002Fdownload\u002Fv2.48.0\u002Fprometheus-2.48.0.linux-amd64.tar.gz\ntar xvf prometheus-2.48.0.linux-amd64.tar.gz\nsudo cp prometheus-2.48.0.linux-amd64\u002F{prometheus,promtool} \u002Fusr\u002Flocal\u002Fbin\u002F\n```\n\nCreate `\u002Fetc\u002Fprometheus\u002Fprometheus.yml`:\n\n```yaml\nglobal:\n  scrape_interval: 15s\n  scrape_timeout: 10s\n  evaluation_interval: 15s\n  external_labels:\n    cluster: 'production'\n    region: 'us-east-1'\n\n# Alertmanager configuration\nalerting:\n  alertmanagers:\n    - static_configs:\n        - targets:\n            - localhost:9093\n\n# Load recording and alerting rules\nrule_files:\n  - \"rules\u002F*.yml\"\n\n# Scrape configurations\nscrape_configs:\n  # Prometheus self-monitoring\n  - job_name: 'prometheus'\n    static_configs:\n      - targets: ['localhost:9090']\n        labels:\n          env: 'production'\n\n  # Node exporter for host metrics\n  - job_name: 'node'\n    static_configs:\n      - targets:\n          - 'node1:9100'\n          - 'node2:9100'\n        labels:\n          env: 'production'\n\n  # Application metrics with file-based service discovery\n  - job_name: 'app-services'\n    file_sd_configs:\n      - files:\n          - '\u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json'\n        refresh_interval: 30s\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: instance\n      - source_labels: [env]\n        target_label: environment\n```\n\n**Got:** Prometheus starts successfully, web UI accessible at `http:\u002F\u002Flocalhost:9090`, targets listed under Status > Targets.\n\n**If fail:**\n- Check syntax with `promtool check config \u002Fetc\u002Fprometheus\u002Fprometheus.yml`\n- Verify file permissions: `sudo chown -R prometheus:prometheus \u002Fetc\u002Fprometheus \u002Fvar\u002Flib\u002Fprometheus`\n- Check logs: `journalctl -u prometheus -f`\n\n### Step 2: Configure Service Discovery\n\nSet up dynamic target discovery to avoid manual target management.\n\nFor **Kubernetes** environments, add to `scrape_configs`:\n\n```yaml\n  - job_name: 'kubernetes-pods'\n    kubernetes_sd_configs:\n      - role: pod\n    relabel_configs:\n      # Only scrape pods with prometheus.io\u002Fscrape annotation\n      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]\n        action: keep\n        regex: true\n      # Use custom port if specified\n      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_port]\n        action: replace\n        target_label: __address__\n        regex: ([^:]+)(?::\\d+)?;(\\d+)\n        replacement: $1:$2\n      # Add namespace as label\n      - source_labels: [__meta_kubernetes_namespace]\n        target_label: kubernetes_namespace\n      # Add pod name as label\n      - source_labels: [__meta_kubernetes_pod_name]\n        target_label: kubernetes_pod_name\n```\n\nFor **file-based** service discovery, create `\u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json`:\n\n```json\n[\n  {\n    \"targets\": [\"web-app-1:8080\", \"web-app-2:8080\"],\n    \"labels\": {\n      \"job\": \"web-app\",\n      \"env\": \"production\",\n      \"team\": \"platform\"\n    }\n  },\n  {\n    \"targets\": [\"api-service-1:9090\", \"api-service-2:9090\"],\n    \"labels\": {\n      \"job\": \"api-service\",\n      \"env\": \"production\",\n      \"team\": \"backend\"\n    }\n  }\n]\n```\n\nFor **Consul** service discovery:\n\n```yaml\n  - job_name: 'consul-services'\n    consul_sd_configs:\n      - server: 'consul.example.com:8500'\n        services: []  # Empty list means discover all services\n    relabel_configs:\n      - source_labels: [__meta_consul_service]\n        target_label: job\n      - source_labels: [__meta_consul_tags]\n        regex: '.*,monitoring,.*'\n        action: keep\n```\n\n**Got:** Dynamic targets appear in Prometheus UI, automatically updated when services scale or change.\n\n**If fail:**\n- Kubernetes: Verify RBAC permissions with `kubectl auth can-i list pods --as=system:serviceaccount:monitoring:prometheus`\n- File SD: Validate JSON with `python -m json.tool \u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json`\n- Consul: Test connectivity with `curl http:\u002F\u002Fconsul.example.com:8500\u002Fv1\u002Fcatalog\u002Fservices`\n\n### Step 3: Create Recording Rules\n\nPre-aggregate expensive queries for dashboard performance and alerting efficiency.\n\nCreate `\u002Fetc\u002Fprometheus\u002Frules\u002Frecording_rules.yml`:\n\n```yaml\ngroups:\n  - name: api_aggregations\n    interval: 30s\n    rules:\n      # Calculate request rate per endpoint (5m window)\n      - record: job:http_requests:rate5m\n        expr: |\n          sum by (job, endpoint, method) (\n            rate(http_requests_total[5m])\n          )\n\n      # Calculate error rate percentage\n      - record: job:http_errors:rate5m\n        expr: |\n          sum by (job) (\n            rate(http_requests_total{status=~\"5..\"}[5m])\n          ) \u002F sum by (job) (\n            rate(http_requests_total[5m])\n          ) * 100\n\n      # P95 latency by endpoint\n      - record: job:http_request_duration_seconds:p95\n        expr: |\n          histogram_quantile(0.95,\n            sum by (job, endpoint, le) (\n              rate(http_request_duration_seconds_bucket[5m])\n            )\n          )\n\n  - name: resource_aggregations\n    interval: 1m\n    rules:\n      # CPU usage by instance\n      - record: instance:cpu_usage:ratio\n        expr: |\n          1 - avg by (instance) (\n            rate(node_cpu_seconds_total{mode=\"idle\"}[5m])\n          )\n\n      # Memory usage percentage\n      - record: instance:memory_usage:ratio\n        expr: |\n          1 - (\n            node_memory_MemAvailable_bytes \u002F node_memory_MemTotal_bytes\n          )\n\n      # Disk usage by mount point\n      - record: instance:disk_usage:ratio\n        expr: |\n          1 - (\n            node_filesystem_avail_bytes{fstype!~\"tmpfs|fuse.*\"}\n            \u002F node_filesystem_size_bytes{fstype!~\"tmpfs|fuse.*\"}\n          )\n```\n\nValidate and reload:\n\n```bash\n# Validate rules syntax\npromtool check rules \u002Fetc\u002Fprometheus\u002Frules\u002Frecording_rules.yml\n\n# Reload Prometheus configuration (without restart)\ncurl -X POST http:\u002F\u002Flocalhost:9090\u002F-\u002Freload\n\n# Or send SIGHUP signal\nsudo killall -HUP prometheus\n```\n\n**Got:** Recording rules evaluate successfully, new metrics visible in Prometheus with `job:` prefix, query performance improved for dashboards.\n\n**If fail:**\n- Check rule syntax with `promtool check rules`\n- Verify evaluation interval matches data availability\n- Check for missing source metrics: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Ftargets`\n- Review logs for evaluation errors: `journalctl -u prometheus | grep -i error`\n\n### Step 4: Configure Storage and Retention\n\nOptimize storage for retention requirements and query performance.\n\nEdit `\u002Fetc\u002Fsystemd\u002Fsystem\u002Fprometheus.service`:\n\n```ini\n[Unit]\nDescription=Prometheus Monitoring System\nDocumentation=https:\u002F\u002Fprometheus.io\u002Fdocs\u002Fintroduction\u002Foverview\u002F\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=prometheus\nGroup=prometheus\nExecStart=\u002Fusr\u002Flocal\u002Fbin\u002Fprometheus \\\n  --config.file=\u002Fetc\u002Fprometheus\u002Fprometheus.yml \\\n  --storage.tsdb.path=\u002Fvar\u002Flib\u002Fprometheus \\\n  --storage.tsdb.retention.time=30d \\\n  --storage.tsdb.retention.size=50GB \\\n  --web.console.templates=\u002Fetc\u002Fprometheus\u002Fconsoles \\\n  --web.console.libraries=\u002Fetc\u002Fprometheus\u002Fconsole_libraries \\\n  --web.listen-address=:9090 \\\n  --web.enable-lifecycle \\\n  --web.enable-admin-api\n\nRestart=always\nRestartSec=10s\n\n[Install]\nWantedBy=multi-user.target\n```\n\nKey storage flags:\n- `--storage.tsdb.retention.time=30d`: Keep 30 days of data\n- `--storage.tsdb.retention.size=50GB`: Limit storage to 50GB (whichever limit hits first)\n- `--storage.tsdb.wal-compression`: Enable WAL compression (reduces disk I\u002FO)\n- `--web.enable-lifecycle`: Allow config reload via HTTP POST\n- `--web.enable-admin-api`: Enable snapshot and delete APIs\n\nEnable and start:\n\n```bash\nsudo systemctl daemon-reload\nsudo systemctl enable prometheus\nsudo systemctl start prometheus\nsudo systemctl status prometheus\n```\n\n**Got:** Prometheus retains metrics according to policy, disk usage stays within limits, old data automatically pruned.\n\n**If fail:**\n- Monitor disk usage: `du -sh \u002Fvar\u002Flib\u002Fprometheus`\n- Check TSDB stats: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fstatus\u002Ftsdb`\n- Verify retention settings: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fstatus\u002Fruntimeinfo | jq .data.storageRetention`\n- Force cleanup: `curl -X POST http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fadmin\u002Ftsdb\u002Fdelete_series?match[]={__name__=~\".+\"}`\n\n### Step 5: Set Up Federation (Multi-Cluster)\n\nConfigure hierarchical Prometheus for aggregating metrics across clusters.\n\nOn **edge Prometheus** instances (in each cluster), ensure external labels are set:\n\n```yaml\nglobal:\n  external_labels:\n    cluster: 'production-east'\n    datacenter: 'us-east-1'\n```\n\nOn **central Prometheus** instance, add federation scrape config:\n\n```yaml\nscrape_configs:\n  - job_name: 'federate-production'\n    honor_labels: true\n    metrics_path: '\u002Ffederate'\n    params:\n      'match[]':\n        # Aggregate only pre-computed recording rules\n        - '{__name__=~\"job:.*\"}'\n        # Include alert states\n        - '{__name__=~\"ALERTS.*\"}'\n        # Include critical infrastructure metrics\n        - 'up{job=~\".*\"}'\n    static_configs:\n      - targets:\n          - 'prometheus-east.example.com:9090'\n          - 'prometheus-west.example.com:9090'\n        labels:\n          env: 'production'\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: instance\n      - source_labels: [__address__]\n        regex: 'prometheus-(.*).example.com.*'\n        target_label: cluster\n        replacement: '$1'\n```\n\nFederation best practices:\n- Use `honor_labels: true` to preserve original labels\n- Federate only recording rules and aggregates (not raw metrics)\n- Set appropriate scrape intervals (longer than edge Prometheus evaluation)\n- Use `match[]` to filter metrics (avoid federating everything)\n\n**Got:** Central Prometheus shows federated metrics from all clusters, queries can span multiple regions, minimal data duplication.\n\n**If fail:**\n- Verify federation endpoint accessibility: `curl http:\u002F\u002Fprometheus-east.example.com:9090\u002Ffederate?match[]={__name__=~\"job:.*\"} | head -20`\n- Check for label conflicts (central vs edge external labels)\n- Monitor federation lag: compare timestamp differences\n- Review match patterns: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Flabel\u002F__name__\u002Fvalues | jq .data | grep \"job:\"`\n\n### Step 6: Implement High Availability (Optional)\n\nDeploy redundant Prometheus instances with identical configurations for failover.\n\nUse **Thanos** or **Cortex** for true HA, or simple load-balanced setup:\n\n```yaml\n# prometheus-1.yml and prometheus-2.yml (identical configs)\nglobal:\n  scrape_interval: 15s\n  external_labels:\n    prometheus: 'prometheus-1'  # Different per instance\n    replica: 'A'\n\n# Use --web.external-url flag for each instance\n# prometheus-1: --web.external-url=http:\u002F\u002Fprometheus-1.example.com:9090\n# prometheus-2: --web.external-url=http:\u002F\u002Fprometheus-2.example.com:9090\n```\n\nConfigure Grafana to query both instances:\n\n```json\n{\n  \"name\": \"Prometheus-HA\",\n  \"type\": \"prometheus\",\n  \"url\": \"http:\u002F\u002Fprometheus-lb.example.com\",\n  \"jsonData\": {\n    \"httpMethod\": \"POST\",\n    \"timeInterval\": \"15s\"\n  }\n}\n```\n\nUse HAProxy or nginx for load balancing:\n\n```nginx\nupstream prometheus_backend {\n    server prometheus-1.example.com:9090 max_fails=3 fail_timeout=30s;\n    server prometheus-2.example.com:9090 max_fails=3 fail_timeout=30s;\n}\n\nserver {\n    listen 9090;\n    location \u002F {\n        proxy_pass http:\u002F\u002Fprometheus_backend;\n        proxy_set_header Host $host;\n    }\n}\n```\n\n**Got:** Query requests balanced across instances, automatic failover if one instance down, no data loss during single instance failure.\n\n**If fail:**\n- Verify both instances scraping same targets (slight time skew acceptable)\n- Check for configuration drift between instances\n- Monitor deduplication in queries (Grafana shows duplicate series)\n- Review load balancer health checks\n\n## Validation\n\n- [ ] Prometheus web UI accessible at expected endpoint\n- [ ] All configured scrape targets showing as UP in Status > Targets\n- [ ] Service discovery dynamically adding\u002Fremoving targets as expected\n- [ ] Recording rules evaluating successfully (no errors in logs)\n- [ ] Metrics retention matching configured time\u002Fsize limits\n- [ ] Federation (if configured) pulling metrics from edge instances\n- [ ] Queries returning expected metric cardinality (not excessive)\n- [ ] Disk usage stable and within allocated storage budget\n- [ ] Configuration reload working via HTTP endpoint or SIGHUP\n- [ ] Prometheus self-monitoring metrics available (up, scrape duration, etc.)\n\n## Pitfalls\n\n- **High cardinality metrics**: Avoid labels with unbounded values (user IDs, timestamps, UUIDs). Use recording rules to aggregate before storage.\n- **Scrape interval mismatch**: Recording rules should evaluate at intervals equal to or greater than scrape intervals to avoid gaps.\n- **Federation overload**: Federating all metrics creates massive data duplication. Only federate aggregated recording rules.\n- **Missing relabel configs**: Without proper relabeling, service discovery can create confusing or duplicate labels.\n- **Retention too short**: Set retention longer than your longest dashboard time window to avoid \"no data\" gaps.\n- **No resource limits**: Prometheus can consume excessive memory with high cardinality. Set `--storage.tsdb.max-block-duration` and monitor heap usage.\n- **Disabled lifecycle endpoint**: Without `--web.enable-lifecycle`, config reloads require full restarts causing scrape gaps.\n\n## Related Skills\n\n- `configure-alerting-rules` - Define alerting rules based on Prometheus metrics and route to Alertmanager\n- `build-grafana-dashboards` - Visualize Prometheus metrics with Grafana dashboards and panels\n- `define-slo-sli-sla` - Establish SLO\u002FSLI targets using Prometheus recording rules and error budget tracking\n- `instrument-distributed-tracing` - Complement metrics with distributed tracing for deeper observability\n","# Setup Prometheus Monitoring\n\nConfigure a production-ready Prometheus deployment with scrape targets, recording rules, and federation.\n\n## When to Use\n\n- Setting up centralized metrics collection for microservices or distributed systems\n- Implementing time-series monitoring for application and infrastructure metrics\n- Establishing a foundation for SLO\u002FSLI tracking and alerting\n- Consolidating metrics from multiple Prometheus instances via federation\n- Migrating from legacy monitoring solutions to a modern observability stack\n\n## Inputs\n\n- **Required**: List of scrape targets (services, exporters, endpoints)\n- **Required**: Retention period and storage requirements\n- **Optional**: Existing service discovery mechanism (Kubernetes, Consul, EC2)\n- **Optional**: Recording rules for pre-aggregated metrics\n- **Optional**: Federation hierarchy for multi-cluster setups\n\n## Procedure\n\n### Step 1: Install and Configure Prometheus\n\nCreate the base Prometheus configuration with global settings and scrape intervals.\n\n```bash\n# Create Prometheus directory structure\nmkdir -p \u002Fetc\u002Fprometheus\u002F{rules,file_sd}\nmkdir -p \u002Fvar\u002Flib\u002Fprometheus\n\n# Download Prometheus (adjust version as needed)\ncd \u002Ftmp\nwget https:\u002F\u002Fgithub.com\u002Fprometheus\u002Fprometheus\u002Freleases\u002Fdownload\u002Fv2.48.0\u002Fprometheus-2.48.0.linux-amd64.tar.gz\ntar xvf prometheus-2.48.0.linux-amd64.tar.gz\nsudo cp prometheus-2.48.0.linux-amd64\u002F{prometheus,promtool} \u002Fusr\u002Flocal\u002Fbin\u002F\n```\n\nCreate `\u002Fetc\u002Fprometheus\u002Fprometheus.yml`:\n\n```yaml\nglobal:\n  scrape_interval: 15s\n  scrape_timeout: 10s\n  evaluation_interval: 15s\n  external_labels:\n    cluster: 'production'\n    region: 'us-east-1'\n\n# Alertmanager configuration\nalerting:\n  alertmanagers:\n    - static_configs:\n        - targets:\n            - localhost:9093\n\n# Load recording and alerting rules\nrule_files:\n  - \"rules\u002F*.yml\"\n\n# Scrape configurations\nscrape_configs:\n  # Prometheus self-monitoring\n  - job_name: 'prometheus'\n    static_configs:\n      - targets: ['localhost:9090']\n        labels:\n          env: 'production'\n\n  # Node exporter for host metrics\n  - job_name: 'node'\n    static_configs:\n      - targets:\n          - 'node1:9100'\n          - 'node2:9100'\n        labels:\n          env: 'production'\n\n  # Application metrics with file-based service discovery\n  - job_name: 'app-services'\n    file_sd_configs:\n      - files:\n          - '\u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json'\n        refresh_interval: 30s\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: instance\n      - source_labels: [env]\n        target_label: environment\n```\n\n**Got:** Prometheus starts successfully, web UI accessible at `http:\u002F\u002Flocalhost:9090`, targets listed under Status > Targets.\n\n**If fail:**\n- Check syntax with `promtool check config \u002Fetc\u002Fprometheus\u002Fprometheus.yml`\n- Verify file permissions: `sudo chown -R prometheus:prometheus \u002Fetc\u002Fprometheus \u002Fvar\u002Flib\u002Fprometheus`\n- Check logs: `journalctl -u prometheus -f`\n\n### Step 2: Configure Service Discovery\n\nSet up dynamic target discovery to avoid manual target management.\n\nFor **Kubernetes** environments, add to `scrape_configs`:\n\n```yaml\n  - job_name: 'kubernetes-pods'\n    kubernetes_sd_configs:\n      - role: pod\n    relabel_configs:\n      # Only scrape pods with prometheus.io\u002Fscrape annotation\n      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]\n        action: keep\n        regex: true\n      # Use custom port if specified\n      - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_port]\n        action: replace\n        target_label: __address__\n        regex: ([^:]+)(?::\\d+)?;(\\d+)\n        replacement: $1:$2\n      # Add namespace as label\n      - source_labels: [__meta_kubernetes_namespace]\n        target_label: kubernetes_namespace\n      # Add pod name as label\n      - source_labels: [__meta_kubernetes_pod_name]\n        target_label: kubernetes_pod_name\n```\n\nFor **file-based** service discovery, create `\u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json`:\n\n```json\n[\n  {\n    \"targets\": [\"web-app-1:8080\", \"web-app-2:8080\"],\n    \"labels\": {\n      \"job\": \"web-app\",\n      \"env\": \"production\",\n      \"team\": \"platform\"\n    }\n  },\n  {\n    \"targets\": [\"api-service-1:9090\", \"api-service-2:9090\"],\n    \"labels\": {\n      \"job\": \"api-service\",\n      \"env\": \"production\",\n      \"team\": \"backend\"\n    }\n  }\n]\n```\n\nFor **Consul** service discovery:\n\n```yaml\n  - job_name: 'consul-services'\n    consul_sd_configs:\n      - server: 'consul.example.com:8500'\n        services: []  # Empty list means discover all services\n    relabel_configs:\n      - source_labels: [__meta_consul_service]\n        target_label: job\n      - source_labels: [__meta_consul_tags]\n        regex: '.*,monitoring,.*'\n        action: keep\n```\n\n**Got:** Dynamic targets appear in Prometheus UI, automatically updated when services scale or change.\n\n**If fail:**\n- Kubernetes: Verify RBAC permissions with `kubectl auth can-i list pods --as=system:serviceaccount:monitoring:prometheus`\n- File SD: Validate JSON with `python -m json.tool \u002Fetc\u002Fprometheus\u002Ffile_sd\u002Fservices.json`\n- Consul: Test connectivity with `curl http:\u002F\u002Fconsul.example.com:8500\u002Fv1\u002Fcatalog\u002Fservices`\n\n### Step 3: Create Recording Rules\n\nPre-aggregate expensive queries for dashboard performance and alerting efficiency.\n\nCreate `\u002Fetc\u002Fprometheus\u002Frules\u002Frecording_rules.yml`:\n\n```yaml\ngroups:\n  - name: api_aggregations\n    interval: 30s\n    rules:\n      # Calculate request rate per endpoint (5m window)\n      - record: job:http_requests:rate5m\n        expr: |\n          sum by (job, endpoint, method) (\n            rate(http_requests_total[5m])\n          )\n\n      # Calculate error rate percentage\n      - record: job:http_errors:rate5m\n        expr: |\n          sum by (job) (\n            rate(http_requests_total{status=~\"5..\"}[5m])\n          ) \u002F sum by (job) (\n            rate(http_requests_total[5m])\n          ) * 100\n\n      # P95 latency by endpoint\n      - record: job:http_request_duration_seconds:p95\n        expr: |\n          histogram_quantile(0.95,\n            sum by (job, endpoint, le) (\n              rate(http_request_duration_seconds_bucket[5m])\n            )\n          )\n\n  - name: resource_aggregations\n    interval: 1m\n    rules:\n      # CPU usage by instance\n      - record: instance:cpu_usage:ratio\n        expr: |\n          1 - avg by (instance) (\n            rate(node_cpu_seconds_total{mode=\"idle\"}[5m])\n          )\n\n      # Memory usage percentage\n      - record: instance:memory_usage:ratio\n        expr: |\n          1 - (\n            node_memory_MemAvailable_bytes \u002F node_memory_MemTotal_bytes\n          )\n\n      # Disk usage by mount point\n      - record: instance:disk_usage:ratio\n        expr: |\n          1 - (\n            node_filesystem_avail_bytes{fstype!~\"tmpfs|fuse.*\"}\n            \u002F node_filesystem_size_bytes{fstype!~\"tmpfs|fuse.*\"}\n          )\n```\n\nValidate and reload:\n\n```bash\n# Validate rules syntax\npromtool check rules \u002Fetc\u002Fprometheus\u002Frules\u002Frecording_rules.yml\n\n# Reload Prometheus configuration (without restart)\ncurl -X POST http:\u002F\u002Flocalhost:9090\u002F-\u002Freload\n\n# Or send SIGHUP signal\nsudo killall -HUP prometheus\n```\n\n**Got:** Recording rules evaluate successfully, new metrics visible in Prometheus with `job:` prefix, query performance improved for dashboards.\n\n**If fail:**\n- Check rule syntax with `promtool check rules`\n- Verify evaluation interval matches data availability\n- Check for missing source metrics: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Ftargets`\n- Review logs for evaluation errors: `journalctl -u prometheus | grep -i error`\n\n### Step 4: Configure Storage and Retention\n\nOptimize storage for retention requirements and query performance.\n\nEdit `\u002Fetc\u002Fsystemd\u002Fsystem\u002Fprometheus.service`:\n\n```ini\n[Unit]\nDescription=Prometheus Monitoring System\nDocumentation=https:\u002F\u002Fprometheus.io\u002Fdocs\u002Fintroduction\u002Foverview\u002F\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=prometheus\nGroup=prometheus\nExecStart=\u002Fusr\u002Flocal\u002Fbin\u002Fprometheus \\\n  --config.file=\u002Fetc\u002Fprometheus\u002Fprometheus.yml \\\n  --storage.tsdb.path=\u002Fvar\u002Flib\u002Fprometheus \\\n  --storage.tsdb.retention.time=30d \\\n  --storage.tsdb.retention.size=50GB \\\n  --web.console.templates=\u002Fetc\u002Fprometheus\u002Fconsoles \\\n  --web.console.libraries=\u002Fetc\u002Fprometheus\u002Fconsole_libraries \\\n  --web.listen-address=:9090 \\\n  --web.enable-lifecycle \\\n  --web.enable-admin-api\n\nRestart=always\nRestartSec=10s\n\n[Install]\nWantedBy=multi-user.target\n```\n\nKey storage flags:\n- `--storage.tsdb.retention.time=30d`: Keep 30 days of data\n- `--storage.tsdb.retention.size=50GB`: Limit storage to 50GB (whichever limit hits first)\n- `--storage.tsdb.wal-compression`: Enable WAL compression (reduces disk I\u002FO)\n- `--web.enable-lifecycle`: Allow config reload via HTTP POST\n- `--web.enable-admin-api`: Enable snapshot and delete APIs\n\nEnable and start:\n\n```bash\nsudo systemctl daemon-reload\nsudo systemctl enable prometheus\nsudo systemctl start prometheus\nsudo systemctl status prometheus\n```\n\n**Got:** Prometheus retains metrics according to policy, disk usage stays within limits, old data automatically pruned.\n\n**If fail:**\n- Monitor disk usage: `du -sh \u002Fvar\u002Flib\u002Fprometheus`\n- Check TSDB stats: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fstatus\u002Ftsdb`\n- Verify retention settings: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fstatus\u002Fruntimeinfo | jq .data.storageRetention`\n- Force cleanup: `curl -X POST http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Fadmin\u002Ftsdb\u002Fdelete_series?match[]={__name__=~\".+\"}`\n\n### Step 5: Set Up Federation (Multi-Cluster)\n\nConfigure hierarchical Prometheus for aggregating metrics across clusters.\n\nOn **edge Prometheus** instances (in each cluster), ensure external labels are set:\n\n```yaml\nglobal:\n  external_labels:\n    cluster: 'production-east'\n    datacenter: 'us-east-1'\n```\n\nOn **central Prometheus** instance, add federation scrape config:\n\n```yaml\nscrape_configs:\n  - job_name: 'federate-production'\n    honor_labels: true\n    metrics_path: '\u002Ffederate'\n    params:\n      'match[]':\n        # Aggregate only pre-computed recording rules\n        - '{__name__=~\"job:.*\"}'\n        # Include alert states\n        - '{__name__=~\"ALERTS.*\"}'\n        # Include critical infrastructure metrics\n        - 'up{job=~\".*\"}'\n    static_configs:\n      - targets:\n          - 'prometheus-east.example.com:9090'\n          - 'prometheus-west.example.com:9090'\n        labels:\n          env: 'production'\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: instance\n      - source_labels: [__address__]\n        regex: 'prometheus-(.*).example.com.*'\n        target_label: cluster\n        replacement: '$1'\n```\n\nFederation best practices:\n- Use `honor_labels: true` to preserve original labels\n- Federate only recording rules and aggregates (not raw metrics)\n- Set appropriate scrape intervals (longer than edge Prometheus evaluation)\n- Use `match[]` to filter metrics (avoid federating everything)\n\n**Got:** Central Prometheus shows federated metrics from all clusters, queries can span multiple regions, minimal data duplication.\n\n**If fail:**\n- Verify federation endpoint accessibility: `curl http:\u002F\u002Fprometheus-east.example.com:9090\u002Ffederate?match[]={__name__=~\"job:.*\"} | head -20`\n- Check for label conflicts (central vs edge external labels)\n- Monitor federation lag: compare timestamp differences\n- Review match patterns: `curl http:\u002F\u002Flocalhost:9090\u002Fapi\u002Fv1\u002Flabel\u002F__name__\u002Fvalues | jq .data | grep \"job:\"`\n\n### Step 6: Implement High Availability (Optional)\n\nDeploy redundant Prometheus instances with identical configurations for failover.\n\nUse **Thanos** or **Cortex** for true HA, or simple load-balanced setup:\n\n```yaml\n# prometheus-1.yml and prometheus-2.yml (identical configs)\nglobal:\n  scrape_interval: 15s\n  external_labels:\n    prometheus: 'prometheus-1'  # Different per instance\n    replica: 'A'\n\n# Use --web.external-url flag for each instance\n# prometheus-1: --web.external-url=http:\u002F\u002Fprometheus-1.example.com:9090\n# prometheus-2: --web.external-url=http:\u002F\u002Fprometheus-2.example.com:9090\n```\n\nConfigure Grafana to query both instances:\n\n```json\n{\n  \"name\": \"Prometheus-HA\",\n  \"type\": \"prometheus\",\n  \"url\": \"http:\u002F\u002Fprometheus-lb.example.com\",\n  \"jsonData\": {\n    \"httpMethod\": \"POST\",\n    \"timeInterval\": \"15s\"\n  }\n}\n```\n\nUse HAProxy or nginx for load balancing:\n\n```nginx\nupstream prometheus_backend {\n    server prometheus-1.example.com:9090 max_fails=3 fail_timeout=30s;\n    server prometheus-2.example.com:9090 max_fails=3 fail_timeout=30s;\n}\n\nserver {\n    listen 9090;\n    location \u002F {\n        proxy_pass http:\u002F\u002Fprometheus_backend;\n        proxy_set_header Host $host;\n    }\n}\n```\n\n**Got:** Query requests balanced across instances, automatic failover if one instance down, no data loss during single instance failure.\n\n**If fail:**\n- Verify both instances scraping same targets (slight time skew acceptable)\n- Check for configuration drift between instances\n- Monitor deduplication in queries (Grafana shows duplicate series)\n- Review load balancer health checks\n\n## Validation\n\n- [ ] Prometheus web UI accessible at expected endpoint\n- [ ] All configured scrape targets showing as UP in Status > Targets\n- [ ] Service discovery dynamically adding\u002Fremoving targets as expected\n- [ ] Recording rules evaluating successfully (no errors in logs)\n- [ ] Metrics retention matching configured time\u002Fsize limits\n- [ ] Federation (if configured) pulling metrics from edge instances\n- [ ] Queries returning expected metric cardinality (not excessive)\n- [ ] Disk usage stable and within allocated storage budget\n- [ ] Configuration reload working via HTTP endpoint or SIGHUP\n- [ ] Prometheus self-monitoring metrics available (up, scrape duration, etc.)\n\n## Pitfalls\n\n- **High cardinality metrics**: Avoid labels with unbounded values (user IDs, timestamps, UUIDs). Use recording rules to aggregate before storage.\n- **Scrape interval mismatch**: Recording rules should evaluate at intervals equal to or greater than scrape intervals to avoid gaps.\n- **Federation overload**: Federating all metrics creates massive data duplication. Only federate aggregated recording rules.\n- **Missing relabel configs**: Without proper relabeling, service discovery can create confusing or duplicate labels.\n- **Retention too short**: Set retention longer than your longest dashboard time window to avoid \"no data\" gaps.\n- **No resource limits**: Prometheus can consume excessive memory with high cardinality. Set `--storage.tsdb.max-block-duration` and monitor heap usage.\n- **Disabled lifecycle endpoint**: Without `--web.enable-lifecycle`, config reloads require full restarts causing scrape gaps.\n\n## Related Skills\n\n- `configure-alerting-rules` - Define alerting rules based on Prometheus metrics and route to Alertmanager\n- `build-grafana-dashboards` - Visualize Prometheus metrics with Grafana dashboards and panels\n- `define-slo-sli-sla` - Establish SLO\u002FSLI targets using Prometheus recording rules and error budget tracking\n- `instrument-distributed-tracing` - Complement metrics with distributed tracing for deeper observability\n",{"name":5,"locale":23,"license":14,"metadata":24,"translator":31,"description":32,"allowed-tools":33,"source_commit":34,"source_locale":35,"translation_date":36},"caveman-lite",{"tags":25,"author":26,"domain":27,"version":28,"language":29,"complexity":30},"prometheus, monitoring, metrics, scrape, recording-rules","Philipp Thoss","observability","1.0","multi","intermediate","Julius Brussee homage — caveman","Configure Prometheus for time-series metrics collection, including scrape configurations, service discovery, recording rules, and federation patterns for multi-cluster deployments. Use when setting up centralized metrics collection for microservices, implementing time-series monitoring for application and infrastructure, establishing a foundation for SLO\u002FSLI tracking and alerting, or migrating from legacy monitoring solutions to a modern observability stack.\n","Read Write Edit Bash Grep Glob","82c77053","en","2026-05-03","master","f483e54f3ad5f202a77d45f2e57f8d970b71195f","skills_library\u002Fsetup-prometheus-monitoring",2,"https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills","https:\u002F\u002Fgithub.com\u002Froohe","yoou.link","2026-05-19 15:56:07",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add roohe\u002Fagentic-super-skills --skill setup-prometheus-monitoring",{"tool":51,"command":52},"bunx","bunx skills add roohe\u002Fagentic-super-skills --skill setup-prometheus-monitoring",{"tool":54,"command":55},"pnpm","pnpm dlx skills add roohe\u002Fagentic-super-skills --skill setup-prometheus-monitoring","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fsetup-prometheus-monitoring\u002FSKILL.md",true,[],[60,67,74,81,88,95],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":18},"01M73D865CZME2FCMKA4PQM348","zarr-python","Chunked N-D arrays for cloud storage. Compressed arrays, parallel I\u002FO, S3\u002FGCS integration, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M73D7Z64J4ABWZJD7P44XBBF","youtube-downloader","Download and process YouTube content for research. Use when: downloading competitor videos for analysis; extracting audio for podcasts; getting transcripts for content repurposing; archiving webinars; research content curation","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyoutube-downloader\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":18},"01M73D7K8778TGZV3GJFR3703D","yc-pitch-deck","Create a compelling startup pitch deck that follows the structure proven to raise billions from top investors. Master the YC and Sequoia formats that get founders funded. Use when: **Fundraising** to create investor pitch decks; **YC application** to structure your narrative; **Demo Day prep** to craft your 2-minute pitch; **Angel investors** to communicate your opportunity; **Partnership pitches** to structure compelling asks","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyc-pitch-deck\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M73D70KJSE0E8Z28YMNNRT04","x-twitter-scraper","Use when the user needs X (Twitter) data or confirmation-gated X actions through Xquik: tweet search, user lookup, follower extraction, media download, monitoring, webhooks, MCP, SDKs, posting, likes, DMs, and profile updates. Requires a Xquik API key. Never ask for X login material.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fx-twitter-scraper\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":18},"01M73D6ED01GV077R7K4NZNFZJ","write-vignette","Create R package vignettes using R Markdown or Quarto. Covers vignette setup, YAML configuration, code chunk options, building and testing, and CRAN requirements for vignettes. Use when adding a Getting Started tutorial, documenting complex workflows spanning multiple functions, creating domain-specific guides, or when CRAN submission requires user-facing documentation beyond function help pages.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-vignette\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":18},"01M73D69YJR0BK3NFHE0CYG3EF","write-validation-documentation","Write IQ\u002FOQ\u002FPQ validation documentation for computerized systems in regulated environments. Covers protocols, reports, test scripts, deviation handling, and approval workflows. Use when validating R or other software for regulated use, preparing for a regulatory audit, documenting qualification of computing environments, or creating and updating validation protocols and reports for new or re-qualified systems.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-validation-documentation\u002FSKILL.md",[],[]]