一、前言
本文主要是介绍如何给一台服务器,搭建一个优雅的资源监控系统
如果对你有帮助,欢迎三连 收藏点赞关注!!!---- Nick.Peng
二、准备
分别下载以下安装包,下载地址:https://prometheus.io/download/
- grafana-enterprise-9.3.6.linux-amd64
- node_exporter-1.5.0.linux-amd64
- prometheus-2.42.0.linux-amd64
三、安装
安装Prometheus
# 源码安装prometheus
tar -zxvf prometheus-2.42.0.linux-amd64.tar.gz -C /monitor/module/
mv prometheus-2.42.0.linux-amd64/ prometheus-2.42.0
# 后台启动,默认端口9090
nohup ./prometheus --config.file=prometheus.yml --web.listen-address=:9089 > ./prometheus.log 2>&1 &
安装Node_exporter
# 源码安装node_exporter
tar -zxvf node_exporter-1.5.0.linux-amd64.tar.gz -C /monitor/module/
mv node_exporter-1.5.0.linux-amd64/ node_exporter-1.5.0
# 启动node_exporter,下面会介绍系统进程自动启动方式
cd node_exporter-1.5.0 && ./node_exporter
# 测试node_exporter是否能访问 或者 直接在浏览器中访问以下地址
wget http://localhost:9100/metrics
安装Grafana
# 源码安装grafana
tar -zxvf grafana-enterprise-9.3.6.linux-amd64.tar.gz -C /monitor/module/
# 后台启动Grafana
nohup ./bin/grafana-server web > ./grafana.log 2>&1 &
四、配置
Prometheus 配置
编辑配置文件,修改 job_name 和 targets,如下:vim /monitor/module/prometheus-2.42.0/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: ["localhost:9090"]
- targets: ["localhost:9089"]
- job_name: "node exporter"
static_configs:
# node服务器地址加端口,端口默认9100
- targets: ["localhost:9100"]
Node_exporter 配置自启动
sudo vim /usr/lib/systemd/system/node_exporter.service
######## 以下是配置开机自启配置 ########
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
[Service]
Type=simple
User=atguigu
ExecStart=/monitor/module/node_exporter-1.5.0/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
######## 配置文件结束 ########
Grafana 配置
vim grafana-9.3.6/conf/defaults.ini
# 修改服务端口,默认是3000
http_port = 9090
#################################### SMTP / Emailing #####################
[smtp]
enabled = true
host = smtp.163.com:465
user = xxxxxx@163.com
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = SISQXWNSUKZB-NICK
cert_file =
key_file =
skip_verify = true
from_address = 邮箱地址
from_name = Grafana
ehlo_identity =
startTLS_policy =
导入node_exporter Dashbord文件
下载地址:https://grafana.com/grafana/dashboards/
五、效果
文章来源:https://www.toymoban.com/news/detail-464345.html
六、参考文献
12_监控报警_添加相关仪表盘模板_哔哩哔哩_bilibili文章来源地址https://www.toymoban.com/news/detail-464345.html
到了这里,关于手把手教你给服务器搭建一套资源监控系统的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!