Skip to content

Commit f175ec9

Browse files
committed
PMM-2019 Moved buffer from values to parameters
1 parent f7e64ff commit f175ec9

File tree

3 files changed

+35
-42
lines changed

3 files changed

+35
-42
lines changed

collector/info_schema_innodb_cmp.go

+6-10
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,30 @@ var (
2424
vtype prometheus.ValueType
2525
desc *prometheus.Desc
2626
}{
27-
"page_size": {prometheus.CounterValue,
28-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_page_size"),
29-
"Compressed page size in bytes.",
30-
[]string{"page_size"}, nil)},
3127
"compress_ops": {prometheus.CounterValue,
32-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_ops"),
28+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_ops_total"),
3329
"Number of times a B-tree page of the size PAGE_SIZE has been compressed.",
3430
[]string{"page_size"}, nil)},
3531
"compress_ops_ok": {prometheus.CounterValue,
36-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_ops_ok"),
32+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_ops_ok_total"),
3733
"Number of times a B-tree page of the size PAGE_SIZE has been successfully compressed.",
3834
[]string{"page_size"}, nil)},
3935
"compress_time": {prometheus.CounterValue,
40-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_time"),
36+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_compress_time_seconds_total"),
4137
"Total time in seconds spent in attempts to compress B-tree pages.",
4238
[]string{"page_size"}, nil)},
4339
"uncompress_ops": {prometheus.CounterValue,
44-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_uncompress_ops"),
40+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_uncompress_ops_total"),
4541
"Number of times a B-tree page has been uncompressed.",
4642
[]string{"page_size"}, nil)},
4743
"uncompress_time": {prometheus.CounterValue,
48-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_uncompress_time"),
44+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmp_uncompress_time_seconds_total"),
4945
"Total time in seconds spent in uncompressing B-tree pages.",
5046
[]string{"page_size"}, nil)},
5147
}
5248
)
5349

54-
// ScrapeInnodbCmp collects from `information_schema.innodb_cmp`.
50+
// ScrapeClientStat collects from `information_schema.client_statistics`.
5551
type ScrapeInnodbCmp struct{}
5652

5753
// Name of the Scraper.

collector/info_schema_innodb_cmpmem.go

+23-24
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,30 @@ const innodbCmpMemQuery = `
1717
FROM information_schema.INNODB_CMPMEM
1818
`
1919

20+
//Metric descriptors.
2021
var (
2122
// Map known innodb_cmp values to types. Unknown types will be mapped as
2223
// untyped.
2324
informationSchemaInnodbCmpMemTypes = map[string]struct {
2425
vtype prometheus.ValueType
2526
desc *prometheus.Desc
2627
}{
27-
"page_size": {prometheus.CounterValue,
28-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_page_size"),
29-
"Block size in bytes.",
30-
[]string{"page_size"}, nil)},
31-
"buffer_pool_instance": {prometheus.CounterValue,
32-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_buffer_pool_instance"),
33-
"A unique identifier for the buffer pool instance.",
34-
[]string{"page_size"}, nil)},
3528
"pages_used": {prometheus.CounterValue,
36-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_pages_used"),
29+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_pages_used_total"),
3730
"Number of blocks of the size PAGE_SIZE that are currently in use.",
38-
[]string{"page_size"}, nil)},
31+
[]string{"page_size", "buffer"}, nil)},
3932
"pages_free": {prometheus.CounterValue,
40-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_pages_free"),
33+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_pages_free_total"),
4134
"Number of blocks of the size PAGE_SIZE that are currently available for allocation.",
42-
[]string{"page_size"}, nil)},
35+
[]string{"page_size", "buffer"}, nil)},
4336
"relocation_ops": {prometheus.CounterValue,
44-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_relocation_ops"),
37+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_relocation_ops_total"),
4538
"Number of times a block of the size PAGE_SIZE has been relocated.",
46-
[]string{"page_size"}, nil)},
39+
[]string{"page_size", "buffer"}, nil)},
4740
"relocation_time": {prometheus.CounterValue,
48-
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_relocation_time"),
41+
prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, "innodb_cmpmem_relocation_time_seconds_total"),
4942
"Total time in microseconds spent in relocating blocks of the size PAGE_SIZE.",
50-
[]string{"page_size"}, nil)},
43+
[]string{"page_size", "buffer"}, nil)},
5144
}
5245
)
5346

@@ -80,40 +73,46 @@ func (ScrapeInnodbCmpMem) Scrape(db *sql.DB, ch chan<- prometheus.Metric) error
8073

8174
// The client column is assumed to be column[0], while all other data is assumed to be coerceable to float64.
8275
// Because of the client column, clientStatData[0] maps to columnNames[1] when reading off the metrics
83-
// (because clientStatScanArgs is mapped as [ &client, &clientData[0], &clientData[1] ... &clientdata[n] ]
76+
// (because clientStatScanArgs is mapped as [ &client, &buffer, &clientData[0], &clientData[1] ... &clientdata[n] ]
8477
// To map metrics to names therefore we always range over columnNames[1:]
8578
columnNames, err := informationSchemaInnodbCmpMemRows.Columns()
79+
8680
if err != nil {
8781
log.Debugln("INNODB_CMPMEM stats are not available.")
8882
return err
8983
}
9084

9185
var (
9286
client string // Holds the client name, which should be in column 0.
93-
clientStatData = make([]float64, len(columnNames)-1) // 1 less because of the client column.
87+
buffer string // Holds the buffer number, which should be in column 1.
88+
clientStatData = make([]float64, len(columnNames)-2) // 2 less because of the client column.
9489
clientStatScanArgs = make([]interface{}, len(columnNames))
9590
)
9691

9792
clientStatScanArgs[0] = &client
93+
clientStatScanArgs[1] = &buffer
9894
for i := range clientStatData {
99-
clientStatScanArgs[i+1] = &clientStatData[i]
95+
clientStatScanArgs[i+2] = &clientStatData[i]
10096
}
10197

10298
for informationSchemaInnodbCmpMemRows.Next() {
10399
if err := informationSchemaInnodbCmpMemRows.Scan(clientStatScanArgs...); err != nil {
104100
return err
105101
}
106-
107102
// Loop over column names, and match to scan data. Unknown columns
108103
// will be filled with an untyped metric number. We assume other then
109104
// cient, that we'll only get numbers.
110-
for idx, columnName := range columnNames[1:] {
105+
for idx, columnName := range columnNames[2:] {
111106
if metricType, ok := informationSchemaInnodbCmpMemTypes[columnName]; ok {
112-
ch <- prometheus.MustNewConstMetric(metricType.desc, metricType.vtype, float64(clientStatData[idx]), client)
107+
if columnName == "relocation_time" {
108+
ch <- prometheus.MustNewConstMetric(metricType.desc, metricType.vtype, float64(clientStatData[idx]/1000), client, buffer)
109+
} else {
110+
ch <- prometheus.MustNewConstMetric(metricType.desc, metricType.vtype, float64(clientStatData[idx]), client, buffer)
111+
}
113112
} else {
114113
// Unknown metric. Report as untyped.
115-
desc := prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, fmt.Sprintf("innodb_cmpmem_%s", strings.ToLower(columnName))), fmt.Sprintf("Unsupported metric from column %s", columnName), []string{"page_size"}, nil)
116-
ch <- prometheus.MustNewConstMetric(desc, prometheus.UntypedValue, float64(clientStatData[idx]), client)
114+
desc := prometheus.NewDesc(prometheus.BuildFQName(namespace, informationSchema, fmt.Sprintf("innodb_cmpmem_%s", strings.ToLower(columnName))), fmt.Sprintf("Unsupported metric from column %s", columnName), []string{"page_size", "buffer"}, nil)
115+
ch <- prometheus.MustNewConstMetric(desc, prometheus.UntypedValue, float64(clientStatData[idx]), client, buffer)
117116
}
118117
}
119118
}

collector/info_schema_innodb_cmpmem_test.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ func TestScrapeInnodbCmpMem(t *testing.T) {
1616
}
1717
defer db.Close()
1818

19-
columns := []string{"page_size", "page_size", "buffer_pool_instance", "pages_used", "pages_free", "relocation_ops", "relocation_time"}
19+
columns := []string{"page_size", "buffer", "pages_used", "pages_free", "relocation_ops", "relocation_time"}
2020
rows := sqlmock.NewRows(columns).
21-
AddRow("1024", 10, 20, 30, 40, 50, 60)
21+
AddRow("1024", "0", 30, 40, 50, 60)
2222
mock.ExpectQuery(sanitizeQuery(innodbCmpMemQuery)).WillReturnRows(rows)
2323

2424
ch := make(chan prometheus.Metric)
@@ -30,12 +30,10 @@ func TestScrapeInnodbCmpMem(t *testing.T) {
3030
}()
3131

3232
expected := []MetricResult{
33-
{labels: labelMap{"page_size": "1024"}, value: 10, metricType: dto.MetricType_COUNTER},
34-
{labels: labelMap{"page_size": "1024"}, value: 20, metricType: dto.MetricType_COUNTER},
35-
{labels: labelMap{"page_size": "1024"}, value: 30, metricType: dto.MetricType_COUNTER},
36-
{labels: labelMap{"page_size": "1024"}, value: 40, metricType: dto.MetricType_COUNTER},
37-
{labels: labelMap{"page_size": "1024"}, value: 50, metricType: dto.MetricType_COUNTER},
38-
{labels: labelMap{"page_size": "1024"}, value: 60, metricType: dto.MetricType_COUNTER},
33+
{labels: labelMap{"page_size": "1024", "buffer": "0"}, value: 30, metricType: dto.MetricType_COUNTER},
34+
{labels: labelMap{"page_size": "1024", "buffer": "0"}, value: 40, metricType: dto.MetricType_COUNTER},
35+
{labels: labelMap{"page_size": "1024", "buffer": "0"}, value: 50, metricType: dto.MetricType_COUNTER},
36+
{labels: labelMap{"page_size": "1024", "buffer": "0"}, value: 0.06, metricType: dto.MetricType_COUNTER},
3937
}
4038
convey.Convey("Metrics comparison", t, func() {
4139
for _, expect := range expected {

0 commit comments

Comments
 (0)