Prometheus
介绍
Prometheus 是一个监控系统和时序数据库,是一个云原生计算基金会项目,是一个系统和服务监控系统。它以给定的间隔从配置的目标收集指标,评估规则表达式,显示结果,并可以在观察到指定条件时触发警报。
Prometheus与其他监控标准和监控系统的区别在于:
1、多维数据模型
2、PromQL,一种强大而灵活的查询语言,可以利用这种维度
3、不依赖分布式存储;单个服务器节点是可以的
4、时间序列采集的HTTP拉取模型
5、通过批处理作业的中间网关支持推送时间序列
6、通过服务发现或静态配置发现目标
7、支持多种绘图和仪表板模式
8、支持分层和横向联合
部署和配置prometheus
[root@prometheus-72 ~]# cd /opt/src/
# 下载不成功,可以使用浏览器下载,或者多线程下载器。https://prometheus.io/download/
[root@prometheus-72 src]# wget https://github.com/prometheus/prometheus/releases/download/v2.22.0-rc.0/prometheus-2.22.0-rc.0.linux-amd64.tar.gz
[root@prometheus-72 src]# tar -xf prometheus-2.22.0-rc.0.linux-amd64.tar.gz -C /opt/release/
[root@prometheus-72 src]# ln -s /opt/release/prometheus-2.22.0-rc.0.linux-amd64 /opt/apps/prometheus
[root@prometheus-72 ~]# vim /opt/apps/prometheus/prometheus.yml # 主配置文件
global:
# 采集周期
scrape_interval: 60s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
# prometheus 自身监控
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# node_exporter 监控数据采集
- job_name: 'node'
static_configs:
- targets:
- "10.4.7.72:9100"
relabel_configs:
- source_labels: [__address__]
regex: (.+):[0-9]+
target_label: host
[root@prometheus-72 ~]# /opt/apps/prometheus/promtool check config /opt/apps/prometheus/prometheus.yml # 检查配置文件
Checking /opt/apps/prometheus/prometheus.yml
SUCCESS: 0 rule files found
[root@prometheus-72 ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus service
# 如果该机器上部署了时间同步服务或者ntp脚本,不太建议设置开机自启动
# 非常容易出现 Error on ingesting samples that are too old or are too far into the future
After=network.target ntpdate.service sntp.service ntpd.service chronyd.service
[Service]
User=prometheus
Group=prometheus
KillMode=control-group
Restart=on-failure
RestartSec=60
ExecStart=/opt/apps/prometheus/prometheus --config.file=/opt/apps/prometheus/prometheus.yml --web.console.templates=/opt/apps/prometheus/consoles --web.console.libraries=/opt/apps/prometheus/console_libraries --storage.tsdb.path=/data/prometheus --log.level=info
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@prometheus-72 ~]# systemctl daemon-reload
[root@prometheus-72 ~]# systemctl start prometheus.service .
[root@prometheus-72 ~]# systemctl enable prometheus.service