Prometheus 完全笔记-02
三 与其他监控系统对不
3.1 Prometheus vs. Zabbix
- Zabbix 使用的是 C 和 PHP, Prometheus 使用 Golang, 整体而言 Prometheus 运行速度更快一点。
- Zabbix 属于传统主机监控,主要用于物理主机、交换机、网络等监控,Prometheus 不仅适用主机监控,还适用于 Cloud、SaaS、Openstack、Container 监控。
- Zabbix 在传统主机监控方面,有更丰富的插件。
- Zabbix 可以在 WebGui 中配置很多事情,Prometheus 需要手动修改文件配置。、
3.2 Prometheus vs. Nagios
- Nagios 数据不支持自定义 Labels, 不支持查询,告警也不支持去噪、分组, 没有数据存储,如果想查询历史状态,需要安装插件。
- Nagios 是上世纪 90 年代的监控系统,比较适合小集群或静态系统的监控Nagios 太古老,很多特性都没有,Prometheus 要优秀很多。
3.3 Prometheus vs Sensu
- Sensu 广义上讲是 Nagios 的升级版本,它解决了很多 Nagios 的问题,如果你对 Nagios 很熟悉,使用 Sensu 是个不错的选择。
- Sensu 依赖 RabbitMQ 和 Redis,数据存储上扩展性更好。
3.4 Prometheus vs InfluxDB
- InfluxDB 是一个开源的时序数据库,主要用于存储数据,如果想搭建监控告警系统,需要依赖其他系统。
- InfluxDB 在存储水平扩展以及高可用方面做的更好, 毕竟核心是数据库。
四 安装部署
4.1 prometheus安装
- 二进制安装
cd /opt && wget https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz
tar -zxf prometheus-2.12.0.linux-amd64.tar.gz
mv prometheus-2.12.0.linux-amd64 prometheus
chown root.root prometheus -R
# 配置为服务
cat >/usr/lib/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 设置服务开机自启动
systemctl enable prometheus
systemctl start prometheus
# 直接启动
nohup ./prometheus --config.file=prometheus.yml 2>&1 1>prometheus.log &
# 查看服务
[root@VM_0_13_centos pushgateway]# netstat -lntup |grep prometheus
tcp6 0 0 :::9090 :::* LISTEN 16655/prometheus
- 源码编译安装
$ go get github.com/prometheus/prometheus/cmd/...
$ prometheus --config.file=your_config.yml
# 或者make build
$ mkdir -p $GOPATH/src/github.com/prometheus
$ cd $GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/prometheus.git
$ cd prometheus
$ make build
$ ./prometheus --config.file=your_config.yml
- docker安装
docker run --name prometheus -d -p 127.0.0.1:9090:9090 prom/prometheus
4.2 alertmanager安装
- 二进制安装
cd /opt && wget -c https://github.com/prometheus/alertmanager/releases/download/v0.18.0/alertmanager-0.18.0.linux-amd64.tar.gz
tar zxf alertmanager-0.18.0.linux-amd64.tar.gz
mv alertmanager-0.18.0.linux-amd64 alertmanager
chown root.root alertmanager -R
# 配置服务
cat >/usr/lib/systemd/system/alertmanager.service <<EOF
[Unit]
Description=Alertmanager
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/opt/alertmanager/alertmanager --config.file=/opt/alertmanager/alertmanager.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 设置服务开机自启动
systemctl enable alertmanager
systemctl start alertmanager
# 直接启动
nohup ./alertmanager --config.file=alertmanager.yml 2>&1 1>alertmanager.log &
# 查看服务
[root@VM_0_13_centos pushgateway]# netstat -lntup |grep alertmanager
tcp6 0 0 :::9094 :::* LISTEN 17237/alertmanager
tcp6 0 0 :::9093 :::* LISTEN 17237/alertmanager
udp6 0 0 :::9094 :::* 17237/alertmanager
- 编译安装
$ GO15VENDOREXPERIMENT=1 go get github.com/prometheus/alertmanager/cmd/...
# cd $GOPATH/src/github.com/prometheus/alertmanager
$ alertmanager --config.file=<your_file>
# 手动源码构建
$ mkdir -p $GOPATH/src/github.com/prometheus
$ cd $GOPATH/src/github.com/prometheus
$ git clone https://github.com/prometheus/alertmanager.git
$ cd alertmanager
$ make build
$ ./alertmanager --config.file=<your_file>
# amtool构建
$ make build BINARIES=amtool
- docker安装
docker pull quay.io/prometheus/alertmanager
4.3 node_export安装
利用node_export来监控主机,官方也提供了很多其他的export可以用来直接使用
- 二进制安装
cd /opt && wget -c https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar zxf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 node_exporter
chown root.root node_exporter -R
# 配置服务
cat >/usr/lib/systemd/system/node_exporter.service <<EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/opt/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 设置服务开机自启动
systemctl enable node_exporter
systemctl start node_exporter
# 直接启动
nohup ./node_exporter --config.file=node_exporter.yml 2>&1 1>node_exporter.log &
# 查看服务
[root@VM_0_13_centos pushgateway]# netstat -lntup |grep node_export
tcp6 0 0 :::9100 :::* LISTEN 4551/node_exporter
4.4 pushgateway
- 安装
cd /opt && wget -c https://github.com/prometheus/pushgateway/releases/download/v0.9.1/pushgateway-0.9.1.linux-amd64.tar.gz
tar zxf pushgateway-0.9.1.linux-amd64.tar.gz
mv pushgateway-0.9.1.linux-amd64 pushgateway
chown root.root pushgateway -R
# 配置服务
cat >/usr/lib/systemd/system/pushgateway.service <<EOF
[Unit]
Description=pushgateway
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/opt/pushgateway/pushgateway
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# 设置服务开机自启动
systemctl enable pushgateway
systemctl start pushgateway
# 直接启动
nohup ./pushgateway --config.file=node_exporter.yml 2>&1 1>node_exporter.log &
# 查看服务
[root@VM_0_13_centos pushgateway]# netstat -lntup |grep push
tcp6 0 0 :::9091 :::* LISTEN 5982/pushgateway
- 查看web页面
![image-20190826182701121](/Users/xuel/Library/Application Support/typora-user-images/image-20190826182701121.png)
- shell命令创建
echo "some_metric 3.14" | curl --data-binary @- http://localhost:9091/metrics/job/some_job
- 发送复杂数据
cat <<EOF | curl --data-binary @- http://localhost:9091/metrics/job/some_job/instance/some_instance
# TYPE some_metric counter
some_metric{label="val1"} 42
# TYPE another_metric gauge
# HELP another_metric Just an example.
another_metric 2398.283
EOF
4.5 Grafana配置
4.5.1 grafana安装
- 安装grafana
wget https://dl.grafana.com/oss/release/grafana-6.3.3-1.x86_64.rpm
sudo yum localinstall grafana-6.3.3-1.x86_64.rpm -y
systemctl enable grafana-server.service
systemctl start grafana-server.service
# web页面3000 登录信息:admin/admin
# 安装插件
grafana-cli plugins install grafana-piechart-panel
systemctl restart grafana-server
4.5.2 添加数据源
添加prometheus,填写prometheus的管理地址
![image-20190826155302403](/Users/xuel/Library/Application Support/typora-user-images/image-20190826155302403.png)
- 导入dashboard
通过https://grafana.com/grafana/dashboards中获取
- 配置dashboard
![image-20190826144058377](/Users/xuel/Library/Application Support/typora-user-images/image-20190826144058377.png)
![image-20190826150244677](/Users/xuel/Library/Application Support/typora-user-images/image-20190826150244677.png)
4.5.3 grafana告警邮件配置
- 修改grafana配置文件,添加email配置
# 修改/etc/grafana/grafana.ini
[smtp]
enabled = true
host = smtxxxxxxom:465
user = 1xxxxxxxxx
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = xxxxxxxxxxxx
;cert_file =
;key_file =
;skip_verify = false
from_address = 1xxxxxxxxxxx3316@163.com
;from_name = Grafana
;ehlo_identity = dashboard.example.com
- grafana web界面配置Notification channels
![image-20190826155540354](/Users/xuel/Library/Application Support/typora-user-images/image-20190826155540354.png)
![image-20190826155618702](/Users/xuel/Library/Application Support/typora-user-images/image-20190826155618702.png)
4…4 alter配置
⚠️:Template variables are not supported in alert queries,在查询中不能使用模版语法,不然无法创建告警
![image-20190826163837032](/Users/xuel/Library/Application Support/typora-user-images/image-20190826163837032.png)
![image-20190826164353945](/Users/xuel/Library/Application Support/typora-user-images/image-20190826164353945.png)
告警测试
![image-20190826164422146](/Users/xuel/Library/Application Support/typora-user-images/image-20190826164422146.png)
查看告警历史
![image-20190826164436089](/Users/xuel/Library/Application Support/typora-user-images/image-20190826164436089.png)
告警触发
![image-20190826165103853](/Users/xuel/Library/Application Support/typora-user-images/image-20190826165103853.png)
![image-20190826164858353](/Users/xuel/Library/Application Support/typora-user-images/image-20190826164858353.png)
- 点赞
- 收藏
- 关注作者
评论(0)