#《56_C2C电商社会化治理平台的监控体系设计》
具体部署不用演示了,因为比较简单,给一下步骤就行
#prometheus-2.4.0.linux-amd64.tar.gz
tar -zxvf prometheus-2.4.0.linux-amd64.tar.gz -C /data
cd /data
chown -R root:root prometheus-2.4.0.linux-amd64
ln -sv prometheus-2.4.0.linux-amd64 prometheus
cd /data/prometheus
./prometheus直接访问本机的9090端口号,就能看到prometheus的web ui
接着就是对要监控的机器去部署node exporter,是基于go语言写的,可以拿到cpu、内存、磁盘空间、磁盘io、网络带宽、系统负载、主板温度等一系列的机器资源监控指标,这个是最基本要做的监控
在https://prometheus.io/download/里面找到node exporter的下载地址,下载一个最新的版本,接着进行解压缩,直接./node_exporter运行起来,就O了,默认的监听端口是9100,然后再把这个node exporter跟prometheus集成起来
编辑prometheus的配置文件,有一个prometheus.yml,里面需要加入job去跟node_exporter进行集成
scrape_configs:
- job_name: ‘prometheus’
static_configs:
-targets: [‘192.168.xx.xx:9090’]
- job_name: ‘node_exporter’
static_configs:
-targets: [‘192.168.xx.xx:9100’]重启prometheus server就可以了,直接进入web ui就可以在targets里找到你要监控的机器,然后里面各项资源监控报表都可以看到了
让spring boot业务系统接入prometheus也很简单,首先是加入一些依赖
就是io.prometheus.simpleclient相关的一些依赖,这个其实大家可以自行搜索,网上很多文章讲这个,我们就是说思路,然后在Application类上加入@EnablePrometheusEndpoint注解就可以了
此时你访问http://localhost:8080/prometheus,就可以看到jvm的监控指标了
如果还要接入自定义的指标,需要加入一个拦截器,然后代码里用prometheus client提供的Counter类去进行指标计数就可以了,除此之外,还有gauge、Histogram之类的指标收集API,都可以用来统计业务指标,然后就跟之前一样,接入prometheus即可
业务指标:需要采集三个,异常指标,QPS,接口时延,TP99,TP95,TP90
其实说实话,这些操作步骤,搜索就是很多,所以不带着大家做了,但是希望大家脑子里应该有这么个思路