Prometheus - Node Exporter (host data acquisition) - Grafana (Visualization)

 

 

Installation Node Exporter

Node Exporter adopt Golang write, and there are no third-party reliance, just download, unzip to run. From https://prometheus.io/download/ obtain the latest version of the node exporter binary packages.

tar -xzf node_exporter-0.15.2.darwin-amd64.tar.gz
cd node_exporter-0.15.2.darwin-amd64

Run node exporter:

./node_exporter

After a successful start, you can see the following output:

INFO[0000] Listening on :9100                            source="node_exporter.go:76"

 Visit http: // localhost: 9100 / can see the following pages:

 

 

 

Node Exporter monitoring indicators

Access HTTP: // localhost: 9100 / metrics , you can see all the monitoring data for the current host of the current node exporter acquired, as follows:

 

  Each will have information before monitoring indicators similar to some of the form:

# HELP node_cpu Seconds the cpus spent in each mode.
# TYPE node_cpu counter
node_cpu{cpu="cpu0",mode="idle"} 362812.7890625
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 3.0703125

其中HELP用于解释当前指标的含义,TYPE则说明当前指标的数据类型。在上面的例子中node_cpu的注释表明当前指标是cpu0上idle进程占用CPU的总时间,CPU占用时间是一个只增不减的度量指标,从类型中也可以看出node_cpu的数据类型是计数器(counter),与该指标的实际含义一致。又例如node_load1该指标反映了当前主机在最近一分钟以内的负载情况,系统的负载情况会随系统资源的使用而变化,因此node_load1反映的是当前状态,数据可能增加也可能减少,从注释中可以看出当前指标类型为仪表盘(gauge),与指标反映的实际含义一致。

除了这些以外,在当前页面中根据物理主机系统的不同,你还可能看到如下监控指标:

  • node_boot_time:系统启动时间

  • node_cpu:系统CPU使用量

  • nodedisk*:磁盘IO

  • nodefilesystem*:文件系统用量

  • node_load1:系统负载

  • nodememeory*:内存使用量

  • nodenetwork*:网络带宽

  • node_time:当前系统时间

  • go_*:node exporter中go相关指标

  • process_*:node exporter自身进程相关运行指标

 

 

Node Exporter收集监控数据

为了能够让Prometheus Server能够从当前node exporter获取到监控数据,这里需要修改Prometheus配置文件。编辑prometheus.yml并在scrape_configs节点下添加以下内容:

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']
  # 采集node exporter监控数据
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100']

重新启动Prometheus Server

访问http://localhost:9090,进入到Prometheus Server。如果输入“up”并且点击执行按钮以后,可以看到如下结果:

如果Prometheus能够正常从node exporter获取数据,则会看到以下结果:

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

其中“1”表示正常,反之“0”则为异常。

 

 

可视化监控数据

Prometheus UI提供了快速验证PromQL以及临时可视化支持的能力,而在大多数场景下引入监控系统通常还需要构建可以长期使用的监控数据可视化面板(Dashboard)。

这时用户可以考虑使用第三方的可视化工具如Grafana,Grafana是一个开源的可视化平台,并且提供了对Prometheus的完整支持。

 

访问http://localhost:3000就可以进入到Grafana的界面中,默认情况下使用账户admin/admin进行登录。在Grafana首页中显示默认的使用向导,包括:安装、添加数据源、创建Dashboard、邀请成员、以及安装应用和插件等主要流程:

  这里将添加Prometheus作为默认的数据源,如下图所示,指定数据源类型为Prometheus并且设置Prometheus的访问地址即可,在配置正确的情况下点击“Add”按钮,会提示连接成功的信息:

 在完成数据源的添加之后就可以在Grafana中创建我们可视化Dashboard了。Grafana提供了对PromQL的完整支持,如下所示,通过Grafana添加Dashboard并且为该Dashboard添加一个类型为“Graph”的面板。

并在该面板的“Metrics”选项下通过PromQL查询需要可视化的数据:

 点击界面中的保存选项,就创建了我们的第一个可视化Dashboard了。 当然作为开源软件,Grafana社区鼓励用户分享Dashboard通过https://grafana.com/dashboards网站,可以找到大量可直接使用的Dashboard:

 Grafana中所有的Dashboard通过JSON进行共享,下载并且导入这些JSON文件,就可以直接使用这些已经定义好的Dashboard:

 

 

 

 

 

 参考:https://yunlzheng.gitbook.io/prometheus-book/ 

Guess you like

Origin www.cnblogs.com/caoweixiong/p/12120301.html