8.2 grafana上导入模板看图并讲解告警

本节重点介绍 :

  • grafana 上导入mysqld-dashboard
  • global status 相关源码解读
  • 重要指标讲解
    • 连接数
    • 内存
    • TPS、QPS

将采集任务添加到prometheus中

yaml 复制代码
  - job_name: mysqld_exporter
    honor_timestamps: true
    scrape_interval: 8s
    scrape_timeout: 8s
    metrics_path: /metrics
    scheme: http
    follow_redirects: true
    static_configs:
    - targets:
      - 192.168.3.200:9104

grafana 上导入mysqld-dashboard

调整大盘变量

  • 举例图片
  • 最终的效果图

指标讲解和相关源码讲解

global status 相关的

mysql_global_status_threads_connected 表示当前连接数

  • 源码 位置 D:\go_path\src\github.com\ning1875\mysqld_exporter\collector\global_status.go
  • 执行SHOW GLOBAL STATUS命令,逐行遍历,如果key 不在 正则中,则用 mysql_global_status前缀+key,类型为prometheus.UntypedValue
  • scrape函数
go 复制代码
func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error {
	globalStatusRows, err := db.QueryContext(ctx, globalStatusQuery)

	for globalStatusRows.Next() {
		if err := globalStatusRows.Scan(&key, &val); err != nil {
			return err
		}
		if floatVal, ok := parseStatus(val); ok { // Unparsable values are silently skipped.
			key = validPrometheusName(key)
			match := globalStatusRE.FindStringSubmatch(key)
			if match == nil {
				ch <- prometheus.MustNewConstMetric(
					newDesc(globalStatus, key, "Generic metric from SHOW GLOBAL STATUS."),
					prometheus.UntypedValue,
					floatVal,
				)
				continue
			}
  • globalStatusRE正则
go 复制代码
mysql_global_variables_innodb_buffer_pool_sizevar globalStatusRE = regexp.MustCompile(`^(com|handler|connection_errors|innodb_buffer_pool_pages|innodb_rows|performance_schema)_(.*)$`)
  • 指标metrics结果
shell 复制代码
# HELP mysql_global_status_threads_connected Generic metric from SHOW GLOBAL STATUS.
# TYPE mysql_global_status_threads_connected untyped
mysql_global_status_threads_connected 9

- 为什么进行这样

其它连接数

  • mysql_global_status_max_used_connections 表示 服务器启动后已经同时使用的连接的最大数量
  • mysql_global_variables_max_connections 表示 最大连接数
  • mysql_global_status_questions 已执行的由客户端发出的语句
  • mysql_global_status_aborted_connects 尝试已经失败的MySQL服务器的连接的次数
  • mysql_global_status_aborted_clients 由于客户没有正确关闭连接已经死掉,已经放弃的连接数量

内存

  • mysql_global_status_innodb_page_size innodb内存划分粒度
  • mysql_global_status_buffer_pool_pages 用于缓存索引和数据的内存大小
  • mysql_global_variables_innodb_log_buffer_size 用来设置缓存还未提交的事务的缓冲区的大小

TPS 服务器每秒处理的事务数

  • 计算方法
shell 复制代码
Com_commit = SHOW GLOBAL STATUS LIKE 'Com_commit'; 
Com_rollback = SHOW GLOBAL STATUS LIKE 'Com_rollback'; 
Uptime = SHOW GLOBAL STATUS LIKE 'Uptime'; 
TPS=(Com_commit + Com_rollback)/Uptime 
  • promqlsum(rate(mysql_global_status_commands_total{command=~"(commit|rollback)"}[5m])) without (command)

QPS

  • 计算方法
shell 复制代码
Questions = SHOW GLOBAL STATUS LIKE 'Questions'; 
Uptime = SHOW GLOBAL STATUS LIKE 'Uptime'; 
QPS=Questions/Uptime 
  • promql irate(mysql_global_status_queries[5m])

本节重点总结 :

  • grafana 上导入mysqld-dashboard
    • 变量的处理,没有图,变量解析的不对
  • global status 相关源码解读
  • 重要指标讲解
    • 连接数
    • 内存
    • TPS、QPS
相关推荐
鬼先生_sir8 小时前
Spring Cloud 微服务监控实战:SkyWalking + Prometheus+Grafana 全栈解决方案
运维·spring cloud·grafana·prometheus·skywalking
SkyWalking中文站2 天前
使用 TraceQL 查询 SkyWalking 和 Zipkin 链路追踪数据并在 Grafana 中可视化
运维·grafana·监控
zs宝来了2 天前
Prometheus 监控体系原理:Pull 模式与 TSDB 时序数据库
prometheus·时序数据库·监控·tsdb·pull模式
何中应3 天前
Alertmanager设置邮件通知
运维·自动化·prometheus
安审若无3 天前
运维监控及可视化工具Prometheus和grafana
运维·grafana·prometheus
却话巴山夜雨时i3 天前
互联网大厂Java面试实录:从Spring Boot到Kafka的场景应用深度解析
spring boot·kafka·prometheus·微服务架构·java面试·技术解析·互联网大厂
却话巴山夜雨时i4 天前
Java面试实录:从Spring Boot到Kafka的技术探讨
spring boot·微服务·kafka·grafana·prometheus·java面试
阿杜杜不是阿木木4 天前
authentik开源身份认证与管理平台-与 Grafana 集成(12)
grafana·authentik
人人常欢笑7 天前
Grafana 表格自定义下载样式。
javascript·react.js·grafana
川石课堂软件测试7 天前
涨薪技术|Prometheus使用Recoding Rules优化性能
功能测试·测试工具·jmeter·mysql·面试·单元测试·prometheus