最简单使用promethus+spring boot admin搭建spring boot应用监控系统
promethus的安装使用
下载
打开download页面,选择操作系统(Operating system),cpu架构(Architecture)后选择对应的软件下载即可
- prometheus是监控系统,和一个内嵌的时间序列数据库
- alertmanager是告警的组件
因为是springboot应用的监控 所以主要使用这两个就可以(其他组件提供了探测功能,spring boot自身使用actuator提供这些探测信息)
因为主要是在linux上使用,所以下面讲的都是linux的操作
解压到prometheus到一个指定的位置,暂定**/app/monitor-admin/prometheus/**
解压之后有各种各样的文件
- prometheus是可执行文件,要有x权限才能使用
- prometheus.yml是配置文件,yml风格如果手写比较容易出错,最好使用相应的编辑器编写
解压alertmanager到**/app/monitor-admin/prometheus/里面,所以目录是/app/monitor-admin/prometheus/alertmanager**
文件命名风格基本一致
- alertmanager是可执行文件,要有x权限才能使用
- alertmanager.yml是配置文件
启动
启动prometheus最好使用如下命令
./prometheus --config.file=./prometheus.yml --web.enable-lifecycle
#--config.file=./prometheus.yml 指定配置
#--web.enable-lifecycle这个参数的主要目的是为了运行时重载配置
启动完成后使用ip:9090就可以访问到Prometheus的页面了
启动alertmanager可以使用类似的命令
alertmanager的默认端口是9093
简单配置
一个简单的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 这个是Alertmanager的配置
alerting:
alertmanagers:
- static_configs:
- targets:
- 127.0.0.1:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "agent_monitor.yml" #这个是页面上的rules的配置文件
# - "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'.
- job_name: 'agent-server-monitor' #某个job的名字
metrics_path: '/actuator/prometheus' #Prometheus采集的uri,在这里是spring boot提供的promethus接口
scrape_interval: 15s
static_configs:
- targets: ['192.168.6.28:8099'] #目标,实际上就是一个应用的ip:port
labels:
instance: server #实例
name: 192.168.6.28:8099 #区分各个实例,这个标签是可以任意添加的,在这里我的instance代表的是应用的功能,name作为区分
- targets: ['192.168.5.22:8099']
labels:
instance: server
name: 192.168.5.22:8099
agent_monitor.yml 这个配置可以这样子检查
promtool check rules /path/to/example.rules.yml
groups:
- name: monitor
rules:
- alert: InstanceDown
ex