diff --git a/collector/global_status.go b/collector/global_status.go index 21920a71..86058543 100644 --- a/collector/global_status.go +++ b/collector/global_status.go @@ -34,7 +34,7 @@ const ( ) // Regexp to match various groups of status vars. -var globalStatusRE = regexp.MustCompile(`^(com|handler|connection_errors|innodb_buffer_pool_pages|innodb_rows|performance_schema)_(.*)$`) +var globalStatusRE = regexp.MustCompile(`^(com|handler|connection_errors|innodb_buffer_pool_pages|innodb_rows|performance_schema|threads)_(.*)$`) // Metric descriptors. var ( @@ -78,6 +78,11 @@ var ( "Total number of MySQL instrumentations that could not be loaded or created due to memory constraints.", []string{"instrumentation"}, nil, ) + globalThreadsDesc = prometheus.NewDesc( + prometheus.BuildFQName(namespace, globalStatus, "threads"), + "MySQL threads in each state.", + []string{"state"}, nil, + ) ) // ScrapeGlobalStatus collects from `SHOW GLOBAL STATUS`. @@ -168,6 +173,10 @@ func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prom ch <- prometheus.MustNewConstMetric( globalPerformanceSchemaLostDesc, prometheus.CounterValue, floatVal, match[2], ) + case "threads": + ch <- prometheus.MustNewConstMetric( + globalThreadsDesc, prometheus.GaugeValue, floatVal, match[2], + ) } } else if _, ok := textItems[key]; ok { textItems[key] = string(val) diff --git a/collector/global_status_test.go b/collector/global_status_test.go index 14456c91..e78f3492 100644 --- a/collector/global_status_test.go +++ b/collector/global_status_test.go @@ -50,6 +50,10 @@ func TestScrapeGlobalStatus(t *testing.T) { AddRow("Innodb_buffer_pool_pages_made_young", "15"). AddRow("Innodb_rows_read", "8"). AddRow("Performance_schema_users_lost", "9"). + AddRow("Threads_cached", "7"). + AddRow("Threads_connected", "18"). + AddRow("Threads_created", "25"). + AddRow("Threads_running", "1"). AddRow("Slave_running", "OFF"). AddRow("Ssl_version", ""). AddRow("Uptime", "10"). @@ -87,6 +91,10 @@ func TestScrapeGlobalStatus(t *testing.T) { {labels: labelMap{"operation": "made_young"}, value: 15, metricType: dto.MetricType_COUNTER}, {labels: labelMap{"operation": "read"}, value: 8, metricType: dto.MetricType_COUNTER}, {labels: labelMap{"instrumentation": "users_lost"}, value: 9, metricType: dto.MetricType_COUNTER}, + {labels: labelMap{"state": "cached"}, value: 7, metricType: dto.MetricType_GAUGE}, + {labels: labelMap{"state": "connected"}, value: 18, metricType: dto.MetricType_GAUGE}, + {labels: labelMap{"state": "created"}, value: 25, metricType: dto.MetricType_GAUGE}, + {labels: labelMap{"state": "running"}, value: 1, metricType: dto.MetricType_GAUGE}, {labels: labelMap{}, value: 0, metricType: dto.MetricType_UNTYPED}, {labels: labelMap{}, value: 10, metricType: dto.MetricType_UNTYPED}, {labels: labelMap{}, value: 11, metricType: dto.MetricType_UNTYPED},