Prometheus➕Grafana监控node节点资源情况

2022-11-21 19:54:49 浏览数 (1)

Prometheus是一套开源的系统监控报警框架。Prometheus作为新一代的云原生监控系统,相比传统监控监控系统(Nagios或者Zabbix)拥有众多有点。

下载安装启动exporte

代码语言:javascript复制
[root@localhost ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost ~]# tar zxf node_exporter-0.18.1.linux-amd64.tar.gz 
[root@localhost ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporte
[root@localhost ~]# /usr/local/node_exporte/node_exporter &

下载安装Prometheus

代码语言:javascript复制
[root@localhost ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.10.0/prometheus-2.10.0.linux-amd64.tar.gz
[root@localhost ~]# tar -zxf prometheus-2.10.0.linux-amd64.tar.gz
[root@localhost ~]# mv prometheus-2.10.0.linux-amd64 /usr/local/prometheus

配置Prometheus

代码语言:javascript复制
[root@localhost ~]# vim /usr/local/prometheus/prometheus.yml
# 修改如下
  - job_name: 'node'
    static_configs:
    - targets: ['localhost:9100']

启动Prometheus

代码语言:javascript复制
[root@localhost ~]# /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

安装Grafana

代码语言:javascript复制
[root@localhost ~]# wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
[root@localhost ~]# yum -y install initscripts urw-fonts
[root@localhost ~]# rpm -Uvh grafana-5.4.2-1.x86_64.rpm 

启动Grafana

代码语言:javascript复制
[root@localhost ~]# systemctl start grafana-server

Grafana页面配置 访问http://192.168.1.10:3000

默认用户密码都是admin

创建展示界面监控数据源

选择Prometheus

Prometheus所在主机的服务端口

添加仪表盘

上图中的空白处需要添加一个json文件,需要从grafana的官网进行下载,这里可以选择关于Docker的仪表盘,很多种类,这里以官方使用的为主,点击这里使用接下里要用的dashboard,进入页面后,如图所示,根据图中红线处即可下载

然后将文件导入Grafana页面即可,选择数据源为Prometheus

如果让普罗米修斯监控多个节点 在node节点下载安装启动exporte

代码语言:javascript复制
[root@localhost ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost ~]# tar zxf node_exporter-0.18.1.linux-amd64.tar.gz 
[root@localhost ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporte
[root@localhost ~]# /usr/local/node_exporte/node_exporter &

然后到普罗米修斯节点修改配置文件

代码语言:javascript复制
[root@localhost ~]# vim /usr/local/prometheus/prometheus.yml
# 添加如下
  - job_name: 'node'
    static_configs:
    - targets: ['localhost:9100','nodeIP:9100'] #node节点依次向后添加

然后重新运行普罗米修斯

代码语言:javascript复制
[root@localhost ~]# lsof -i:9100
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node_expo  9891 root    3u  IPv6  47017      0t0  TCP *:jetdirect (LISTEN)
node_expo  9891 root    5u  IPv6  54418      0t0  TCP localhost.localdomain:jetdirect->localhost.localdomain:50898 (ESTABLISHED)
prometheu 10322 root    8u  IPv4  54416      0t0  TCP localhost.localdomain:51060->192.168.1.20:jetdirect (ESTABLISHED)
prometheu 10322 root   10u  IPv4  54417      0t0  TCP localhost.localdomain:50898->localhost.localdomain:jetdirect (ESTABLISHED)
#先干掉之前的进程
kill -9 PID
#启动
 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &

重启Grafana刷新页面查看

代码语言:javascript复制
systemctl restart grafana-server

0 人点赞