搭建监控平台(prometheus+pushgateway+granafa)
搭建监控平台
搭建相关环境
-
官网下载相关的安装包,解压 后台启动
// prometheus nohup ./prometheus --config.file=prometheus.yml & // pushgateway nohup ./pushgateway & // granafa nohup ./grafana-server web &
-
访问 9090端口号访问prometheus 9091端口号访问pushgateway 3000端口号访问granafa (默认的登陆账号密码为admin、admin) 在java代码里面推送指标数据到pushgateway
logger.info("开始推送数据指标到pushgateway."); try { CollectorRegistry registry = new CollectorRegistry(); Gauge duration = Gauge.build().name(指标名).help(指标信息).register(registry); // .lables .lableNames 方法可以加标签值 duration.set(Double.parseDouble(监控结果集); PushGateway pg = new PushGateway("localhost:9091"); // 分组 //Map<String, String> groupingKey = new HashMap<>(); //groupingKey.put("instance", my_instance); pg.pushAdd(registry, "my_job", groupingKey); } catch (Exception e){ logger.error("推送指标到pushgateway出现异常", e); e.printStackTrace(); }
到这里就有数据被推上pushgateway,然后prometheus会定时从这里拉取指标数据,之后可以把指标数据通过granafa展示出来
在granafa中配置prometheus数据源和面板,可以将图表更好的显示出来
清空promethus指标数据
-
增加参数重新启动
nohup ./prometheus --config.file=prometheus.yml --web.enable-admin-api &
-
调用相关的API
curl -X POST -g http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={job="任务名"}
grafana中加入短信告警
-
配置通道和告警规则
-
通道 告警 点击Panel Titel下的Edit,点击Alert配置相关告警信息