prometheus 笔记
前言
prometheus 是监控应用软件类似于nagios.
安装
1.官网下载prometheus-2.2.0.linux-amd64压缩包,解压,执行./prometheus即可。这里重要的是配置文件。
a.如果要远程热加载配置文件,启动时加上--web.enable-lifecycle参数。 调用指令是curl -X POST http://localhost:9090/-/reload
b.重要掌握 prometheus.yml 配置文件.prometheus启动时会加载它。
[root@vm-local1 prometheus-2.2.0.linux-amd64]# cat 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). 默认抓取超时10秒# Alertmanager configuration #管理报警配置 alerting:alertmanagers:- static_configs:- targets: ["localhost:9093"] #管理报警包需要单独下载,默认启动端口是9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files:# - "first_rules.yml"# - "second_rules.yml"- rules/mengyuan.rules #要发送报警,就得写规则,定义规则文件# 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' #默认抓取监控机的url后缀地址是/metrics# scheme defaults to 'http'. #模式是httpstatic_configs:- targets: ['localhost:9090','localhost:9100']labels:group: 'zus' #targets就是要抓取的主机,对应的客户端,我这有两个,把它们俩规定为一个组,组名是zus- job_name: dj #又建立个任务名称static_configs:- targets: ['localhost:8000'] #我用django自定义的客户端
注意:
localhost:9090,默认prometheus提供了数据抓取接口,9100端口是prometheus提供的一个监控客户端
2.安装prometheus客户端
官网下载node_exporter-0.16.0-rc.1.linux-amd64客户端,解压,执行./node_exporter 即可,默认是9100端口
3.如何自定义一个客户端,其实很简单,只要返回的数据库类型是这样就可以.我这用的django..只要格式正确就可以
def metrics(req):ss = "feiji 32" + "\n" + "caidian 31"return HttpResponse(ss)
4.编写 rules/mengyuan.rules 规则,规则是发送报警的前提
[root@vm-local1 rules]# cat mengyuan.rules groups: - name: zusrules:# Alert for any instance that is unreachable for >5 minutes.- alert: InstanceDown #报警名字随便写expr: up == 0 #这是一个表达式,如果主机up状态为0,表示关机了,条件为真就会触发报警 可以通过$value得到值for: 5s #5s内,还是0,就发送报警信息,当然是发送给报警管理器labels:severity: page #这个类型的报警定了个标签annotations:summary: "Instance {{ $labels.instance }} down dangqian {{ $value }}"description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes."
5.现在安装报警管理器
a.官网下载alertmanager-0.15.0-rc.1.linux-amd64
重要的还是配置文件,创建修改它
[root@vm-local1 alertmanager-0.15.0-rc.1.linux-amd64]# cat alertmanager.yml route:receiver: mengyuan2 #接收的名字,默认必须有一个,对应receivers的- namegroup_wait: 1s #等待1sgroup_interval: 1s #发送间隔1srepeat_interval: 1m #重复发送等待1m分钟再发group_by: ["zus"] routes: #路由了,匹配规则标签的severity:page 走 receiver: mengyuan , 如果routes不写,就会走默认的mengyuan2- receiver: mengyuan match:severity: pagereceivers: - name: 'mengyuan'webhook_configs: #这我用的webhook_configs 钩子方法, 默认会把规则的报警信息发送到127.0.0.1:8000- url: http://127.0.0.1:8000send_resolved: true - name: 'mengyuan2'webhook_configs:- url: http://127.0.0.1:8000/2send_resolved: true
6.django接收报警发过来的消息
用Django的 request.body会受到json格式的数据,大概像这样
{"receiver":"mengyuan","status":"resolved","alerts":[{"status":"resolved","labels":{"alertname":"InstanceDown","group":"zus","instance":"localhost:9100","job":"prometheus","severity":"page"},"annotations":{"description":"localhost:9100 of job prometheus has been down for more than 5 minutes.","summary":"Instance localhost:9100 down dangqian 0"},"startsAt":"2018-04-06T22:34:13.51281763+08:00","endsAt":"2018-04-06T23:07:43.514552824+08:00","generatorURL":"http://vm-local1:9090/graph?g0.expr=up+%3D%3D+0\u0026g0.tab=1"}],"groupLabels":{},"commonLabels":{"alertname":"InstanceDown","group":"zus","instance":"localhost:9100","job":"prometheus","severity":"page"},"commonAnnotations":{"description":"localhost:9100 of job prometheus has been down for more than 5 minutes.","summary":"Instance localhost:9100 down dangqian 0"},"externalURL":"http://vm-local1:9093","version":"4","groupKey":"{}/{severity=\"page\"}:{}"}
到此,我就可以根据收到的数据,调用邮件接口,或其他第三方报警接口了。
总结:
本人也是刚入门。做的一个笔记。
转载于:https://www.cnblogs.com/whf191/p/8729460.html
prometheus 笔记相关推荐
- Prometheus笔记(一)metric type
欢迎加入go语言学习交流群 636728449 Prometheus笔记(二)监控go项目实时给grafana展示 Prometheus笔记(一)metric type 文章目录 Prometheus ...
- Prometheus笔记
https://blog.csdn.net/luanpeng825485697/article/details/82318204 https://www.cnblogs.com/yangxiaoyi/ ...
- K8S 学习笔记三 核心技术 Helm nfs prometheus grafana 高可用集群部署 容器部署流程
K8S 学习笔记三 核心技术 2.13 Helm 2.13.1 Helm 引入 2.13.2 使用 Helm 可以解决哪些问题 2.13.3 Helm 概述 2.13.4 Helm 的 3 个重要概念 ...
- 2.Prometheus读书笔记:深入Prometheus设计
Prometheus读书笔记:深入Prometheus设计 Prometheus第二章读书笔记的思维导图 Prometheus • 2.深入Prometheus设计 o 2.1指标 Prometh ...
- ROS实验笔记之——基于Prometheus自主无人机开源项目的学习与仿真
最近在公众号上看到Prometheus无人机的资料,发现里面开源了很好的无人机的仿真环境,并且有很好的教程.而本人正好在上<Introduction to Aerial Robotics> ...
- ROS学习笔记——基于Prometheus无人机开源项目仿真环境配置
本笔记基于ubuntu18.04版本,配置基于Prometheus无人机开源项目仿真环境. 需要事先在电脑上安装了ROS,Mavros功能包,其余可参考Amov教程, ...
- ROS实验笔记之——基于Prometheus的无人机运动规划
本博文基于Prometheus项目来学习无人机的运动规划.关于该项目的配置可以参考<ROS实验笔记之--基于Prometheus自主无人机开源项目的学习与仿真> Demo演示 基于2D-L ...
- 普罗米修斯笔记:初识Prometheus
文章目录 Prometheus简介 Prometheus特性 pull方式 push方式 核心组成部分 Prometheus server Client libraries Push Gateway ...
- Prometheus监控学习笔记之360基于Prometheus的在线服务监控实践
0x00 初衷 最近参与的几个项目,无一例外对监控都有极强的要求,需要对项目中各组件进行详细监控,如服务端API的请求次数.响应时间.到达率.接口错误率.分布式存储中的集群IOPS.节点在线情况.偏移 ...
最新文章
- jQuery的文档操作方法
- c++ 标准库格式化时间戳(既将时间戳转字符串,字符串转时间戳)
- jQuery 仿淘宝 鼠标悬停显示大图效果
- 简单分析及总结BlockingQueue接口下七个常用类
- Promises/A+规范中文翻译
- oracle查看登录时间黑屏,史上最强黑屏行动-微软20日黑屏反盗版验证
- Kaggle-泰坦尼克号
- linux处理制表文件,linux下PDF及表格处理软件
- Vue教程:简介(一)
- 现实版高达!美日巨型机器人格斗大战结果即将见分晓
- 【转】JavaScript中的this关键字使用的四种调用模式
- 1003 我要通过! (20 分)—PAT (Basic Level) Practice (中文)
- 12306全国火车站点所在区划代码经纬度数据,精确到县区级
- 谷粒商城微服务分布式高级篇十一———商城检索
- 通过UA判断手机的类型
- 【SoC FPGA学习】十、SoC FPGA 开发板的 FPGA 配置数据下载和固化
- 盗贼之海服务器维护时间,盗贼之海常见问题解决方法
- 有道身份证查询接口API
- 蓝桥杯,我劝你不要参加的8个完美理由
- 快速电商排版网页布局ps神器插件_安装教程
热门文章
- php有lambda表达式吗,Python中lambda表达式的简单介绍(附示例)
- Python-100 练习题 04 判断天数
- 论文阅读(2)--Picking Deep Filter Responses for Fine-grained Image Recognition
- 1-2docker-基本的使用
- 算法之快速排序(递归和非递归)
- LeetCode Smallest Range
- SQLAllocStmt与SQLFreeStmt
- Git Push 避免输入用户名和密码方法
- GDB调试程序(二)
- 在C#里,如何执行cmd里的常用dos命令 (转)