Skip to content

Commit

Permalink
Add label aggregation for innodb buffer metrics
Browse files Browse the repository at this point in the history
Add label aggregation for innodb_metrics buffer subsystem.
* Total can be ignored as it is an aggregation of data+misc+free
* Dirty pages are not aggregateable, keep as a separate metric.
  • Loading branch information
SuperQ committed Jun 5, 2016
1 parent 4a0d95d commit b386f9e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
39 changes: 38 additions & 1 deletion collector/info_schema_innodb_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,23 @@ var (
"Total number of buffer pages written total.",
[]string{"type"}, nil,
)
infoSchemaBufferPoolPagesDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "innodb_metrics_buffer_pool_pages"),
"Total number of buffer pool pages by state.",
[]string{"state"}, nil,
)
infoSchemaBufferPoolPagesDirtyDesc = prometheus.NewDesc(
prometheus.BuildFQName(namespace, informationSchema, "innodb_metrics_buffer_pool_dirty_pages"),
"Total number of dirty pages in the buffer pool.",
nil, nil,
)
)

// Regexp for matching metric aggregations.
var bufferPageRE = regexp.MustCompile(`^buffer_page_(read|written)_(.*)$`)
var (
bufferRE = regexp.MustCompile(`^buffer_(pool_pages)_(.*)$`)
bufferPageRE = regexp.MustCompile(`^buffer_page_(read|written)_(.*)$`)
)

// ScrapeInnodbMetrics collects from `information_schema.innodb_metrics`.
func ScrapeInnodbMetrics(db *sql.DB, ch chan<- prometheus.Metric) error {
Expand Down Expand Up @@ -73,6 +86,30 @@ func ScrapeInnodbMetrics(db *sql.DB, ch chan<- prometheus.Metric) error {
}
continue
}
if subsystem == "buffer" {
match := bufferRE.FindStringSubmatch(name)
// Many buffer substem metrics are not matched, fall through to generic metric.
if match != nil {
switch match[1] {
case "pool_pages":
switch match[2] {
case "total":
// Ignore total, it is an aggregation of the rest.
continue
case "dirty":
// Dirty pages are a separate metric, not in the total.
ch <- prometheus.MustNewConstMetric(
infoSchemaBufferPoolPagesDirtyDesc, prometheus.GaugeValue, value,
)
default:
ch <- prometheus.MustNewConstMetric(
infoSchemaBufferPoolPagesDesc, prometheus.GaugeValue, value, match[2],
)
}
}
continue
}
}
metricName := "innodb_metrics_" + subsystem + "_" + name
// MySQL returns counters named two different ways. "counter" and "status_counter"
// value >= 0 is necessary due to upstream bugs: http://bugs.mysql.com/bug.php?id=75966
Expand Down
7 changes: 6 additions & 1 deletion collector/info_schema_innodb_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ func TestScrapeInnodbMetrics(t *testing.T) {
AddRow("buffer_pool_size", "server", "value", "Server buffer pool size (all buffer pools) in bytes", 2).
AddRow("buffer_page_read_system_page", "buffer_page_io", "counter", "Number of System Pages read", 3).
AddRow("buffer_page_written_undo_log", "buffer_page_io", "counter", "Number of Undo Log Pages written", 4).
AddRow("NOPE", "buffer_page_io", "counter", "An invalid buffer_page_io metric", 5)
AddRow("buffer_pool_pages_dirty", "buffer", "gauge", "Number of Undo Log Pages written", 5).
AddRow("buffer_pool_pages_data", "buffer", "gauge", "Number of Undo Log Pages written", 6).
AddRow("buffer_pool_pages_total", "buffer", "gauge", "Number of Undo Log Pages written", 7).
AddRow("NOPE", "buffer_page_io", "counter", "An invalid buffer_page_io metric", 999)
mock.ExpectQuery(sanitizeQuery(infoSchemaInnodbMetricsQuery)).WillReturnRows(rows)

ch := make(chan prometheus.Metric)
Expand All @@ -47,6 +50,8 @@ func TestScrapeInnodbMetrics(t *testing.T) {
{labels: labelMap{}, value: 2, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"type": "system_page"}, value: 3, metricType: dto.MetricType_COUNTER},
{labels: labelMap{"type": "undo_log"}, value: 4, metricType: dto.MetricType_COUNTER},
{labels: labelMap{}, value: 5, metricType: dto.MetricType_GAUGE},
{labels: labelMap{"state": "data"}, value: 6, metricType: dto.MetricType_GAUGE},
}
convey.Convey("Metrics comparison", t, func() {
for _, expect := range metricExpected {
Expand Down

0 comments on commit b386f9e

Please sign in to comment.