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
相关推荐
牛奶咖啡132 分钟前
Prometheus+Grafana构建云原生分布式监控系统(二)
prometheus·prometheus工作流程·prometheus适用场景·prometheus下载安装·prometheus指标解析·ntp时间同步操作·prometheus配置解析
这儿有个昵称16 小时前
互联网大厂Java面试场景:从Spring框架到微服务架构的提问解析
java·spring boot·微服务·kafka·grafana·prometheus·数据库优化
·云扬·2 天前
使用Prometheus+Grafana实现Elasticsearch监控的完整实践
elasticsearch·grafana·prometheus
忍冬行者3 天前
prometheus通过VMware_explorter监控VMware虚拟化集群
云原生·云计算·grafana·prometheus
L1624764 天前
Prometheus、Cadvisor和Grafana体系完整学习手册
学习·grafana·prometheus
·云扬·4 天前
ClickHouse监控体系搭建:基于Prometheus+Grafana实现数据可视化
clickhouse·grafana·prometheus
小二·4 天前
Python Web 开发进阶实战:性能压测与调优 —— Locust + Prometheus + Grafana 构建高并发可观测系统
前端·python·prometheus
zxcxylong5 天前
almalinux下部署promethues+grafana服务-容器化
docker·grafana·prometheus·docker compose·almalinux
A-刘晨阳5 天前
【云原生】Prometheus之PromQL用法详解
运维·云原生·grafana·prometheus·监控·promql
牛奔6 天前
grafana 二次开发,制作镜像流程
grafana