Prometheus + Grafana之监控Linux服务器系统

概述

对Linux服务器系统进行监控主要是用到了node_exporter这个工具。node_exporter简单易用,只需要下载后解压运行即可。

点此进入node_exporter的下载界面。
在这里插入图片描述

一、安装

首先对其解压。

tar –xzvf node_exporter-1.1.2.linux-amd64

cd node_exporter-1.1.2.linux-amd64

二、运行node_exporter

./node_exporter

运行后可以看到类似的反馈信息(仅供参考)

level=error ts=2021-06-03T06:05:07.279Z caller=collector.go:161 msg="collector failed" name=cpufreq duration_seconds=0.004688889 err="strconv.ParseUint: parsing \"<unknown>\": invalid syntax"
level=error ts=2021-06-03T06:05:22.277Z caller=collector.go:161 msg="collector failed" name=cpufreq duration_seconds=0.000626559 err="strconv.ParseUint: parsing \"<unknown>\": invalid syntax"
level=error ts=2021-06-03T06:05:37.278Z caller=collector.go:161 msg="collector failed" name=cpufreq duration_seconds=0.006807693 err="strconv.ParseUint: parsing \"<unknown>\": invalid syntax"
level=error ts=2021-06-03T06:05:52.276Z caller=collector.go:161 msg="collector failed" name=cpufreq duration_seconds=0.005156034 err="strconv.ParseUint: parsing \"<unknown>\": invalid syntax"

此时可以通过访问http://yourIP:9100
在这里插入图片描述
点击上图的Metrics可以看到node_exporter获取到的当前主机的监控数据。如下如截取的片段
在这里插入图片描述
每个监控指标之前都有一段类似这样的信息:

# HELP node_cpu_guest_seconds_total Seconds the CPUs spent in guests (VMs) for each mode.
# TYPE node_cpu_guest_seconds_total counter

# HELP node_cooling_device_max_state Maximum throttle state of the cooling device
# TYPE node_cooling_device_max_state gauge

在这里HELP主要是对指标进行了解释,说明这个指标的含义。TYPE说明当前指标的数据类型。
这其中可以了解到cpu有些只表示只增不减的所以数据类型为counter;node_cooling_device_max_state这个指标可以从注释中看出指标类型为gauge。

除此之外,常见的还有一下指标:

  • node_boot_time:系统启动时间
  • node_cpu:系统CPU使用量
  • nodedisk*:磁盘IO
  • nodefilesystem*:文件系统用量
  • node_load1:系统负载
  • nodememeory*:内存使用量
  • nodenetwork*:网络带宽
  • node_time:当前系统时间
  • go_*:node exporter中go相关指标
  • process_*:node exporter自身进程相关运行指标

三、修改Prometheus配置文件收集数据

为了能够让Prometheus获取到监控数据,这里需要对prometheus.yml文件进行配置。追加node字段即可。

[root@localhost prometheus]# cat 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=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['yourIP:9090']


  - job_name: 'node'
    static_configs:
     - targets: ['yourIP:9100']

[root@localhost prometheus]# 

添加文件后需要重新启动prometheus。
先不优雅地关闭prometheus,

[root@localhost prometheus]# ps -A |grep prometheus
  3205 ?        00:00:36 prometheus
[root@localhost prometheus]# kill -9 3205

再启动prometheus

./prometheus --config.file=prometheus.yml

这时再访问Prometheus的Web UI,输入up 点击 execute可以看到
在这里插入图片描述
如果能够正常获取到node_exporter数据会看到Elements部分的数据

up{instance="172.16.20.47:9090",job="prometheus"}	1
up{instance="172.16.20.47:9100",job="node"}   1

1表示为正常,0表示为异常。

四、Grafana添加数据

之前已经把Grafana给起来了,访问Grafana的Web UI,默认用户名和密码都是admin,根据需要进行更改。
在这里插入图片描述

添加数据源

第一步,就是要把Prometheus的数据源添加进来。左侧设置按钮,选择 Data Source, Add data source。
在这里插入图片描述
选择Prometheus数据源。
在这里插入图片描述
将默认的Prometheus地址和端口填入地址栏。
在这里插入图片描述
可以通过点击Save&Test可以测试数据源是否可以连通。
在这里插入图片描述

创建Dashboard

先创建一个Dashboard,通过设置齿轮给Dashboard命名。
在这里插入图片描述

创建行

给Dashboard命名后,新建一行(add a new row),给这它一个新的行名。
在这里插入图片描述
在这里插入图片描述

新建panel

在这里插入图片描述
点击add an empty panel后进入下面这个界面:
在这里插入图片描述
通过图上,这个页面可以为这个panel命名、添加描述信息、选择用什么样的图展示,
最重要的是,选择好数据来源为Prometheus,其次在Metrics下拉箭头中选择要展示的指标。比如
在这里插入图片描述
添加完一个指标后我们还可以添加指标通过这个按钮。
在这里插入图片描述
同样地添加步骤。
添加完后记得应用 保存。
在这里插入图片描述
在这里插入图片描述
其他指标添加方式雷同,这是为了分类,将这个panel移动到新建的行下。

效果图:
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Energet!c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值