Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set type of mysql_global_status_threads_* to gauge #615

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion collector/global_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -169,6 +174,10 @@ func (ScrapeGlobalStatus) Scrape(ctx context.Context, instance *instance, ch cha
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)
Expand Down
8 changes: 8 additions & 0 deletions collector/global_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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").
Expand Down Expand Up @@ -88,6 +92,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},
Expand Down