一.背景
最近在工作中需要改造现有的系统监控指标,为了更进进一步深入了解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