手把手教你给服务器搭建一套资源监控系统

目录

    • 一、前言
    • 二、准备
    • 三、安装
      • 安装Prometheus
      • 安装Node_exporter
      • 安装Grafana
    • 四、配置
      • Prometheus 配置
      • Node_exporter 配置自启动
      • Grafana 配置
    • 五、效果
    • 六、参考文献

一、前言

本文主要是介绍如何给一台服务器,搭建一个优雅的资源监控系统
如果对你有帮助,欢迎三连 收藏点赞关注!!!

---- 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=` 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 = [email protected]
# 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/

手把手教你给服务器搭建一套资源监控系统_第1张图片

五、效果

手把手教你给服务器搭建一套资源监控系统_第2张图片

六、参考文献

12_监控报警_添加相关仪表盘模板_哔哩哔哩_bilibili

你可能感兴趣的:(软件使用,服务器,监控系统,Grafana,Prometheus)