Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
set type of mysql_global_status_threads_* to gauge
Browse files Browse the repository at this point in the history
Signed-off-by: Ali Orouji <ali.orouji@booking.com>
alio-booking committed Feb 15, 2022
1 parent fbb8022 commit 047fd97
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion collector/global_status.go
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions collector/global_status_test.go
Original file line number Diff line number Diff line change
@@ -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},

0 comments on commit 047fd97

Please sign in to comment.