docker-compose.yml

    1. version: "3"
    2. services:
    3. prometheus:
    4. container_name: prometheus
    5. image: prom/prometheus:v2.23.0
    6. ports:
    7. - 9090:9090
    8. volumes:
    9. - ./prometheus.yml:/etc/prometheus/prometheus.yml
    10. - ./data:/prometheus

    新建 ./prometheus.yml 文件,该文件是 prometheus 的配置文件,默认配置如下:

    1. # my global config
    2. global:
    3. scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
    4. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
    5. # scrape_timeout is set to the global default (10s).
    6. # Alertmanager configuration
    7. alerting:
    8. alertmanagers:
    9. - static_configs:
    10. - targets:
    11. # - alertmanager:9093
    12. # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    13. rule_files:
    14. # - "first_rules.yml"
    15. # - "second_rules.yml"
    16. # A scrape configuration containing exactly one endpoint to scrape:
    17. # Here it's Prometheus itself.
    18. scrape_configs:
    19. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
    20. - job_name: 'prometheus'
    21. # metrics_path defaults to '/metrics'
    22. # scheme defaults to 'http'.
    23. static_configs:
    24. - targets: ['localhost:9090']

    如果要手机新的系统的监控信息,可以在 scrape_configs 下新增一个 job ,以 mysql 为例:

    1. - job_name: 'mysql8'
    2. static_configs:
    3. - targets: ['192.168.0.103:9104']

    如果 mysqld-exporter 已经把端口暴露出来的话, targets 可以填宿主机器 ip,或者与 mysqld-exporter 在同个网络下的话,可以填 mysql-exporter-network:9104

    链接:https://github.com/prometheus/mysqld_exporter