开源的系统监控工具
。根据配置的任务(job)以http/s周期性的收刮scrape/pull)指定目标(target)上的指标(metric)。目标(target)可以以静态方式或者自动发现方式指定。Prometheus将收刮(scrape)的指标(metric)保存在本地或者远程存储上
。Prometheus官网
Go语言
编写的,这使得它们很容易以二进制文件的形式构建和部署。配置共分为三部分,分别是全局配置、告警配置、收集数据配置
vim /usr/local/prometheus/prometheus.yml
#全局配置
global:
scrape_interval: 15s #每隔15秒向目标抓取一次数,默认为一分钟
evaluation_interval: 15s #每隔15秒执行一次告警规则,默认为一分钟
# scrape_timeout: 600s #抓取数据的超时时间,默认为10s
#告警配置
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093 #alertmanager所部署机器的ip和端口
#定义告警规则和阈值的yml文件
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
#收集数据配置
#以下是Prometheus自身的一个配置.
scrape_configs:
#这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:"prometheus"}的标签.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs: #静态配置
- targets: ["localhost:9090"]
环境说明
主机 | IP |
---|---|
master | 192.168.129.135 |
slave | 192.168.129.136 |
提供安装包
prometheus-2.31.1.linux-amd64.tar.gz
//安装go语言
[root@master ~]# yum -y install go
[root@master ~]# go version
go version go1.16.7 linux/amd64
//解压
[root@master src]# ls
debug kernels
[root@master src]# ls
debug kernels prometheus-2.31.1.linux-amd64.tar.gz
[root@master src]# tar xf prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/
[root@master src]# ls /usr/local/
bin etc games include lib lib64 libexec prometheus-2.31.1.linux-amd64 sbin share src
//创建软连接
[root@master src]# ln -s /usr/local/prometheus-2.31.1.linux-amd64/ prometheus
[root@master src]# ls /usr/local/
bin games lib libexec prometheus-2.31.1.linux-amd64 share
etc include lib64 prometheus sbin src
//启动
[root@master src]# /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
//设置开机自启
[root@master ~]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=The Prometheus Server
After=network.target
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
ExecStop=/bin/kill -HUP $MAINPID
RestartSec=15s
[Install]
WantedBy=multi-user.target
[root@master ~]# systemctl daemon-reload
[root@master ~]# systemctl enable --now prometheus
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /usr/lib/systemd/system/prometheus.service.
[root@master ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 [::]:22 [::]:*
验证
浏览器打开IP:9090端口即可打开普罗米修斯自带的监控页面
提供安装包
node_exporter-1.3.0.linux-amd64.tar.gz
//解压
[root@slave ~]# /usr/src/
[root@slave src]# ls
debug kernels node_exporter-1.3.0.linux-amd64.tar.gz
[root@p2 src]# tar xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/
//创建软连接
[root@p2 src]# ln -s /usr/local/node_exporter-1.3.0.linux-amd64/ node_exporter
[root@p2 src]# ls /usr/local/
bin games lib libexec node_exporter-1.3.0.linux-amd64 share
etc include lib64 node_exporter sbin src
//启动
[root@slave ~]# /usr/local/node_exporter/node_exporter
ts=2021-11-25T14:30:06.826Z caller=node_exporter.go:182 level=info msg="Starting node_exporter" version="(version=1.3.0, branch=HEAD, revision=c65f870ef90a4088210af0319498b832360c3366)"
ts=2021-11-25T14:30:06.826Z caller=node_exporter.go:183 level=info msg="Build context" build_context="(go=go1.17.3, user=root@4801f8f250a6, date=20211118-16:34:14)"
//设置开机自启
[root@slave ~]# vim /etc/systemd/system/node_exporter.service
[unit]
Description=The node_exporter Server
After=network.target
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
RestartSec=15s
SyslogIdentifier=node_exporter
[Install]
WantedBy=multi-user.target
//重新加载
[root@slave ~]# systemctl daemon-reload
[root@slave ~]# systemctl enable --now node_exporter
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /etc/systemd/system/node_exporter.service.
//查看状态
[root@slave ~]# systemctl status node_exporter
● node_exporter.service
Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2021-11-25 22:34:49 CST; 1min 38s ago
Main PID: 65492 (node_exporter)
Tasks: 4 (limit: 11300)
Memory: 8.7M
CGroup: /system.slice/node_exporter.service
└─65492 /usr/local/node_exporter/node_exporter
11月 25 22:34:49 slave node_exporter[65492]: ts=2021-11-25T14:34:49.349Z caller=node_exporter.go:115>
11月 25 22:34:49 slave node_exporter[65492]: ts=2021-11-25T14:34:49.349Z caller=node_exporter.go:115>
[root@slave ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:9100 *:*
LISTEN 0 128 [::]:22 [::]:*
查看监控数据
浏览器打开IP:9090/metrics
修改Prometheus 配置,监控Linux机器
[root@master ~]# cat /usr/local/prometheus/prometheus.yml
# 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']
- job_name: 'Linux' #添加以下5行
static_configs:
- targets: ['192.168.129.136:9100'] #添加被控机的ip以及端口
labels:
instance: Linux
//重启
[root@master ~]# systemctl restart prometheus
[root@master ~]# yum -y install grafana
[root@master ~]# grafana-cli plugins install alexanderzobnin-zabbix-app
installing alexanderzobnin-zabbix-app @ 4.1.5
from: https://grafana.com/api/plugins/alexanderzobnin-zabbix-app/versions/4.1.5/download
into: /var/lib/grafana/plugins
✔ Installed alexanderzobnin-zabbix-app successfully
Restart grafana after installing plugins . <service grafana-server restart>
[root@master ~]# systemctl start grafana-server
[root@master ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 128 *:3000 *:*
LISTEN 0 128 *:9090 *:*
LISTEN 0 128 *:80 *:*
网页登录