微服务框架(二十三)Prometheus + Grafana 安装、配置及使用

版权声明:觉得此文有用的,就点个赞或留个言呐~ 若要转载的话,请注明文章出处: https://blog.csdn.net/why_still_confused/article/details/88429168

此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。

本文为Prometheus + Grafana 安装、配置及使用

本系列文章中所使用的框架版本为Spring Boot 2.0.3-RELEASE,Spring 5.0.7-RELEASE,Dubbo 2.6.2。

Prometheus

prometheus.yml

先创建prometheus.yml文件,初始化配置

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['127.0.0.1:9090']

docker容器启动

采集数据持久化在磁盘中,docker启动时挂载的data目录需授权

prometheus 运行过程中使用的用户是nobodydata目录权限需设置为757

  • prometheus.yml为promethus的配置文件,修改后需重启生效
  • /prometheus/data为promethus的磁盘持久化数据
  • --config.file=/etc/prometheus/prometheus.yml为启动容器时加载的配置文件
docker run -d \
--name prometheus \
--net monitor \
--hostname prom \
-p 9090:9090 \
-v /media/raid10/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /media/raid10/prometheus/data:/prometheus/data \
prom/prometheus \
--config.file=/etc/prometheus/prometheus.yml

增加promtheus拉取数据的项目,需在挂载的配置文件prometheus.yml中增加对应的Endpoint设置并重启服务

增加数据采集点

修改prometheus.yml配置文件

scrape_configs:
  - job_name: 'controller'
    metrics_path: '/actuator/prometheus'
    static_configs:
      - targets: ['localhost:9700']
        labels: 
          application: dubbo

重启Prometheus

docker restart prometheus

最佳做法

  1. --storage.tsdb.retention.time定义旧数据的删除策略,默认为15d
  2. Prometheus RE2语法正则表达式

Grafana

docker容器启动

  • auth.anonymous为匿名登录选项,设置为enabled=true即可免登录(Viewer)
  • grafana.ini为配置文件
  • 挂载/etc/timezone/etc/localtime文件,使grafana-reporter生成报表时使用服务器时区
docker run -d \
--name grafana \
--net monitor \
-p 3000:3000 \
-v /media/raid10/grafana/grafana.ini:/etc/grafana/grafana.ini \
-v grafana:/var/lib/grafana \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
grafana/grafana

监控报警

  1. 添加监控通知渠道Alerting->Notifications channels
  2. 为图表设置报警配置Alert Config
  3. 为图表设置添加报警渠道及信息

常用的报警渠道有EmailDingDingWebhook

模板变量

报警中不能使用带模板变量的查询语句

issue-查询语句的模板变量支持

dashboard

常用模板

plugins

1.进入容器

docker exec -it grafana /bin/bash

2.安装对应插件

grafana-cli plugins install grafana-piechart-panel

查找对应的图表ID,安装完成后退出容器

3.重启grafana

docker restart grafana

猜你喜欢

转载自blog.csdn.net/why_still_confused/article/details/88429168
今日推荐