Skip to content

Commit 047fd97

Browse files
committed
set type of mysql_global_status_threads_* to gauge
Signed-off-by: Ali Orouji <[email protected]>
1 parent fbb8022 commit 047fd97

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

collector/global_status.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434
)
3535

3636
// Regexp to match various groups of status vars.
37-
var globalStatusRE = regexp.MustCompile(`^(com|handler|connection_errors|innodb_buffer_pool_pages|innodb_rows|performance_schema)_(.*)$`)
37+
var globalStatusRE = regexp.MustCompile(`^(com|handler|connection_errors|innodb_buffer_pool_pages|innodb_rows|performance_schema|threads)_(.*)$`)
3838

3939
// Metric descriptors.
4040
var (
@@ -78,6 +78,11 @@ var (
7878
"Total number of MySQL instrumentations that could not be loaded or created due to memory constraints.",
7979
[]string{"instrumentation"}, nil,
8080
)
81+
globalThreadsDesc = prometheus.NewDesc(
82+
prometheus.BuildFQName(namespace, globalStatus, "threads"),
83+
"MySQL threads in each state.",
84+
[]string{"state"}, nil,
85+
)
8186
)
8287

8388
// ScrapeGlobalStatus collects from `SHOW GLOBAL STATUS`.
@@ -168,6 +173,10 @@ func (ScrapeGlobalStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prom
168173
ch <- prometheus.MustNewConstMetric(
169174
globalPerformanceSchemaLostDesc, prometheus.CounterValue, floatVal, match[2],
170175
)
176+
case "threads":
177+
ch <- prometheus.MustNewConstMetric(
178+
globalThreadsDesc, prometheus.GaugeValue, floatVal, match[2],
179+
)
171180
}
172181
} else if _, ok := textItems[key]; ok {
173182
textItems[key] = string(val)

collector/global_status_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func TestScrapeGlobalStatus(t *testing.T) {
5050
AddRow("Innodb_buffer_pool_pages_made_young", "15").
5151
AddRow("Innodb_rows_read", "8").
5252
AddRow("Performance_schema_users_lost", "9").
53+
AddRow("Threads_cached", "7").
54+
AddRow("Threads_connected", "18").
55+
AddRow("Threads_created", "25").
56+
AddRow("Threads_running", "1").
5357
AddRow("Slave_running", "OFF").
5458
AddRow("Ssl_version", "").
5559
AddRow("Uptime", "10").
@@ -87,6 +91,10 @@ func TestScrapeGlobalStatus(t *testing.T) {
8791
{labels: labelMap{"operation": "made_young"}, value: 15, metricType: dto.MetricType_COUNTER},
8892
{labels: labelMap{"operation": "read"}, value: 8, metricType: dto.MetricType_COUNTER},
8993
{labels: labelMap{"instrumentation": "users_lost"}, value: 9, metricType: dto.MetricType_COUNTER},
94+
{labels: labelMap{"state": "cached"}, value: 7, metricType: dto.MetricType_GAUGE},
95+
{labels: labelMap{"state": "connected"}, value: 18, metricType: dto.MetricType_GAUGE},
96+
{labels: labelMap{"state": "created"}, value: 25, metricType: dto.MetricType_GAUGE},
97+
{labels: labelMap{"state": "running"}, value: 1, metricType: dto.MetricType_GAUGE},
9098
{labels: labelMap{}, value: 0, metricType: dto.MetricType_UNTYPED},
9199
{labels: labelMap{}, value: 10, metricType: dto.MetricType_UNTYPED},
92100
{labels: labelMap{}, value: 11, metricType: dto.MetricType_UNTYPED},

0 commit comments

Comments
 (0)