本文介绍如何安装部署并使用 Prometheus 软件。
Prometheus 安装部署
下载 Prometheus 软件。
解压并安装 Prometheus 软件。
sudo tar zxvf Prometheus-2.30.3.linux-amd64.tar.gz -C /usr/local/复制 OBAgent 生成的 Prometheus 配置文件到 Prometheus 安装目录中。
说明
OBAgent 携带了 Prometheus 配置文件的模版,使用 OBD 部署 OBAgent, 会自动填充模版中的内容。该配置文件被放在 OBAgent 安装目录下,如
/home/admin/obagent/conf/Prometheus_config/。这个配置文件可以供 Prometheus 软件直接使用。OBAgent 的安装部署,请参考 OBAgentsudo mv Prometheus_config/ /usr/local/Prometheus-2.30.3.linux-amd64/新建 Prometheus 服务文件。
sudo mkdir /var/lib/Prometheus sudo vim /etc/systemd/system/Prometheus.service [Unit] Description=Prometheus Server Documentation=https://Prometheus.io/docs/introduction/overview/ After=network-online.target [Service] Restart=on-failure ExecStart=/usr/local/Prometheus-2.30.3.linux-amd64/Prometheus --config.file=/usr/local/Prometheus-2.30.3.linux-amd64/Prometheus_config/Prometheus.yaml --storage.tsdb.path=/var/lib/Prometheus --web.enable-lifecycle --web.external-url=http://172.20.xx.xx:9090 [Install] WantedBy=multi-user.target启动 Prometheus 服务。
sudo systemctl daemon-reload sudo systemctl start Prometheus sudo systemctl status Prometheus [admin@**** ~]$ sudo systemctl status Prometheus ● Prometheus.service - Prometheus Server Loaded: loaded (/etc/systemd/system/Prometheus.service; disabled; vendor preset: disabled) Active: active (running) since Thu 2021-10-21 15:54:42 CST; 49s ago Docs: https://Prometheus.io/docs/introduction/overview/ Main PID: 902555 (Prometheus) Tasks: 13 (limit: 195588) Memory: 40.6M CGroup: /system.slice/Prometheus.service └─902555 /usr/local/Prometheus-2.30.3.linux-amd64/Prometheus --config.file=/usr/local/Prometheus-2.30.3.linux-amd64/Prometheus_config/Prometheus.yaml --storage.tsdb.path=/var/lib/Prometheus --web.enable-lifecycle --web.external-url=http://172.20.xx.xx:9090 Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.275Z caller=head.go:479 component=tsdb msg="Replaying on-disk memory mappable chunks if any" Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.275Z caller=head.go:513 component=tsdb msg="On-disk memory mappable chunks replay completed" duration=2.127µs Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.275Z caller=head.go:519 component=tsdb msg="Replaying WAL, this may take a while" Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.275Z caller=head.go:590 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0 Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.275Z caller=head.go:596 component=tsdb msg="WAL replay completed" checkpoint_replay_duration=39.378µs wal_replay_duration=185.207µs total_replay_duration=242.438µs Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.277Z caller=main.go:849 fs_type=XFS_SUPER_MAGIC Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.277Z caller=main.go:852 msg="TSDB started" Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.277Z caller=main.go:979 msg="Loading configuration file" filename=/usr/local/Prometheus-2.30.3.linux-amd64/Prometheus_config/Prometheus.yaml Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.281Z caller=main.go:1016 msg="Completed loading of configuration file" filename=/usr/local/Prometheus-2.30.3.linux-amd64/Prometheus_config/Prometheus.yaml totalDuration=4.630509ms db_storage=1> Oct 21 15:54:42 obce00 Prometheus[902555]: level=info ts=2021-10-21T07:54:42.281Z caller=main.go:794 msg="Server is ready to receive web requests."确认 Prometheus 是否启动成功。
[admin@**** ~]$ sudo netstat -ntlp | grep 9090 tcp6 0 0 :::9090 :::* LISTEN 902555/Prometheus
Prometheus 使用
查看数据库告警
使用浏览器访问:http://172.20.xx.xx:9090/alerts。
说明
此处链接中的 IP 为示例中配置 Prometheus 的服务器 IP,根据实际情况将其转换为自身配置 Prometheus 的服务器 IP。

查看节点 LOAD
使用浏览器访问:http://172.20.xx.xx:9090/graph

节点中会涉及到很多自定义的指标名,目前支持的主机监控指标名如下:
| 指标名 | Ladel | 描述 | 类型 |
|---|---|---|---|
| node_cpu_seconds_total | cpu,mode,svr_ip | CPU 时间 | counter |
| node_disk_read_bytes_total | device,svr_ip | 磁盘读取字节数 | counter |
| node_disk_read_time_seconds_total | device,svr_ip | 磁盘读取消耗总时间 | counter |
| node_disk_reads_completed_total | device,svr_ip | 磁盘读取完成次数 | counter |
| node_disk_written_bytes_total | device,svr_ip | 磁盘写入字节数 | counter |
| node_disk_write_time_seconds_total | device,svr_ip | 磁盘写入消耗总时间 | counter |
| node_disk_writes_completed_total | device,svr_ip | 磁盘写入完成次数 | counter |
| node_filesystem_avail_bytes | device,fstype,mountpoint,svr_ip | 文件系统可用大小 | gauge |
| node_filesystem_readonly | device,fstype,mountpoint,svr_ip | 文件系统是否只读 | gauge |
| node_filesystem_size_bytes | device,fstype,mountpoint,svr_ip | 文件系统大小 | gauge |
| node_load1 | svr_ip | 1 分钟平均 load | gauge |
| node_load5 | svr_ip | 5 分钟平均 load | gauge |
| node_load15 | svr_ip | 15 分钟平均 load | gauge |
| node_memory_Buffers_bytes | svr_ip | 内存 buffer 大小 | gauge |
| node_memory_Cached_bytes | svr_ip | 内存 cache 大小 | gauge |
| node_memory_MemFree_bytes | svr_ip | 内存 free 大小 | gauge |
| node_memory_MemTotal_bytes | svr_ip | 内存总大小 | gauge |
| node_network_receive_bytes_total | device,svr_ip | 网络接受总字节数 | counter |
| node_network_transmit_bytes_total | device,svr_ip | 网络发送总字节数 | counter |
| node_ntp_offset_seconds | svr_ip | NTP 时钟偏移 |