Skip to content

Commit

Permalink
Merge pull request #1 from aliorouji/set-type-of-mysql_global_status_…
Browse files Browse the repository at this point in the history
…threads-metrics

set type of mysql_global_status_threads_* to gauge
  • Loading branch information
aliorouji authored Feb 15, 2022
2 parents e2ff660 + 3427b9b commit 990d129
Show file tree
Hide file tree
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
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 @@ -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)
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 @@ -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").
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit 990d129

Please sign in to comment.