prometheus+node_exporter组件部署监控

安装Prometheus:

prometheus+grafana :192.168.1.23
node_exporter : 192.168.1.72 192.168.1.23

1
2
3
4
5
6
wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz    
tar xf prometheus-2.20.1.linux-amd64.tar.gz
# 查看版本
./prometheus --version
# 运行server
./prometheus --config.file=prometheus.yml

配置Prometheus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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=<job_name>` 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: 'exporter'
static_configs:
- targets: ['192.168.1.72:9100','192.168.1.23:9100']

其大致分为四部分:
global:全局配置,其中scrape_interval表示抓取一次数据的间隔时间,evaluation_interval表示进行告警规则检测的间隔时间;
alerting:告警管理器(Alertmanager)的配置,目前还没有安装Alertmanager;
rule_files:告警规则有哪些;
scrape_configs:抓取监控信息的目标。一个job_name就是一个目标,其targets就是采集信息的IP和端口。这里默认监控了Prometheus自己,可以通过修改这里来修改Prometheus的监控端口。Prometheus的每个exporter都会是一个目标,它们可以上报不同的监控信息,比如机器状态,或者mysql性能等等,不同语言sdk也会是一个目标,它们会上报你自定义的业务监控信息。

Prometheus界面

运行后,在浏览器访问[机器IP:端口]就可以查看Prometheus的界面了,这里的机器IP是你运行Prometheus的机器,端口是上面配置文件中配置的监控自己的端口。打开后界面如下:

现在都是down的状态因为被监控机器还没有部署

添加机器状态监控

1
2
3
4
5
6
# 被监控端都需要执行,prometheus服务器需要被监控也要安装
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xf node_exporter-1.3.1.linux-amd64.tar.gz
cd node_exporter-1.3.1.linux-amd64
# 运行监控采集服务
./node_exporter

运行后可以看到在监听9100端口。这样就可以采集了,现在先访问试试能不能有没有成功运行

1
2
curl http://192.168.1.72:9100/metrics
curl http://192.168.1.23:9100/metrics

target的status是“UP”的话,就说明监听成功了

安装Grafana

1
2
3
4
5
# 注:如需要使用grafana的插件模板,先查看模板支持的grafana版本
wget wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.4.7.linux-amd64.tar.gz
tar xf grafana-enterprise-8.4.7.linux-amd64.tar.gz
cd grafana-8.4.7/bin/
./grafana-server web

在Grafana展示监控信息

安装并启动Grafana后,浏览器输入 IP:3000 来访问Grafana,管理员账号密码默认是admin/admin。首次登陆会让你修改管理员密码,然后就可以登录查看了








  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2019-2023 XIN LONG
  • 访问人数: | 浏览次数:

请我喝杯咖啡吧~

支付宝
微信