原文地址:https://xeblog.cn/articles/7git
Prometheus受启发于Google的Brogmon监控系统(类似的Kubernetes是从Google的Brog系统演变而来),从2012年开始由前Google工程师在Soundcloud以开源软件的形式进行研发,而且于2015年早期对外发布早期版本。2016年5月继Kubernetes以后成为第二个正式加入CNCF基金会的项目,同年6月正式发布1.0版本。2017年末发布了基于全新存储层的2.0版本,能更好地与容器平台、云平台配合。web
Prometheus 存储的是时序数据, 即按照相同时序(相同的名字和标签),以时间维度存储连续的数据的集合。spring
监控样本vim
# HELP system_cpu_usage The "recent cpu usage" for the whole system
# TYPE system_cpu_usage gauge
system_cpu_usage 0.23587264544090683
# HELP logback_events_total Number of error level events that made it to the logs
# TYPE logback_events_total counter
logback_events_total{level="error",} 0.0
logback_events_total{level=“info”,} 557.0
复制代码
Prometheus 时序数据分为 Counter, Gauge, Histogram, Summary 四种类型。api
官方下载地址架构
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
复制代码
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
复制代码
进入Prometheus安装根目录 vim prometheus.yml分布式
新增节点ide
- job_name: xeblog-api
metrics_path: /actuator/prometheus
static_configs:
- targets: ['127.0.0.1:8080’]
复制代码
job_name:任务名称 metrics_path: 指标路径 targets:实例地址/项目地址,可配置多个函数
进入Prometheus安装根目录 ./prometheus 运行成功日志 spring-boot
访问地址:localhost:9090
操做符:= != =~ !~
匹配监控任务为xeblog-api的非GET请求方法的请求数
http_server_requests_seconds_count{job="xeblog-api", method!="GET"}
复制代码
匹配监控任务为xeblog-api的非GET请求方法的请求数,且请求路径不为/api/message和/api/version
http_server_requests_seconds_count{job="xeblog-api", method!="GET", uri !~ "/api/message|/api/version"}
复制代码
它门的区别主要是,“=~ !~”支持正则匹配
查询最近5分钟内的全部样本数据: http_request_total{}[5m] 可选单位:
查询5分钟前的样本数据: http_request_total{} offset 5m
查询昨天1天内的样本数据: http_request_total{}[1d] offset 1d
// 安装
brew install grafana
// 启动
brew services start grafana
复制代码
启动后访问地址:localhost:3000
登录: 初始用户名和密码都是admin
能够选择本身手动添加或者导入一个已配置好的Json文件 Dashboard分享社区:grafana.com/dashboards 这里能够下载别人分享的Dashboard Json配置文件
vim grafana.ini 个人文件路径是/usr/local/etc/grafana/grafana.ini 配置以下:
[smtp]
enabled = true
host = smtp.qq.com:25
user = 你的QQ@qq.com
# If the password contains # or ; you have to wrap it with trippel quotes. Ex """#password;"""
password = 邮箱口令(不是QQ密码)
;cert_file =
;key_file =
;skip_verify = false
from_address = 你的QQ@qq.com
from_name = Grafana
# EHLO identity in SMTP dialog (defaults to instance_name)
;ehlo_identity = dashboard.example.com
复制代码
这里配置的是QQ邮箱,其余邮箱同理
配置完后,重启Grafana
brew services restart grafana
复制代码
须要注意的是,Prometheus不支持带有模版变量的监控设置报警,不然会提示“Template variables are not supported in alert queries”
监控示例: 监控CPU使用率 PromQL:
system_cpu_usage{instance="实例地址", job="任务名称"}
复制代码
感谢阅读,若有错误,望指正!
参考资料