




Prometheus使用4种方法来描述监视的指标
nstance:能够接收 Prometheus Server 数据 Scrape 操作的每个网络端点( endpoint ),即为一 Job ,例如一个MySQL主从复制集群中的所有
$ tar zxf prometheus-2.25.2.linux-amd64.tar.gz -C /usr/local
$ cd /usr/local && ln -sv prometheus-2.25.2.linux-amd64 prometheus
$ cd /usr/local/prometheus && ./prometheus
$ cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit]
Description=prometheus
[Service]
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml
ExecReload=/bin/kill -HUP \$MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 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']
| 参数 | 说明 |
|---|---|
| scrape_interval | 采集数据时间间隔 |
| evaluation_interval | 评估告警规则时间间隔,默认是1分钟 |
| scrape_timeout | 采集数据超时时间,默认10秒 |
| rule_files | 指定告警规则文件 |
| scrape_configs | 配置被监控端,称为target,每个target使用job_name分组管理 |
| alerting | 配置告警服务端 |
参考文档:https://prometheus.io/docs/prometheus/latest/configuration/configuration/
| 选项 | 说明 |
|---|---|
| –config.file “/path/to/prometheus.yml” | 指定prometheus.yml配置文件路径 |
| –storage.tsdb.path “/path/to/data” | 指定监控指标数据存储的路径 |
| –storage.tsdb.retention=15d | 历史数据最大保留时间,默认15天 |
| –web.console.templates=“/path/to/consoles” | 指定控制台模板目录路径 |
| –web.console.libraries=“/path/to/consoles_libraries” | 指定控制台库目录路径 |
| –web.max-connections=512 | 设置最大同时连接数 |
| –web.external-url “http://{ip或域名}:9090” | 用于生成返回prometheus的相对和绝对链接地址, 可以在后续告警通知内容中直接点击链接地址访问Prometheus Web UI |
| –web.listen-address “0.0.0.0:9090” | Prometheus默认监控端口 |


指标格式:
{ $ tar zxf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local
$ ln -sv node_exporter-1.1.2.linux-amd64 node_exporter
$ cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network-online.target
[Service]
Type=simple
ExecStart=/opt/node_exporter/node_exporter
ExecReload=/bin/kill -HUP \$MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
$ vim prometheus.yml
...
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
- job_name: 'nodes'
static_configs:
- targets:
- '10.10.10.87:9100'



$ wget https://github.com/google/cadvisor/releases/download/v0.41.0/cadvisor
$ ./cadvisor -port=8080 &>> /var/log/cadvisor.log
$ docker pull google/cadvisor:latest
$ docker run -d \
-v /:/rootfs:ro \
-v /var/run:/var/run:rw \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-p 8080:8080 \
--detach=true \
--name cadvisor \
google/cadvisor:latest


$ vim /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm
repo_gpgcheck=0
enabled=1
gpgcheck=0
$ yum makecache
$ yum install grafana
$ systemctl start grafana-server











搜索相应的数据源

拷贝相应编号

导入grafana


