prometheus+grafana应用监控配置
创始人
2025-01-09 13:36:14
0

配置Prometheus

官方地址:Download | Prometheus

(wegt下载压缩包,解压并重命名prometheus,文件放于/data/prometheus即可)

配置 service方法(文件放于 /etc/systemd/system/prometheus.service):

[Unit]  Description=Prometheus Server  Documentation=https://prometheus.io/docs/introduction/overview/  After=network-online.target  [Service]  Type=simple  User=prometheus Group=prometheus  ExecStart=/data/prometheus/prometheus/prometheus \   --config.file=/data/prometheus/prometheus/prometheus.yml \   --storage.tsdb.path=/data/prometheus/prometheus/data \   --storage.tsdb.retention.time=60d \   --web.enable-lifecycle   Restart=on-failure  [Install]  WantedBy=multi-user.target 

授权给用户 prometheus

# 创建用户 -M 不创建源目录 -s 指定 shell useradd -M -s /usr/sbin/nologin prometheus  # 赋权 chown prometheus:prometheus -R /data/prometheus

启动运行并检查状态

# 启动 systemctl start prometheus.service  # 检查 systemctl status prometheus.service  # 开启自启动 systemctl enable prometheus.service  # 修改单元文件,重新加载systemd配置  sudo systemctl daemon-reload  # 检查日志方法 journalctl -u prometheus.service -f

重新加载 prometheus

# -X  指定 POST 请求 curl -X POST http://localhost:9090/-/reload  

访问web地址9090:

# ip:9090 访问 prometheus    http://xxx.xxx.xxx.xxx:9090   监控指标       http://xxx.xxx.xxx.xxx:9090/metrics

配置 alertmanager

 配置文件

[Unit]  Description=Alert Manager  Wants=network-online.target After=network-online.target  [Service]  Type=simple  User=prometheus Group=prometheus  ExecStart=/data/prometheus/alertmanager/alertmanager \   --config.file=/data/prometheus/alertmanager/alertmanager.yml \   --storage.path=/data/prometheus/prometheus/data \   Restart=always  [Install]  WantedBy=multi-user.target

访问:web端口9093

配置alert服务器告警提示:

root@pass:~# cat /data/prometheus/prometheus/alert.yml  groups: - name: Prometheus alert   rules:   - alert: 服务告警     expr: up == 0     for: 30s     labels:         severity: critical     annotations:         instance: "{{ $labels.instance }}"         description: "{{ $labels.job }} 服务器"

访问web检查:

检查yml文件配置方法promtool工具:

root@pass:~# cd /data/prometheus/prometheus/ root@pass:/data/prometheus/prometheus# ./promtool check config prometheus.yml Checking prometheus.yml   SUCCESS: 1 rule files found  SUCCESS: prometheus.yml is valid prometheus config file syntax  Checking alert.yml   SUCCESS: 1 rules found

配置grafana

下载地址:Download Grafana | Grafana Labs

配置service文件:

[Unit] Description=Grafana server  Documentation=http://docs.grafana.org   [Service] Type=simple User=prometheus Group=prometheus Restart=on-failure ExecStart= /data/prometheus/grafana/bin/grafana-server \ 	--config=/data/prometheus/grafana/conf/defaults.ini \ 	--homepath=/data/prometheus/grafana  [Install] WantedBy=multi-user.target 

访问web端口3000:(默认账号及密码admin/admin)


 

配置node_exporter

下载地址同Prometheus

配置service文件:

[Unit] Description=node_exporter  Documentation=http://prometheus.io/  After=network.target   [Service] User=prometheus Group=prometheus Restart=on-failure ExecStart= /data/prometheus/node_exporter/node_exporter  [Install] WantedBy=multi-user.target 

访问web端口9100

 最后注意记得配置时将需要的配置到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:             - localhost:9093            # - alertmanager:9093  # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files:   - "alert.yml"   # - "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"]           - job_name: "node-exporter"     scrape_interval: 15s     # metrics_path defaults to '/metrics'     # scheme defaults to 'http'.      static_configs:       - targets: ["localhost:9090"]         labels:              instance: Prometheus服务器

web页面展示

手动创建仪表板:官方地址  Grafana dashboards | Grafana Labs

复制需要的ID ,然后导入到granafa图表中即可

第一步:

第二步:

第三步:

展示结果:

相关内容

热门资讯

教程攻略!拱趴游戏辅助器,拱趴... 拱趴游戏辅助器开挂教程视频分享装挂详细步骤在当今的网络游戏中,拱趴游戏辅助器作为一种经典的娱乐方式,...
我来教大家!wepoker辅助... 我来教大家!wepoker辅助器免费,青橙竞技卡五星辅助,起初有开挂辅助插件(有挂细节);无需打开直...
透明讲解!新悠悠挂,新老夫子挂... 大家好,今天小编来为大家解答新老夫子挂这个问题咨询软件客服可以免费测试直接加微信(136704302...
我来向大家传授!衢州辅助器免费... 我来向大家传授!衢州辅助器免费,极速暗宝辅助,详细辅助下载(有挂讲解);打开点击测试直接进入微信(1...
盘点几款!衢州都莱辅助软件,推... 盘点几款!衢州都莱辅助软件,推筒子压桩公式规律,素来有开挂辅助器(有挂规律);打开点击测试直接进入微...
透视透明!新道游戏辅助器免费版... 透视透明!新道游戏辅助器免费版,wpk软件是真的吗(AI教程辅助脚本)1、下载安装好新道游戏辅助器免...
热点推荐!广东闲来游戏辅助,朱... 热点推荐!广东闲来游戏辅助,朱雀开心罗松开挂,推荐开挂辅助工具(果真有挂)您好:广东闲来游戏辅助这款...
我来教教你!福建天天开心王国辅... 您好:这款福建天天开心王国辅助游戏是可以开挂的,确实是有挂的,很多玩家在这款福建天天开心王国辅助游戏...
透视挂!hhpoker有没有辅... >>您好:雀友会广东潮汕麻雀辅助确实是有挂的,很多玩家在这款雀友会广东潮汕麻雀辅助游戏中打牌都会发现...
发现一款!中至余干510k控制... 发现一款!中至余干510k控制输赢,天天乐卡五星,实测辅助挂(有挂分享);无需打开直接搜索打开薇:1...