prometheus配置说明

前面转载了一篇关于prometheus的介绍,这里介绍一下prometheus的配置,为了自己以后可以参考。

配置demo

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:
    - targets: ['localhost:9090']

  - job_name: 'linux'
    static_configs:
    - targets: ['localhost:9100']
      labels:
        instance: node1

  - job_name: 'monitor-demo-v1'
    static_configs:
    - targets: ['x.x.x.x:80']
  
  # 自动监控增减的node
  - job_name: nodes-discovery
    file_sd_configs:
      - files:
        - '/etc/prometheus/fileconfig/nodes.json'

# 远程服务地址配置
remote_write:
  - url: "http://influxdb:8086/api/v1/prom/write?db=prometheus&u=prom&p=prom"
remote_read:
  - url: "http://influxdb:8086/api/v1/prom/read?db=prometheus&u=prom&p=prom"

2.配置介绍

2.1 global配置

global配置是一个全局的配置,如果没有对每一个job(scrape_configs下的job_name项)配置,就采用全局的配置。

scrape_interval: 每隔多长时间抓去一次数据
evaluation_interval: 每隔多长时间评估一次规则

2.2 alerting告警配置

还没用到,这里暂不介绍,后续补充。

2.3 rule_files配置

还没用到,暂不介绍,后续补充

2.4 scrape_configs配置

这里配置需要从哪些目标服务器上抓取数据,job_name="prometheus"是prometheus自身的服务器,端口默认是9090,这里也可以配置抓去的间隔。

job_name=nodes-discovery是配置的自动发现增加服务器的接口。file_sd_configs表示启动prometheus的文件发现功能。也就是说,可以将配置主机等信息写入文件中,如果用户修改了配置,比如增加或删除了某些主机,那么Prometheus会自动发现这些更改而不用每次reload甚至重启。

nodes.json的内容demo如下:

[
    {
        "targets": ["192.168.1.1:9100"],
        "labels": {
            "alias": "node1",
            "job": "node"
        }
    },
    {
        "targets": ["192.168.1.2:9100"],
        "labels": {
            "alias": "node2",
            "job": "node"
        }
    }
]

2.5 远程数据库访问配置

remote_write 配置的是写的数据库地址
remote_read 配置的是读的数据库地址

参考文献

https://prometheus.io/
https://www.jianshu.com/p/413fd42ae660

你可能感兴趣的:(docker,监控系统)