1 装置node_exporter
指标监控主机操作系统:Ubuntu Server 20.04
一键装置脚本:
sudo useradd --no-create-home --shell /bin/false node_exporter \&& cd /opt && wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz \&& tar xvf node_exporter-0.18.1.linux-amd64.tar.gz \&& sudo mv node_exporter-0.18.1.linux-amd64 /opt/node_exporter \&& sudo chown node_exporter:node_exporter /opt/node_exporter -R \&& sudo touch /etc/systemd/system/node_exporter.service \&& sudo echo '[Unit]Description=Node ExporterWants=network-online.targetAfter=network-online.target[Service]User=node_exporterGroup=node_exporterType=simpleExecStart=/opt/node_exporter/node_exporter --collector.systemd[Install]WantedBy=multi-user.target' > /etc/systemd/system/node_exporter.service \&& sudo systemctl daemon-reload \&& sudo systemctl enable node_exporter \&& sudo systemctl start node_exporter \&& sudo journalctl -f --unit node_exporter
装置实现后拜访:http://${host}:9100/
,确认服务失常启动,如下图所示:
2 装置Prometheus工夫序列数据库
Prometheus通过基于HTTP的pull形式采集时序数据,能够通过服务发现或者动态配置去获取要采集的指标服务器,反对单主节点工作,反对多种可视化图表及仪表盘。
在中控节点装置Prometheus,一键装置脚本:
sudo mkdir -p /opt/promethes \&& touch /opt/promethes/promethes.yml \&& sudo echo 'global: scrape_interval: 15s external_labels: monitor: 'codelab-monitor'scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - job_name: 'node' scrape_interval: 5s static_configs: - targets: ['${host1}:9100','${host2}:9100', ...]' > /opt/promethes/promethes.yml \&& docker run -d --restart=always \ -p 9090:9090 \ -v /opt/promethes/promethes.yml:/etc/prometheus/prometheus.yml \ prom/prometheus
- 加粗的targets的值是待监控的主机列表
装置实现后拜访:http://${host}:9090/
,确认服务失常启动,如下图所示:
3 装置Grafana图形化监控控制台
- Grafana是一个开源的度量剖析与可视化套件。 纯Javascript 开发的前端工具,通过拜访库(如InfluxDB),展现自定义报表、显示图表等。Grafana的UI更加灵便,有丰盛的插件,功能强大。
在中控节点(host0)装置Grafana,一键装置脚本:
sudo apt-get install -y apt-transport-https \&& sudo apt-get install -y software-properties-common wget \&& wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - \&& echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list \&& sudo apt-get update&& sudo apt-get install grafana
装置实现后拜访:http://${host0}:3000/
,确认服务失常启动
3.1 配置默认Prometheus数据源
左侧菜单Configuration → Data Sources
,点击/编辑默认Prometheus数据源,配置URL为:http://localhost:9090
,Save & Test
3.2 装置Node Exporter Dashboard
- 插件地址:https://grafana.com/grafana/d...
- 如何装置:https://grafana.com/docs/graf...
- 以配置文件的形式导入,配置文件
4 参考
- nwesterhausen/node_exporter_setup.md
- Node Exporter 接口阐明
- Prometheus Installation
- Prometheus Getting Started
- 应用Node Exporter采集主机数据