|
| 1 | +// Copyright 2018 The Prometheus Authors |
| 2 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +// you may not use this file except in compliance with the License. |
| 4 | +// You may obtain a copy of the License at |
| 5 | +// |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +// |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | + |
| 14 | +// Scrape `information_schema.ROCKSDB_PERF_CONTEXT`. |
| 15 | + |
| 16 | +package collector |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + "log/slog" |
| 21 | + |
| 22 | + "github.com/prometheus/client_golang/prometheus" |
| 23 | +) |
| 24 | + |
| 25 | +const rocksdbPerfContextQuery = ` |
| 26 | + SELECT |
| 27 | + TABLE_SCHEMA, |
| 28 | + TABLE_NAME, |
| 29 | + ifnull(PARTITION_NAME, ''), |
| 30 | + STAT_TYPE, |
| 31 | + VALUE |
| 32 | + FROM information_schema.ROCKSDB_PERF_CONTEXT |
| 33 | + ` |
| 34 | + |
| 35 | +// Metric descriptors. |
| 36 | +var informationSchemaRocksDBPerfContextMetrics = map[string]struct { |
| 37 | + vtype prometheus.ValueType |
| 38 | + desc *prometheus.Desc |
| 39 | +}{ |
| 40 | + "USER_KEY_COMPARISON_COUNT": { |
| 41 | + prometheus.CounterValue, |
| 42 | + prometheus.NewDesc( |
| 43 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_user_key_comparison_count"), |
| 44 | + "Total number of user key comparisons performed in binary search.", |
| 45 | + []string{"schema", "table", "part"}, nil, |
| 46 | + ), |
| 47 | + }, |
| 48 | + "BLOCK_CACHE_HIT_COUNT": { |
| 49 | + prometheus.CounterValue, |
| 50 | + prometheus.NewDesc( |
| 51 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_block_cache_hit_count"), |
| 52 | + "Total number of block read operations from cache.", |
| 53 | + []string{"schema", "table", "part"}, nil, |
| 54 | + ), |
| 55 | + }, |
| 56 | + "BLOCK_READ_COUNT": { |
| 57 | + prometheus.CounterValue, |
| 58 | + prometheus.NewDesc( |
| 59 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_block_read_count"), |
| 60 | + "Total number of block read operations from disk.", |
| 61 | + []string{"schema", "table", "part"}, nil, |
| 62 | + ), |
| 63 | + }, |
| 64 | + "BLOCK_READ_BYTE": { |
| 65 | + prometheus.CounterValue, |
| 66 | + prometheus.NewDesc( |
| 67 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_block_read_byte"), |
| 68 | + "Total number of bytes read from disk.", |
| 69 | + []string{"schema", "table", "part"}, nil, |
| 70 | + ), |
| 71 | + }, |
| 72 | + "GET_READ_BYTES": { |
| 73 | + prometheus.CounterValue, |
| 74 | + prometheus.NewDesc( |
| 75 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_get_read_bytes"), |
| 76 | + "Number of bytes read during Get operations.", |
| 77 | + []string{"schema", "table", "part"}, nil, |
| 78 | + ), |
| 79 | + }, |
| 80 | + "MULTIGET_READ_BYTES": { |
| 81 | + prometheus.CounterValue, |
| 82 | + prometheus.NewDesc( |
| 83 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_multiget_read_bytes"), |
| 84 | + "Number of bytes read during MultiGet operations.", |
| 85 | + []string{"schema", "table", "part"}, nil, |
| 86 | + ), |
| 87 | + }, |
| 88 | + "ITER_READ_BYTES": { |
| 89 | + prometheus.CounterValue, |
| 90 | + prometheus.NewDesc( |
| 91 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_iter_read_bytes"), |
| 92 | + "Number of bytes read during iterator operations.", |
| 93 | + []string{"schema", "table", "part"}, nil, |
| 94 | + ), |
| 95 | + }, |
| 96 | + "INTERNAL_KEY_SKIPPED_COUNT": { |
| 97 | + prometheus.CounterValue, |
| 98 | + prometheus.NewDesc( |
| 99 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_internal_key_skipped_count"), |
| 100 | + "Count of internal keys skipped during operations.", |
| 101 | + []string{"schema", "table", "part"}, nil, |
| 102 | + ), |
| 103 | + }, |
| 104 | + "INTERNAL_DELETE_SKIPPED_COUNT": { |
| 105 | + prometheus.CounterValue, |
| 106 | + prometheus.NewDesc( |
| 107 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_internal_delete_skipped_count"), |
| 108 | + "Count of internal delete operations that were skipped.", |
| 109 | + []string{"schema", "table", "part"}, nil, |
| 110 | + ), |
| 111 | + }, |
| 112 | + "INTERNAL_RECENT_SKIPPED_COUNT": { |
| 113 | + prometheus.CounterValue, |
| 114 | + prometheus.NewDesc( |
| 115 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_internal_recent_skipped_count"), |
| 116 | + "Count of recently skipped internal operations.", |
| 117 | + []string{"schema", "table", "part"}, nil, |
| 118 | + ), |
| 119 | + }, |
| 120 | + "INTERNAL_MERGE_COUNT": { |
| 121 | + prometheus.CounterValue, |
| 122 | + prometheus.NewDesc( |
| 123 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_internal_merge_count"), |
| 124 | + "Total number of internal merge operations.", |
| 125 | + []string{"schema", "table", "part"}, nil, |
| 126 | + ), |
| 127 | + }, |
| 128 | + "GET_FROM_MEMTABLE_COUNT": { |
| 129 | + prometheus.CounterValue, |
| 130 | + prometheus.NewDesc( |
| 131 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_get_from_memtable_count"), |
| 132 | + "Number of Get operations served from the memtable.", |
| 133 | + []string{"schema", "table", "part"}, nil, |
| 134 | + ), |
| 135 | + }, |
| 136 | + "SEEK_ON_MEMTABLE_COUNT": { |
| 137 | + prometheus.CounterValue, |
| 138 | + prometheus.NewDesc( |
| 139 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_seek_on_memtable_count"), |
| 140 | + "Count of seek operations in the memtable.", |
| 141 | + []string{"schema", "table", "part"}, nil, |
| 142 | + ), |
| 143 | + }, |
| 144 | + "NEXT_ON_MEMTABLE_COUNT": { |
| 145 | + prometheus.CounterValue, |
| 146 | + prometheus.NewDesc( |
| 147 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_next_on_memtable_count"), |
| 148 | + "Count of next operations in the memtable.", |
| 149 | + []string{"schema", "table", "part"}, nil, |
| 150 | + ), |
| 151 | + }, |
| 152 | + "PREV_ON_MEMTABLE_COUNT": { |
| 153 | + prometheus.CounterValue, |
| 154 | + prometheus.NewDesc( |
| 155 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_prev_on_memtable_count"), |
| 156 | + "Count of previous operations in the memtable.", |
| 157 | + []string{"schema", "table", "part"}, nil, |
| 158 | + ), |
| 159 | + }, |
| 160 | + "SEEK_CHILD_SEEK_COUNT": { |
| 161 | + prometheus.CounterValue, |
| 162 | + prometheus.NewDesc( |
| 163 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_seek_child_seek_count"), |
| 164 | + "Count of child seek operations in RocksDB.", |
| 165 | + []string{"schema", "table", "part"}, nil, |
| 166 | + ), |
| 167 | + }, |
| 168 | + "BLOOM_MEMTABLE_HIT_COUNT": { |
| 169 | + prometheus.CounterValue, |
| 170 | + prometheus.NewDesc( |
| 171 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_bloom_memtable_hit_count"), |
| 172 | + "Count of successful hits in the bloom filter for memtable searches.", |
| 173 | + []string{"schema", "table", "part"}, nil, |
| 174 | + ), |
| 175 | + }, |
| 176 | + "BLOOM_MEMTABLE_MISS_COUNT": { |
| 177 | + prometheus.CounterValue, |
| 178 | + prometheus.NewDesc( |
| 179 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_bloom_memtable_miss_count"), |
| 180 | + "Count of misses in the bloom filter for memtable searches.", |
| 181 | + []string{"schema", "table", "part"}, nil, |
| 182 | + ), |
| 183 | + }, |
| 184 | + "BLOOM_SST_HIT_COUNT": { |
| 185 | + prometheus.CounterValue, |
| 186 | + prometheus.NewDesc( |
| 187 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_bloom_sst_hit_count"), |
| 188 | + "Count of successful hits in the bloom filter for SSTable searches.", |
| 189 | + []string{"schema", "table", "part"}, nil, |
| 190 | + ), |
| 191 | + }, |
| 192 | + "BLOOM_SST_MISS_COUNT": { |
| 193 | + prometheus.CounterValue, |
| 194 | + prometheus.NewDesc( |
| 195 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_bloom_sst_miss_count"), |
| 196 | + "Count of misses in the bloom filter for SSTable searches.", |
| 197 | + []string{"schema", "table", "part"}, nil, |
| 198 | + ), |
| 199 | + }, |
| 200 | + "KEY_LOCK_WAIT_COUNT": { |
| 201 | + prometheus.CounterValue, |
| 202 | + prometheus.NewDesc( |
| 203 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_key_lock_wait_count"), |
| 204 | + "Count of key lock wait events in RocksDB.", |
| 205 | + []string{"schema", "table", "part"}, nil, |
| 206 | + ), |
| 207 | + }, |
| 208 | + "IO_BYTES_WRITTEN": { |
| 209 | + prometheus.CounterValue, |
| 210 | + prometheus.NewDesc( |
| 211 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_io_bytes_written"), |
| 212 | + "Total number of bytes written by I/O operations in RocksDB.", |
| 213 | + []string{"schema", "table", "part"}, nil, |
| 214 | + ), |
| 215 | + }, |
| 216 | + "IO_BYTES_READ": { |
| 217 | + prometheus.CounterValue, |
| 218 | + prometheus.NewDesc( |
| 219 | + prometheus.BuildFQName(namespace, informationSchema, "rocksdb_perf_context_io_bytes_read"), |
| 220 | + "Total number of bytes read by I/O operations in RocksDB.", |
| 221 | + []string{"schema", "table", "part"}, nil, |
| 222 | + ), |
| 223 | + }, |
| 224 | +} |
| 225 | + |
| 226 | +// ScrapeInnodbCmp collects from `information_schema.innodb_cmp`. |
| 227 | +type ScrapeRocksDBPerfContext struct{} |
| 228 | + |
| 229 | +// Name of the Scraper. Should be unique. |
| 230 | +func (ScrapeRocksDBPerfContext) Name() string { |
| 231 | + return informationSchema + ".rocksdb_perf_context" |
| 232 | +} |
| 233 | + |
| 234 | +// Help describes the role of the Scraper. |
| 235 | +func (ScrapeRocksDBPerfContext) Help() string { |
| 236 | + return "Collect metrics from information_schema.ROCKSDB_PERF_CONTEXT" |
| 237 | +} |
| 238 | + |
| 239 | +// Version of MySQL from which scraper is available. |
| 240 | +func (ScrapeRocksDBPerfContext) Version() float64 { |
| 241 | + return 5.6 |
| 242 | +} |
| 243 | + |
| 244 | +// Scrape collects data from database connection and sends it over channel as prometheus metric. |
| 245 | +func (ScrapeRocksDBPerfContext) Scrape(ctx context.Context, instance *instance, ch chan<- prometheus.Metric, logger *slog.Logger) error { |
| 246 | + db := instance.getDB() |
| 247 | + informationSchemaInnodbCmpMemRows, err := db.QueryContext(ctx, rocksdbPerfContextQuery) |
| 248 | + if err != nil { |
| 249 | + return err |
| 250 | + } |
| 251 | + defer informationSchemaInnodbCmpMemRows.Close() |
| 252 | + |
| 253 | + var ( |
| 254 | + schema, table, part, stat string |
| 255 | + value float64 |
| 256 | + ) |
| 257 | + |
| 258 | + for informationSchemaInnodbCmpMemRows.Next() { |
| 259 | + if err := informationSchemaInnodbCmpMemRows.Scan( |
| 260 | + &schema, &table, &part, &stat, &value, |
| 261 | + ); err != nil { |
| 262 | + return err |
| 263 | + } |
| 264 | + if v, ok := informationSchemaRocksDBPerfContextMetrics[stat]; ok { |
| 265 | + ch <- prometheus.MustNewConstMetric(v.desc, v.vtype, value, schema, table, part) |
| 266 | + } |
| 267 | + } |
| 268 | + return nil |
| 269 | +} |
| 270 | + |
| 271 | +// check interface |
| 272 | +var _ Scraper = ScrapeRocksDBPerfContext{} |
0 commit comments