当前位置: 首页 > news >正文

prometheus+grafana应用监控配置

配置Prometheus

官方地址:Download | Prometheus

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

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

[Unit]Description=Prometheus ServerDocumentation=https://prometheus.io/docs/introduction/overview/After=network-online.target[Service]Type=simpleUser=prometheus
Group=prometheusExecStart=/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-lifecycleRestart=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 ManagerWants=network-online.target
After=network-online.target[Service]Type=simpleUser=prometheus
Group=prometheusExecStart=/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.ymlgroups:
- name: Prometheus alertrules:- alert: 服务告警expr: up == 0for: 30slabels:severity: criticalannotations: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.ymlSUCCESS: 1 rule files foundSUCCESS: prometheus.yml is valid prometheus config file syntaxChecking alert.ymlSUCCESS: 1 rules found

配置grafana

下载地址:Download Grafana | Grafana Labs

配置service文件:

[Unit]
Description=Grafana serverDocumentation=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_exporterDocumentation=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=<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"]- 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图表中即可

第一步:

第二步:

第三步:

展示结果:

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 基于springboot+vue+uniapp的超市购物系统小程序
  • 【Java--数据结构】二叉树oj题(上)
  • Nuxt.js头部魔法:轻松自定义页面元信息,提升用户体验
  • LeetCode 92. 反转链表 II
  • Hi3861 OpenHarmony嵌入式应用入门--华为 IoTDA 设备接入
  • 堆、栈和队列(数据结构)
  • PGCCC|【PostgreSQL】PCA+PCP+PCM等IT类认证申报个税退税指南
  • 【mysql】02在ubuntu24安装并配置mysql
  • 【区块链 + 智慧政务】澳门:智慧城市建设之证书电子化项目 | FISCO BCOS应用案例
  • 单元测试有什么好处呢?
  • 【代码随想录_Day30】1049. 最后一块石头的重量 II 494. 目标和 474.一和零
  • SpringBoot集成Sharding-JDBC-5.3.0实现按月动态建表分表
  • 采用自动微分进行模型的训练
  • 睡前故事—绿色科技的未来:可持续发展的梦幻故事
  • 数据建设实践之大数据平台(五)安装hive
  • 【译】理解JavaScript:new 关键字
  • CODING 缺陷管理功能正式开始公测
  • extract-text-webpack-plugin用法
  • Idea+maven+scala构建包并在spark on yarn 运行
  • Java多线程(4):使用线程池执行定时任务
  • mockjs让前端开发独立于后端
  • node-glob通配符
  • 分享自己折腾多时的一套 vue 组件 --we-vue
  • 关于springcloud Gateway中的限流
  • 好的网址,关于.net 4.0 ,vs 2010
  • 基于Vue2全家桶的移动端AppDEMO实现
  • 开源SQL-on-Hadoop系统一览
  • 算法之不定期更新(一)(2018-04-12)
  • 详解移动APP与web APP的区别
  • 学习使用ExpressJS 4.0中的新Router
  • 云大使推广中的常见热门问题
  • 智能合约开发环境搭建及Hello World合约
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • 阿里云ACE认证之理解CDN技术
  • 阿里云重庆大学大数据训练营落地分享
  • "无招胜有招"nbsp;史上最全的互…
  • ## 基础知识
  • ###STL(标准模板库)
  • #考研#计算机文化知识1(局域网及网络互联)
  • (003)SlickEdit Unity的补全
  • (1)svelte 教程:hello world
  • (poj1.2.1)1970(筛选法模拟)
  • (Repost) Getting Genode with TrustZone on the i.MX
  • (二十四)Flask之flask-session组件
  • (非本人原创)我们工作到底是为了什么?​——HP大中华区总裁孙振耀退休感言(r4笔记第60天)...
  • (机器学习的矩阵)(向量、矩阵与多元线性回归)
  • (十七)Flask之大型项目目录结构示例【二扣蓝图】
  • (一)UDP基本编程步骤
  • (转)EXC_BREAKPOINT僵尸错误
  • ***检测工具之RKHunter AIDE
  • .net core IResultFilter 的 OnResultExecuted和OnResultExecuting的区别
  • .NET MAUI学习笔记——2.构建第一个程序_初级篇
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .NET Standard、.NET Framework 、.NET Core三者的关系与区别?
  • .NET 反射 Reflect