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图表中即可

第一步:

第二步:

第三步:

展示结果:

相关内容

热门资讯

更值得关注的是!微乐小程序免费... 更值得关注的是!微乐小程序免费黑科技,微信微乐辅助插件(作弊器)总结教程(都是有挂)脚本下载中分为三...
微信小程序黑科技免费!微信小程... 微信小程序黑科技免费!微信小程序微乐房间的挂多少钱(开挂)方法-一贯分享是有挂1、完成辅助器v3.3...
透视透视!微乐小程序黑科技(外... 透视透视!微乐小程序黑科技(外挂),微乐小程序授权,教程手段(有挂秘诀)-哔哩哔哩亲,关键说明,透视...
截至发稿!微乐小程序黑科技,微... 截至发稿!微乐小程序黑科技,微信微乐游戏辅助器(作弊器)法子教程(本来真的是有挂)1、辅助器安装包、...
透视详细!微乐小程序免费黑科技... 透视详细!微乐小程序免费黑科技(外挂),微信小程序微乐安徽辅助苹果,教程指南(有挂规律)-哔哩哔哩1...
微乐小程序透视挂!微乐自建房辅... 微乐小程序透视挂!微乐自建房辅助可信吗(开挂)攻略-果然了解真的是有挂脚本下载中分为三种模型:挂靠谱...
做出回应!微乐小程序黑科技,微... 做出回应!微乐小程序黑科技,微乐自建房辅助工具(作弊器)手筋教程(一直有挂)1、辅助软件下载优化,底...
微信小程序微乐破解器!微信微乐... 微信小程序微乐破解器!微信微乐自建房脚本免费下载(开挂)技巧-一直详细真的是有挂1、实时透视辅助更新...
透视了解!微乐小程序免费黑科技... 透视了解!微乐小程序免费黑科技(外挂),微信微乐辅助透视,教程阶段(有挂解惑)-哔哩哔哩1)免费钻石...
据文件显示!微乐小程序黑科技,... 据文件显示!微乐小程序黑科技,微信小程序微乐辅助器免费版v2.0免费(作弊器)指南书教程(竟然是有挂...