Grafana + Prometheus + Node Exporter 实现对机器指标监控

一.背景

        最近在工作中需要改造现有的系统监控指标,为了更进进一步深入了解Grafana ,所以自己打算利用 Grafana (数据分析平台),Prometheus(数据源头),Node Exporter(采集机器指标)来完成对本机 内存,cup,网络的监控。

二.下载安装

  1.下载安装grafana

1.下载grafana
https://grafana.com/grafana/download/8.2.6?edition=oss&platform=linux

2.解压
tar -zxvf grafana-8.2.6.linux-amd64.tar.gz 

3.启动 grafana
 ./bin/grafana-server web

4.页面访问    默认(用户名:admin      密码:grafana)
http://localhost:3002

 2.下载安装Node Exporter

1.下载地址
https://prometheus.io/download/#node_exporter

2.解压
tar -zxvf node_exporter-1.4.0-rc.0.linux-amd64.tar.gz

3.启动
./node_exporter

4.验证启动成功(是否存在指标数据)
http://localhost:9100/metrics

 3.下载安装Prometheus

1.下载
https://prometheus.io/download/

2.解压
tar -zxvf prometheus-2.37.1.linux-amd64.tar.gz

3.修改配置 
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).
  external_labels:
    monitor: 'codelab-monitor'
# 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: "node"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    # static_configs targets 修改为 localhost:9100 代表监控的是 node_exporter
    scrape_interval: 5s
    static_configs:
      - targets: ["localhost:9100"]


4.启动
./prometheus --config.file=prometheus.yml


5.验证(看是否有数据)
http://localhost:9090/graph?


三.配置

1.创建数据源头 

2.配置自己的dashboard 

参考:

Getting started | Prometheus 
Monitoring Linux host metrics with the Node Exporter | Prometheus

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,下面是prometheus+node_exporter+grafana的详细部署流程: 1. 下载并安装Prometheus 首先,需要从Prometheus的官方网站 https://prometheus.io/download/ 下载最新版本的Prometheus。下载完成后,解压缩并将其放在合适的位置。然后,可以通过以下命令启动Prometheus: ``` ./prometheus --config.file=prometheus.yml ``` 这里的“prometheus.yml”是Prometheus的配置文件,可以根据需要进行修改。 2. 下载并安装Node Exporter Node Exporter是一个用于收集主机指标的代理程序,可以通过以下命令下载最新版本的Node Exporter: ``` wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz ``` 下载完成后,解压缩并将其放在合适的位置。然后,可以通过以下命令启动Node Exporter: ``` ./node_exporter ``` 3. 配置Prometheus监控Node Exporter监控Node Exporter,需要将其添加到Prometheus的配置文件中。打开“prometheus.yml”文件并添加以下内容: ``` scrape_configs: - job_name: 'node_exporter' scrape_interval: 5s static_configs: - targets: ['localhost:9100'] ``` 这里的“targets”是Node Exporter的地址和端口号。如果要监控多个Node Exporter,则可以添加多个目标。 4. 下载并安装Grafana Grafana是一个用于可视化监控数据的开源平台,可以通过以下命令下载最新版本的Grafana: ``` wget https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz ``` 下载完成后,解压缩并将其放在合适的位置。然后,可以通过以下命令启动Grafana: ``` ./bin/grafana-server ``` 5. 配置Grafana 要将PrometheusGrafana集成,需要在Grafana中添加一个数据源。打开Grafana并导航到“Configuration”>“Data Sources”>“Add Data Source”: - 在“Name”字段中输入数据源的名称。 - 在“Type”字段中选择“Prometheus”。 - 在“HTTP”字段中输入Prometheus的地址和端口号。 - 单击“Save & Test”以保存数据源并测试连接。 接下来,可以创建一个仪表盘并添加一个面板以显示Prometheus数据。导航到“Create”>“Dashboard”>“Add Panel”: - 选择要显示的指标。 - 选择要显示的图表类型。 - 单击“Apply”以保存面板。 6. 查看监控数据 现在,可以通过Grafana查看收集到的监控数据。导航到仪表盘,将其刷新以更新数据,并查看面板中的图表。 以上就是prometheus+node_exporter+grafana的详细部署流程。希望对你有所帮助!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值