天天看点

SpringBoot+Actuator+Prometheus+Consul+Grafana监控系列(三)

上一篇将所有的监控工具安装完成,并编写了各个脚本;

这一篇进行项目编写.

项目地址在下方

添加consul依赖

<dependency>
  <groupId>com.ecwid.consul</groupId>
  <artifactId>consul-api</artifactId>
  <version>1.4.2</version>
</dependency>
           

项目结构

SpringBoot+Actuator+Prometheus+Consul+Grafana监控系列(三)

consul在项目中的配置

#consul 配置
#设置为true,允许注册
toona.metrics.registry.enabled = true
#需要注册的host地址,  对应服务器中consul配置的绑定地址
toona.metrics.registry.host=127.0.0.1
toona.metrics.registry.port=7001

           

consul编写代码较多,这里就不粘贴了. 项目整体会放在GitHub上, 需要的可以Github上面下载;

这个时候整体集成已经完成.可以 启动各个服务进行查看;

查看consul发现的服务: localhost:7001

prometheus视图: localhost:7002

grafana设置可匿名访问

访问的时候,需要账号密码, 默认是admin/admin. 但是admin的权限太大. 有时候我们需要的只是简单的浏览,不需要任何权限,这个时候就可以配置匿名访问; 在/data/monitor/cfg/grafana/下,打开grafana配置文件, 找到Anonymous Auth板块,修改:

enabled = true  //默认false
org_name = Main.Org
org_role = Viewer
           

如此便可以不需要登录就可以访问了. 具体读/写,或者组,机构等权限的配置请参考:

https://grafana.com/docs/installation/configuration/

到此为止,基本的监控平台已经搭建完成,剩下我们需要针对性的配置grafana视图,便于清晰查看所监控的数据; 下一篇会配置grafana;

GitHub: https://github.com/qinyunsurd/monitor