基于 CentOS 7 amd64 系统
Prometheus
- 多维数据模型(有metric名称和键值对确定的时间序列)
- 灵活的查询语言
- 不依赖分布式存储
- 通过pull方式采集时间序列,通过http协议传输
- 支持通过中介网关的push时间序列的方式
- 监控数据通过服务或者静态配置来发现
- 支持图表和dashboard等多种方式
- 组件:
- Prometheus 主程序,主要是负责存储、抓取、聚合、查询方面。
- Alertmanager 程序,主要是负责实现报警功能。
- Pushgateway 程序,主要是实现接收由Client push过来的指标数据,在指定的时间间隔,由主程序来抓取。
- node_exporter 监控远程 linux 服务器CPU、内存、磁盘、I/O等信息
生态架构图
普罗米修斯的体系结构及其一些生态系统组件
https://prometheus.io/docs/introduction/overview/

工作流程
- Prometheus 服务器定期从配置好的 jobs 或者 exporters 中获取度量数据;或者接收来自推送网关发送过来的 度量数据。
- Prometheus 服务器在本地存储收集到的度量数据,并对这些数据进行聚合;
- 运行已定义好的 alert.rules,记录新的时间序列或者向告警管理器推送警报。
- 告警管理器根据配置文件,对接收到的警报进行处理,并通过email等途径发出告警。
- Grafana等图形工具获取到监控数据,并以图形化的方式进行展示。
Client Library 提供度量的四种类型
- Counter 类型: 计数器。
- 是一个累计的指标,代表一个单调递增的计数器,它的值只会增加或在重启时重置为零。
- 一般用于记录访问数,错误数,任务数等
- Gauge 类型:计量器。
- 是代表一个数值类型的指标,它的值可以增或减
- 如CPU的负载,协程数,并发请求量,内存使用量等
- Histogram 柱状图
- 是一种累积直方图,在一段时间范围内对数据进行采样,并将其计入可配置的存储桶(bucket)中。
- 如请求持续时间或响应大小等。
- Summary 摘要
安装
prometheus提供二进制,直接解压即可用.由 go 编写
下载慢,请查看软件下载列表
官网下载
Centos 64x 选择下载 *linux-amd64.tar.gz
1
2
|
wget -c https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.darwin-amd64.tar.gz
tar -xvf prometheus-2.18.1.darwin-amd64.tar.gz -C /usr/local/
|
运行
创建 systemd 服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/usr/local/prometheus/data
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
EOF
|
刷新 systemd && 运行 && 查看
1
2
3
4
|
systemctl daemon-reload # 刷新 systemd 配置
systemctl enable prometheus # 加入开机启动
systemctl start prometheus # 启动服务
systemctl status prometheus # 查看详情
|
预览
http://localhost:9090

自带也会产生监控数据
http://192.168.61.66:9090/metrics
nginx 反向代理
htpasswd 参考
1
2
3
4
5
6
7
8
9
10
|
server {
listen 80;
server_name prome.sgfoot.com;
auth_basic "Auth";
auth_basic_user_file /usr/local/nginx/conf/vhost/htpasswd.users;
location / {
proxy_pass http://127.0.0.1:9090;
index index.html index.htm;
}
}
|
node_exporter 安装
监控远程 linux 服务器CPU、内存、磁盘、I/O等信息
下载慢,请查看软件下载列表
https://prometheus.io/download/

1
2
3
4
5
6
|
cd /usr/local/src
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.0.1.linux-amd64 node_exporter
cd node_exporter
|
运行
先创建 systemd 服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/node_exporter/node_exporter
KillMode=process
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target
EOF
|
刷新 systemd && 运行 && 查看
1
2
3
4
|
systemctl daemon-reload # 刷新 systemd 配置
systemctl enable node_exporter # 加入开机启动
systemctl start node_exporter # 启动服务
systemctl status node_exporter # 查看详情
|
预览
http://192.168.61.66:9100/metrics

添加监控节点
添加 node_exporter
1
2
3
4
5
6
7
8
|
vim /usr/local/prometheus/prometheus.yml
# 在最后一个节点 scrape_configs 下添加 job_name
# 空2个空格
- job_name: 'node' # 一定要全局唯一, 采集本机的 metrics,需要在本机安装 node_exporter
scrape_interval: 10s # 采集的间隔时间
static_configs:
- targets: ['localhost:9100'] # 本机 node_exporter 的 endpoint
|

重启服务
1
|
systemctl restart prometheus
|
浏览器上查看添加是否成功
http://192.168.61.66:9090/targets

参考
- 文档下载
- CentOS7.5 Prometheus2.5+Grafana5.4监控部署
软件下载
- node_exporter1.0.1.linux.amd64
- prometheus-2.21.0.linux.amd64