@@ -17,37 +17,30 @@ const innodbCmpMemQuery = `
17
17
FROM information_schema.INNODB_CMPMEM
18
18
`
19
19
20
+ //Metric descriptors.
20
21
var (
21
22
// Map known innodb_cmp values to types. Unknown types will be mapped as
22
23
// untyped.
23
24
informationSchemaInnodbCmpMemTypes = map [string ]struct {
24
25
vtype prometheus.ValueType
25
26
desc * prometheus.Desc
26
27
}{
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 )},
35
28
"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 " ),
37
30
"Number of blocks of the size PAGE_SIZE that are currently in use." ,
38
- []string {"page_size" }, nil )},
31
+ []string {"page_size" , "buffer" }, nil )},
39
32
"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 " ),
41
34
"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 )},
43
36
"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 " ),
45
38
"Number of times a block of the size PAGE_SIZE has been relocated." ,
46
- []string {"page_size" }, nil )},
39
+ []string {"page_size" , "buffer" }, nil )},
47
40
"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 " ),
49
42
"Total time in microseconds spent in relocating blocks of the size PAGE_SIZE." ,
50
- []string {"page_size" }, nil )},
43
+ []string {"page_size" , "buffer" }, nil )},
51
44
}
52
45
)
53
46
@@ -80,40 +73,46 @@ func (ScrapeInnodbCmpMem) Scrape(db *sql.DB, ch chan<- prometheus.Metric) error
80
73
81
74
// The client column is assumed to be column[0], while all other data is assumed to be coerceable to float64.
82
75
// 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] ]
84
77
// To map metrics to names therefore we always range over columnNames[1:]
85
78
columnNames , err := informationSchemaInnodbCmpMemRows .Columns ()
79
+
86
80
if err != nil {
87
81
log .Debugln ("INNODB_CMPMEM stats are not available." )
88
82
return err
89
83
}
90
84
91
85
var (
92
86
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.
94
89
clientStatScanArgs = make ([]interface {}, len (columnNames ))
95
90
)
96
91
97
92
clientStatScanArgs [0 ] = & client
93
+ clientStatScanArgs [1 ] = & buffer
98
94
for i := range clientStatData {
99
- clientStatScanArgs [i + 1 ] = & clientStatData [i ]
95
+ clientStatScanArgs [i + 2 ] = & clientStatData [i ]
100
96
}
101
97
102
98
for informationSchemaInnodbCmpMemRows .Next () {
103
99
if err := informationSchemaInnodbCmpMemRows .Scan (clientStatScanArgs ... ); err != nil {
104
100
return err
105
101
}
106
-
107
102
// Loop over column names, and match to scan data. Unknown columns
108
103
// will be filled with an untyped metric number. We assume other then
109
104
// cient, that we'll only get numbers.
110
- for idx , columnName := range columnNames [1 :] {
105
+ for idx , columnName := range columnNames [2 :] {
111
106
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
+ }
113
112
} else {
114
113
// 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 )
117
116
}
118
117
}
119
118
}
0 commit comments