docker安装Prometheus

1、创建配置挂载目录
mkdir prometheus
chmod 777 -R prometheus
2、创建编辑配置文件
cd prometheus
touch prometheus.yml
vim prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s

  external_labels:
    cluster_name: 'promtheus'

rule_files:
- "/etc/prometheus/promgen.rule.yml"

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - alertmanager:9093

scrape_configs:
  - job_name: 'promgen'
    file_sd_configs:
      - files:
        - "/etc/prometheus/promgen.json"

  - job_name: 'blackbox'
    metrics_path: /probe
    params:
    file_sd_configs:
      - files:
        - "/etc/prometheus/blackbox.json"
    relabel_configs:
      - source_labels: [__address__]
        regex: (.*)(:80)?
        target_label: __param_target
        replacement: ${1}
      - source_labels: [__param_target]
        regex: (.*)
        target_label: instance
        replacement: ${1}
      - source_labels: []
        regex: .*
        target_label: __address__

创建编辑抓取配置json文件
touch promgen.json
vim promgen.json

[
    {
        "labels": {
            "__farm_source": "promgen",
            "__metrics_path__": "/metrics",
            "__shard": "Default",
            "farm": "hosts",
            "job": "node-exporter",
            "project": "test-project",
            "service": "test-service"
        },
        "targets": [
            "192.168.188.128:9100",
            "192.168.188.130:9100"
        ]
    }
]


安装运行

docker run --name prometheus --rm -d --net=host -v $(pwd)/prometheus:/etc/prometheus:rw  prom/prometheus:latest

你可能感兴趣的:(运维实例汇总)