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
相关推荐
川石课堂软件测试1 天前
软件测试|常见面试题整理
数据库·python·jmeter·mysql·appium·postman·prometheus
蜀道山老天师1 天前
云原生监控入门:监控基础概念 + SLI/SLO/SLA 详解 + Prometheus 从零安装配置
linux·运维·云原生·prometheus
专业白嫖怪1 天前
监控平台Prometheus+Grafana的部署
运维·grafana·prometheus
Elastic 中国社区官方博客2 天前
从平均值到任意百分位数:Elasticsearch 在 ES|QL 中原生支持指数直方图
大数据·数据库·sql·elasticsearch·搜索引擎·全文检索·prometheus
Elastic 中国社区官方博客2 天前
在 Elasticsearch 中使用原生 PromQL 支持查询 Prometheus 指标
大数据·elasticsearch·搜索引擎·信息可视化·全文检索·prometheus
Elastic 中国社区官方博客2 天前
Elastic 9.4:Workflows 正式发布、Agent Builder 更新,以及 Prometheus / PromQL 支持
运维·数据库·人工智能·elasticsearch·搜索引擎·信息可视化·prometheus
虎头金猫4 天前
监控机不在被监控的机器上,Prometheus怎么跨网络把数据拉过来
运维·服务器·开发语言·网络·云原生·开源·prometheus
YaBingSec6 天前
网络安全靶场WP:Grafana 任意文件读取漏洞(CVE-2021-43798)
android·笔记·安全·web安全·ssh·grafana
四方云6 天前
Kamailio + Prometheus 集成方案(含完整可执行配置)
prometheus
雨辰AI7 天前
SpringBoot3 + 人大金仓 V9 微服务监控实战|Prometheus+Grafana+SkyWalking 全链路监控
数据库·后端·微服务·grafana·prometheus·skywalking