微服务框架(二十六)Grafana dashboard 定时报表

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。本文为使用grafana-reporter生成grafana dashboard报表,并使用定时任务邮件发送

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

  本文为使用grafana-reporter生成grafana dashboard报表,并使用定时任务邮件发送

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

定时报表

Grafana是一套开源的监控图表显示框架,支持监控报警功能,而dashboard定时报表功能可使用开源软件grafana-reporter或集成Grafana API来实现

grafana-reporter

grafana-reporter由Go语言编写,是根据grafana dashboard生成PDF报表的HTTP服务

grafana-reporter生成报表的功能,需设置grafana允许匿名访问

[auth.anonymous]
# enable anonymous access
enabled = true

# specify organization name that should be used for unauthenticated users
org_name = Org

docker安装

需注意时区问题,默认生成的报表为UTC时区,推荐使用修改时区后镜像或挂载时区文件

sudo docker run -d \
--name grafana-reporter \
--net monitor \
--net host \
-p 8686:8686 \
IzakMarais/grafana-reporter

前台生成

settings —> Links —> New —> Type -> link Url

link Url:http://ip:8686/api/v5/report/uid

后台下载

wget命令下载pdf

wget -O test.pdf http://ip:8686/api/v5/report/uid?from=now-24h&to=now

mail命令

Linux系统发送邮件的命令插件有很多,如mailmuttsandmail

SMTP配置

阿里云禁止使用25端口,需使用SMTPS的465端口,并配置协议认证文件,详见参考资料

/etc/mail.rc文件末增加SMTP配置

set from=test@qq.com
set smtp=smtps://smtp.exmail.qq.com:465
set smtp-auth-user=test@qq.com
set smtp-auth-password=<auth_token>
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

示例

mail -v -s "title" example@example.com < content.txt

定时任务

contrab

59 23 * * * /media/raid10/grafana/report.sh

定时报告脚本

增加对应的dashboard报告可依照格式添加,并在mail命令中使用-a参数添加附件

#/bin/bash
#auuthor:ricardo
#shell for creating grafana dashboard report
filepath=/media/raid10/grafana/report/
date=$(date +%Y-%m-%d)

# dashboard report name
filename_es_general=Elasticsearch-Nginx-generalapi.linghit.com-${date}.pdf
filename_spring=SpringBoot-Statistics-${date}.pdf
filename_es_api=Elasticsearch-Nginx-api.linghit.com-${date}.pdf

# download grafana dashboard report
wget -O ${filepath}${filename_es_general} http://172.16.7.5:8686/api/v5/report/8oPnVDCmz?from=now-24h&to=now&var-host=test.qq.com
wget -O ${filepath}${filename_spring} http://172.16.7.5:8686/api/v5/report/wAu8Swerd?from=now-24h&to=now
wget -O ${filepath}${filename_es_api} http://172.16.7.5:8686/api/v5/report/8oPnVDCmz?from=now-24h&to=now&var-host=test.qq.com

sleep 30s

# send email
mail -v \
-a ${filepath}${filename_es_general} -a ${filepath}${filename_spring} -a ${filepath}${filename_es_api} \
-s "Grafana监控日报"-`date +%Y-%m-%d` \
-c "test@qq.com" test@qq.com < /media/raid10/grafana/content.txt

参考资料:

  1. Dashboard API
  2. 六种使用Linux命令发送带附件的邮件
  3. Centos7 配置 sendmail、postfix 端口号25、465
相关文章
|
3月前
|
Prometheus 监控 Cloud Native
Grafana 系列 - 统一展示 -12-RED Method Dashboard
Grafana 系列 - 统一展示 -12-RED Method Dashboard
|
4月前
|
Dubbo Java 应用服务中间件
微服务框架(二十七)Grafana 数据源及报警设置
此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。 本文为使用grafana数据源及报警规则设置
|
4月前
|
Prometheus Cloud Native Java
微服务框架(二十三)Prometheus + Grafana 安装、配置及使用
此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。 本文为Prometheus + Grafana 安装、配置及使用 本系列文章中所使用的框架版本为Spring ...
|
4月前
|
Prometheus 监控 Cloud Native
微服务框架(二十二)Prometheus + Grafana 可视化监控
此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。 本文为Prometheus + Grafana 可视化监控的介绍,下篇为Prometheus + Grafana...
|
4月前
|
Prometheus 监控 Cloud Native
微服务框架(十九)Spring Boot 可视化监控 Prometheus + Grafana
  此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。   本文为Spring Boot 通过 micrometer 的监控门面,实现Prometheus + G...
|
4月前
|
Prometheus 监控 Cloud Native
SpringCloud微服务实战——搭建企业级开发框架(四十五):【微服务监控告警实现方式二】使用Actuator(Micrometer)+Prometheus+Grafana实现完整的微服务监控
无论是使用SpringBootAdmin还是使用Prometheus+Grafana都离不开SpringBoot提供的核心组件Actuator。提到Actuator,又不得不提Micrometer,从SpringBoot2.x开始,Actuator的功能实现都是基于Micrometer的。
269 0
|
6月前
|
JSON 监控 数据格式
Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found
Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found
137 0
|
监控 Python
python脚本批量生成grafana中dashboard的panel
python脚本批量生成grafana中dashboard的panel
378 0
python脚本批量生成grafana中dashboard的panel
|
运维 Linux Go
grafana 8.x配置日报定时发送配置及踩坑经过
grafana 8.x配置日报定时发送配置及踩坑经过
1090 0
grafana 8.x配置日报定时发送配置及踩坑经过
|
JSON Linux Go
grafana怎么读取ganglia的rrd展示到dashboard中
grafana怎么读取ganglia的rrd展示到dashboard中
360 0
grafana怎么读取ganglia的rrd展示到dashboard中