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_queries5m)

本节重点总结 :

  • grafana 上导入mysqld-dashboard
    • 变量的处理,没有图,变量解析的不对
  • global status 相关源码解读
  • 重要指标讲解
    • 连接数
    • 内存
    • TPS、QPS
相关推荐
龙腾-虎跃2 天前
Docker 一键启动服务合集:Redis、MySQL、Kafka、MinIO、Prometheus 等(网盘转存防失效)
redis·mysql·docker·kafka·prometheus·小龙虾·miniio
Duang007_3 天前
生产可观测性:从“系统慢“到“根因“的完整链路(Go / TypeScript)
后端·python·golang·typescript·prometheus
JWASX3 天前
go 学习 - prometheus 指标学习
学习·golang·prometheus
JWASX3 天前
go 学习 - prometheus 指标协程池监控
学习·golang·prometheus
爱琴孩5 天前
记一次Prometheus的WAL异常,导致服务器磁盘占用过高
prometheus·wal
Cheney Pan6 天前
第12篇 Prometheus 高可用与长期存储
prometheus
飞鸟真人6 天前
应用性能监测(APM)之 (五)Prometheus与OpenMetrics协议
prometheus·apm·open telemetry·openmetrics
Cheney Pan6 天前
第13篇 监控安全与权限治理
安全·prometheus
蓝胖的四次元口袋8 天前
Prometheus+Grafana知识梳理(2)
grafana·prometheus
Cheney Pan9 天前
第8篇 关键指标分析方法:RED/USE 与黄金信号
prometheus