| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package proxysql |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "strings" |
| 8 | |
| 9 | "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 10 | ) |
| 11 | |
| 12 | // TODO: check https://github.com/ProxySQL/proxysql-grafana-prometheus/blob/main/grafana/provisioning/dashboards/ProxySQL-Host-Statistics.json |
| 13 | |
| 14 | const ( |
| 15 | prioClientConnectionsCount = collectorapi.Priority + iota |
| 16 | prioClientConnectionsRate |
| 17 | prioServerConnectionsCount |
| 18 | prioServerConnectionsRate |
| 19 | prioBackendsTraffic |
| 20 | prioFrontendsTraffic |
| 21 | prioActiveTransactionsCount |
| 22 | prioQuestionsRate |
| 23 | prioSlowQueriesRate |
| 24 | prioQueriesRate |
| 25 | prioBackendStatementsCount |
| 26 | prioBackendStatementsRate |
| 27 | prioFrontendStatementsCount |
| 28 | prioFrontendStatementsRate |
| 29 | prioCachedStatementsCount |
| 30 | prioQueryCacheEntriesCount |
| 31 | prioQueryCacheIO |
| 32 | prioQueryCacheRequestsRate |
| 33 | prioQueryCacheMemoryUsed |
| 34 | prioMySQLMonitorWorkersCount |
| 35 | prioMySQLMonitorWorkersRate |
| 36 | prioMySQLMonitorConnectChecksRate |
| 37 | prioMySQLMonitorPingChecksRate |
| 38 | prioMySQLMonitorReadOnlyChecksRate |
| 39 | prioMySQLMonitorReplicationLagChecksRate |
| 40 | prioJemallocMemoryUsed |
| 41 | prioMemoryUsed |
| 42 | prioMySQLCommandExecutionsRate |
| 43 | prioMySQLCommandExecutionTime |
| 44 | prioMySQLCommandExecutionDurationHistogram |
| 45 | prioMySQLUserConnectionsUtilization |
| 46 | prioMySQLUserConnectionsCount |
| 47 | prioHostgroupStatus |
| 48 | prioBackendStatus |
| 49 | prioBackendConnectionsUsage |
| 50 | prioBackendConnectionsRate |
| 51 | prioBackendQueriesRateRate |
| 52 | prioBackendTraffic |
| 53 | prioBackendLatency |
| 54 | prioUptime |
| 55 | ) |
| 56 | |
| 57 | var ( |
| 58 | baseCharts = collectorapi.Charts{ |
| 59 | clientConnectionsCountChart.Copy(), |
| 60 | clientConnectionsRateChart.Copy(), |
| 61 | serverConnectionsCountChart.Copy(), |
| 62 | serverConnectionsRateChart.Copy(), |
| 63 | backendsTrafficChart.Copy(), |
| 64 | frontendsTrafficChart.Copy(), |
| 65 | activeTransactionsCountChart.Copy(), |
| 66 | questionsRateChart.Copy(), |
| 67 | slowQueriesRateChart.Copy(), |
| 68 | queriesRateChart.Copy(), |
| 69 | backendStatementsCountChart.Copy(), |
| 70 | backendStatementsRateChart.Copy(), |
| 71 | clientStatementsCountChart.Copy(), |
| 72 | clientStatementsRateChart.Copy(), |
| 73 | cachedStatementsCountChart.Copy(), |
| 74 | queryCacheEntriesCountChart.Copy(), |
| 75 | queryCacheIOChart.Copy(), |
| 76 | queryCacheRequestsRateChart.Copy(), |
| 77 | queryCacheMemoryUsedChart.Copy(), |
| 78 | mySQLMonitorWorkersCountChart.Copy(), |
| 79 | mySQLMonitorWorkersRateChart.Copy(), |
| 80 | mySQLMonitorConnectChecksRateChart.Copy(), |
| 81 | mySQLMonitorPingChecksRateChart.Copy(), |
| 82 | mySQLMonitorReadOnlyChecksRateChart.Copy(), |
| 83 | mySQLMonitorReplicationLagChecksRateChart.Copy(), |
| 84 | jemallocMemoryUsedChart.Copy(), |
| 85 | memoryUsedCountChart.Copy(), |
| 86 | uptimeChart.Copy(), |
| 87 | } |
| 88 | |
| 89 | clientConnectionsCountChart = collectorapi.Chart{ |
| 90 | ID: "client_connections_count", |
| 91 | Title: "Client connections", |
| 92 | Units: "connections", |
| 93 | Fam: "connections", |
| 94 | Ctx: "proxysql.client_connections_count", |
| 95 | Priority: prioClientConnectionsCount, |
| 96 | Dims: collectorapi.Dims{ |
| 97 | {ID: "Client_Connections_connected", Name: "connected"}, |
| 98 | {ID: "Client_Connections_non_idle", Name: "non_idle"}, |
| 99 | {ID: "Client_Connections_hostgroup_locked", Name: "hostgroup_locked"}, |
| 100 | }, |
| 101 | } |
| 102 | clientConnectionsRateChart = collectorapi.Chart{ |
| 103 | ID: "client_connections_rate", |
| 104 | Title: "Client connections rate", |
| 105 | Units: "connections/s", |
| 106 | Fam: "connections", |
| 107 | Ctx: "proxysql.client_connections_rate", |
| 108 | Priority: prioClientConnectionsRate, |
| 109 | Dims: collectorapi.Dims{ |
| 110 | {ID: "Client_Connections_created", Name: "created", Algo: collectorapi.Incremental}, |
| 111 | {ID: "Client_Connections_aborted", Name: "aborted", Algo: collectorapi.Incremental}, |
| 112 | }, |
| 113 | } |
| 114 | |
| 115 | serverConnectionsCountChart = collectorapi.Chart{ |
| 116 | ID: "server_connections_count", |
| 117 | Title: "Server connections", |
| 118 | Units: "connections", |
| 119 | Fam: "connections", |
| 120 | Ctx: "proxysql.server_connections_count", |
| 121 | Priority: prioServerConnectionsCount, |
| 122 | Dims: collectorapi.Dims{ |
| 123 | {ID: "Server_Connections_connected", Name: "connected"}, |
| 124 | }, |
| 125 | } |
| 126 | serverConnectionsRateChart = collectorapi.Chart{ |
| 127 | ID: "server_connections_rate", |
| 128 | Title: "Server connections rate", |
| 129 | Units: "connections/s", |
| 130 | Fam: "connections", |
| 131 | Ctx: "proxysql.server_connections_rate", |
| 132 | Priority: prioServerConnectionsRate, |
| 133 | Dims: collectorapi.Dims{ |
| 134 | {ID: "Server_Connections_created", Name: "created", Algo: collectorapi.Incremental}, |
| 135 | {ID: "Server_Connections_aborted", Name: "aborted", Algo: collectorapi.Incremental}, |
| 136 | {ID: "Server_Connections_delayed", Name: "delayed", Algo: collectorapi.Incremental}, |
| 137 | }, |
| 138 | } |
| 139 | |
| 140 | backendsTrafficChart = collectorapi.Chart{ |
| 141 | ID: "backends_traffic", |
| 142 | Title: "Backends traffic", |
| 143 | Units: "B/s", |
| 144 | Fam: "traffic", |
| 145 | Ctx: "proxysql.backends_traffic", |
| 146 | Priority: prioBackendsTraffic, |
| 147 | Dims: collectorapi.Dims{ |
| 148 | {ID: "Queries_backends_bytes_recv", Name: "recv", Algo: collectorapi.Incremental}, |
| 149 | {ID: "Queries_backends_bytes_sent", Name: "sent", Algo: collectorapi.Incremental}, |
| 150 | }, |
| 151 | } |
| 152 | frontendsTrafficChart = collectorapi.Chart{ |
| 153 | ID: "clients_traffic", |
| 154 | Title: "Clients traffic", |
| 155 | Units: "B/s", |
| 156 | Fam: "traffic", |
| 157 | Ctx: "proxysql.clients_traffic", |
| 158 | Priority: prioFrontendsTraffic, |
| 159 | Dims: collectorapi.Dims{ |
| 160 | {ID: "Queries_frontends_bytes_recv", Name: "recv", Algo: collectorapi.Incremental}, |
| 161 | {ID: "Queries_frontends_bytes_sent", Name: "sent", Algo: collectorapi.Incremental}, |
| 162 | }, |
| 163 | } |
| 164 | |
| 165 | activeTransactionsCountChart = collectorapi.Chart{ |
| 166 | ID: "active_transactions_count", |
| 167 | Title: "Client connections that are currently processing a transaction", |
| 168 | Units: "transactions", |
| 169 | Fam: "transactions", |
| 170 | Ctx: "proxysql.active_transactions_count", |
| 171 | Priority: prioActiveTransactionsCount, |
| 172 | Dims: collectorapi.Dims{ |
| 173 | {ID: "Active_Transactions", Name: "active"}, |
| 174 | }, |
| 175 | } |
| 176 | questionsRateChart = collectorapi.Chart{ |
| 177 | ID: "questions_rate", |
| 178 | Title: "Client requests / statements executed", |
| 179 | Units: "questions/s", |
| 180 | Fam: "queries", |
| 181 | Ctx: "proxysql.questions_rate", |
| 182 | Priority: prioQuestionsRate, |
| 183 | Dims: collectorapi.Dims{ |
| 184 | {ID: "Questions", Name: "questions", Algo: collectorapi.Incremental}, |
| 185 | }, |
| 186 | } |
| 187 | slowQueriesRateChart = collectorapi.Chart{ |
| 188 | ID: "slow_queries_rate", |
| 189 | Title: "Slow queries", |
| 190 | Units: "queries/s", |
| 191 | Fam: "queries", |
| 192 | Ctx: "proxysql.slow_queries_rate", |
| 193 | Priority: prioSlowQueriesRate, |
| 194 | Dims: collectorapi.Dims{ |
| 195 | {ID: "Slow_queries", Name: "slow", Algo: collectorapi.Incremental}, |
| 196 | }, |
| 197 | } |
| 198 | queriesRateChart = collectorapi.Chart{ |
| 199 | ID: "queries_rate", |
| 200 | Title: "Queries rate", |
| 201 | Units: "queries/s", |
| 202 | Fam: "queries", |
| 203 | Ctx: "proxysql.queries_rate", |
| 204 | Priority: prioQueriesRate, |
| 205 | Type: collectorapi.Stacked, |
| 206 | Dims: collectorapi.Dims{ |
| 207 | {ID: "Com_autocommit", Name: "autocommit", Algo: collectorapi.Incremental}, |
| 208 | {ID: "Com_autocommit_filtered", Name: "autocommit_filtered", Algo: collectorapi.Incremental}, |
| 209 | {ID: "Com_commit", Name: "commit", Algo: collectorapi.Incremental}, |
| 210 | {ID: "Com_commit_filtered", Name: "commit_filtered", Algo: collectorapi.Incremental}, |
| 211 | {ID: "Com_rollback", Name: "rollback", Algo: collectorapi.Incremental}, |
| 212 | {ID: "Com_rollback_filtered", Name: "rollback_filtered", Algo: collectorapi.Incremental}, |
| 213 | {ID: "Com_backend_change_user", Name: "backend_change_user", Algo: collectorapi.Incremental}, |
| 214 | {ID: "Com_backend_init_db", Name: "backend_init_db", Algo: collectorapi.Incremental}, |
| 215 | {ID: "Com_backend_set_names", Name: "backend_set_names", Algo: collectorapi.Incremental}, |
| 216 | {ID: "Com_frontend_init_db", Name: "frontend_init_db", Algo: collectorapi.Incremental}, |
| 217 | {ID: "Com_frontend_set_names", Name: "frontend_set_names", Algo: collectorapi.Incremental}, |
| 218 | {ID: "Com_frontend_use_db", Name: "frontend_use_db", Algo: collectorapi.Incremental}, |
| 219 | }, |
| 220 | } |
| 221 | |
| 222 | backendStatementsCountChart = collectorapi.Chart{ |
| 223 | ID: "backend_statements_count", |
| 224 | Title: "Statements available across all backend connections", |
| 225 | Units: "statements", |
| 226 | Fam: "statements", |
| 227 | Ctx: "proxysql.backend_statements_count", |
| 228 | Priority: prioBackendStatementsCount, |
| 229 | Dims: collectorapi.Dims{ |
| 230 | {ID: "Stmt_Server_Active_Total", Name: "total"}, |
| 231 | {ID: "Stmt_Server_Active_Unique", Name: "unique"}, |
| 232 | }, |
| 233 | } |
| 234 | backendStatementsRateChart = collectorapi.Chart{ |
| 235 | ID: "backend_statements_rate", |
| 236 | Title: "Statements executed against the backends", |
| 237 | Units: "statements/s", |
| 238 | Fam: "statements", |
| 239 | Ctx: "proxysql.backend_statements_rate", |
| 240 | Priority: prioBackendStatementsRate, |
| 241 | Type: collectorapi.Stacked, |
| 242 | Dims: collectorapi.Dims{ |
| 243 | {ID: "Com_backend_stmt_prepare", Name: "prepare", Algo: collectorapi.Incremental}, |
| 244 | {ID: "Com_backend_stmt_execute", Name: "execute", Algo: collectorapi.Incremental}, |
| 245 | {ID: "Com_backend_stmt_close", Name: "close", Algo: collectorapi.Incremental}, |
| 246 | }, |
| 247 | } |
| 248 | clientStatementsCountChart = collectorapi.Chart{ |
| 249 | ID: "client_statements_count", |
| 250 | Title: "Statements that are in use by clients", |
| 251 | Units: "statements", |
| 252 | Fam: "statements", |
| 253 | Ctx: "proxysql.client_statements_count", |
| 254 | Priority: prioFrontendStatementsCount, |
| 255 | Dims: collectorapi.Dims{ |
| 256 | {ID: "Stmt_Client_Active_Total", Name: "total"}, |
| 257 | {ID: "Stmt_Client_Active_Unique", Name: "unique"}, |
| 258 | }, |
| 259 | } |
| 260 | clientStatementsRateChart = collectorapi.Chart{ |
| 261 | ID: "client_statements_rate", |
| 262 | Title: "Statements executed by clients", |
| 263 | Units: "statements/s", |
| 264 | Fam: "statements", |
| 265 | Ctx: "proxysql.client_statements_rate", |
| 266 | Priority: prioFrontendStatementsRate, |
| 267 | Type: collectorapi.Stacked, |
| 268 | Dims: collectorapi.Dims{ |
| 269 | {ID: "Com_frontend_stmt_prepare", Name: "prepare", Algo: collectorapi.Incremental}, |
| 270 | {ID: "Com_frontend_stmt_execute", Name: "execute", Algo: collectorapi.Incremental}, |
| 271 | {ID: "Com_frontend_stmt_close", Name: "close", Algo: collectorapi.Incremental}, |
| 272 | }, |
| 273 | } |
| 274 | cachedStatementsCountChart = collectorapi.Chart{ |
| 275 | ID: "cached_statements_count", |
| 276 | Title: "Global prepared statements", |
| 277 | Units: "statements", |
| 278 | Fam: "statements", |
| 279 | Ctx: "proxysql.cached_statements_count", |
| 280 | Priority: prioCachedStatementsCount, |
| 281 | Dims: collectorapi.Dims{ |
| 282 | {ID: "Stmt_Cached", Name: "cached"}, |
| 283 | }, |
| 284 | } |
| 285 | |
| 286 | queryCacheEntriesCountChart = collectorapi.Chart{ |
| 287 | ID: "query_cache_entries_count", |
| 288 | Title: "Query Cache entries", |
| 289 | Units: "entries", |
| 290 | Fam: "query cache", |
| 291 | Ctx: "proxysql.query_cache_entries_count", |
| 292 | Priority: prioQueryCacheEntriesCount, |
| 293 | Dims: collectorapi.Dims{ |
| 294 | {ID: "Query_Cache_Entries", Name: "entries"}, |
| 295 | }, |
| 296 | } |
| 297 | queryCacheMemoryUsedChart = collectorapi.Chart{ |
| 298 | ID: "query_cache_memory_used", |
| 299 | Title: "Query Cache memory used", |
| 300 | Units: "B", |
| 301 | Fam: "query cache", |
| 302 | Ctx: "proxysql.query_cache_memory_used", |
| 303 | Priority: prioQueryCacheMemoryUsed, |
| 304 | Dims: collectorapi.Dims{ |
| 305 | {ID: "Query_Cache_Memory_bytes", Name: "used"}, |
| 306 | }, |
| 307 | } |
| 308 | queryCacheIOChart = collectorapi.Chart{ |
| 309 | ID: "query_cache_io", |
| 310 | Title: "Query Cache I/O", |
| 311 | Units: "B/s", |
| 312 | Fam: "query cache", |
| 313 | Ctx: "proxysql.query_cache_io", |
| 314 | Priority: prioQueryCacheIO, |
| 315 | Dims: collectorapi.Dims{ |
| 316 | {ID: "Query_Cache_bytes_IN", Name: "in", Algo: collectorapi.Incremental}, |
| 317 | {ID: "Query_Cache_bytes_OUT", Name: "out", Algo: collectorapi.Incremental}, |
| 318 | }, |
| 319 | } |
| 320 | queryCacheRequestsRateChart = collectorapi.Chart{ |
| 321 | ID: "query_cache_requests_rate", |
| 322 | Title: "Query Cache requests", |
| 323 | Units: "requests/s", |
| 324 | Fam: "query cache", |
| 325 | Ctx: "proxysql.query_cache_requests_rate", |
| 326 | Priority: prioQueryCacheRequestsRate, |
| 327 | Dims: collectorapi.Dims{ |
| 328 | {ID: "Query_Cache_count_GET", Name: "read", Algo: collectorapi.Incremental}, |
| 329 | {ID: "Query_Cache_count_SET", Name: "write", Algo: collectorapi.Incremental}, |
| 330 | {ID: "Query_Cache_count_GET_OK", Name: "read_success", Algo: collectorapi.Incremental}, |
| 331 | }, |
| 332 | } |
| 333 | |
| 334 | mySQLMonitorWorkersCountChart = collectorapi.Chart{ |
| 335 | ID: "mysql_monitor_workers_count", |
| 336 | Title: "MySQL monitor workers", |
| 337 | Units: "threads", |
| 338 | Fam: "monitor", |
| 339 | Ctx: "proxysql.mysql_monitor_workers_count", |
| 340 | Priority: prioMySQLMonitorWorkersCount, |
| 341 | Dims: collectorapi.Dims{ |
| 342 | {ID: "MySQL_Monitor_Workers", Name: "workers"}, |
| 343 | {ID: "MySQL_Monitor_Workers_Aux", Name: "auxiliary"}, |
| 344 | }, |
| 345 | } |
| 346 | mySQLMonitorWorkersRateChart = collectorapi.Chart{ |
| 347 | ID: "mysql_monitor_workers_rate", |
| 348 | Title: "MySQL monitor workers rate", |
| 349 | Units: "workers/s", |
| 350 | Fam: "monitor", |
| 351 | Ctx: "proxysql.mysql_monitor_workers_rate", |
| 352 | Priority: prioMySQLMonitorWorkersRate, |
| 353 | Dims: collectorapi.Dims{ |
| 354 | {ID: "MySQL_Monitor_Workers_Started", Name: "started", Algo: collectorapi.Incremental}, |
| 355 | }, |
| 356 | } |
| 357 | mySQLMonitorConnectChecksRateChart = collectorapi.Chart{ |
| 358 | ID: "mysql_monitor_connect_checks_rate", |
| 359 | Title: "MySQL monitor connect checks", |
| 360 | Units: "checks/s", |
| 361 | Fam: "monitor", |
| 362 | Ctx: "proxysql.mysql_monitor_connect_checks_rate", |
| 363 | Priority: prioMySQLMonitorConnectChecksRate, |
| 364 | Dims: collectorapi.Dims{ |
| 365 | {ID: "MySQL_Monitor_connect_check_OK", Name: "succeed", Algo: collectorapi.Incremental}, |
| 366 | {ID: "MySQL_Monitor_connect_check_ERR", Name: "failed", Algo: collectorapi.Incremental}, |
| 367 | }, |
| 368 | } |
| 369 | mySQLMonitorPingChecksRateChart = collectorapi.Chart{ |
| 370 | ID: "mysql_monitor_ping_checks_rate", |
| 371 | Title: "MySQL monitor ping checks", |
| 372 | Units: "checks/s", |
| 373 | Fam: "monitor", |
| 374 | Ctx: "proxysql.mysql_monitor_ping_checks_rate", |
| 375 | Priority: prioMySQLMonitorPingChecksRate, |
| 376 | Dims: collectorapi.Dims{ |
| 377 | {ID: "MySQL_Monitor_ping_check_OK", Name: "succeed", Algo: collectorapi.Incremental}, |
| 378 | {ID: "MySQL_Monitor_ping_check_ERR", Name: "failed", Algo: collectorapi.Incremental}, |
| 379 | }, |
| 380 | } |
| 381 | mySQLMonitorReadOnlyChecksRateChart = collectorapi.Chart{ |
| 382 | ID: "mysql_monitor_read_only_checks_rate", |
| 383 | Title: "MySQL monitor read only checks", |
| 384 | Units: "checks/s", |
| 385 | Fam: "monitor", |
| 386 | Ctx: "proxysql.mysql_monitor_read_only_checks_rate", |
| 387 | Priority: prioMySQLMonitorReadOnlyChecksRate, |
| 388 | Dims: collectorapi.Dims{ |
| 389 | {ID: "MySQL_Monitor_read_only_check_OK", Name: "succeed", Algo: collectorapi.Incremental}, |
| 390 | {ID: "MySQL_Monitor_read_only_check_ERR", Name: "failed", Algo: collectorapi.Incremental}, |
| 391 | }, |
| 392 | } |
| 393 | mySQLMonitorReplicationLagChecksRateChart = collectorapi.Chart{ |
| 394 | ID: "mysql_monitor_replication_lag_checks_rate", |
| 395 | Title: "MySQL monitor replication lag checks", |
| 396 | Units: "checks/s", |
| 397 | Fam: "monitor", |
| 398 | Ctx: "proxysql.mysql_monitor_replication_lag_checks_rate", |
| 399 | Priority: prioMySQLMonitorReplicationLagChecksRate, |
| 400 | Dims: collectorapi.Dims{ |
| 401 | {ID: "MySQL_Monitor_replication_lag_check_OK", Name: "succeed", Algo: collectorapi.Incremental}, |
| 402 | {ID: "MySQL_Monitor_replication_lag_check_ERR", Name: "failed", Algo: collectorapi.Incremental}, |
| 403 | }, |
| 404 | } |
| 405 | |
| 406 | jemallocMemoryUsedChart = collectorapi.Chart{ |
| 407 | ID: "jemalloc_memory_used", |
| 408 | Title: "Jemalloc used memory", |
| 409 | Units: "bytes", |
| 410 | Fam: "memory", |
| 411 | Ctx: "proxysql.jemalloc_memory_used", |
| 412 | Type: collectorapi.Stacked, |
| 413 | Priority: prioJemallocMemoryUsed, |
| 414 | Dims: collectorapi.Dims{ |
| 415 | {ID: "jemalloc_active", Name: "active"}, |
| 416 | {ID: "jemalloc_allocated", Name: "allocated"}, |
| 417 | {ID: "jemalloc_mapped", Name: "mapped"}, |
| 418 | {ID: "jemalloc_metadata", Name: "metadata"}, |
| 419 | {ID: "jemalloc_resident", Name: "resident"}, |
| 420 | {ID: "jemalloc_retained", Name: "retained"}, |
| 421 | }, |
| 422 | } |
| 423 | memoryUsedCountChart = collectorapi.Chart{ |
| 424 | ID: "memory_used", |
| 425 | Title: "Memory used", |
| 426 | Units: "bytes", |
| 427 | Fam: "memory", |
| 428 | Ctx: "proxysql.memory_used", |
| 429 | Priority: prioMemoryUsed, |
| 430 | Type: collectorapi.Stacked, |
| 431 | Dims: collectorapi.Dims{ |
| 432 | {ID: "Auth_memory", Name: "auth"}, |
| 433 | {ID: "SQLite3_memory_bytes", Name: "sqlite3"}, |
| 434 | {ID: "query_digest_memory", Name: "query_digest"}, |
| 435 | {ID: "mysql_query_rules_memory", Name: "query_rules"}, |
| 436 | {ID: "mysql_firewall_users_table", Name: "firewall_users_table"}, |
| 437 | {ID: "mysql_firewall_users_config", Name: "firewall_users_config"}, |
| 438 | {ID: "mysql_firewall_rules_table", Name: "firewall_rules_table"}, |
| 439 | {ID: "mysql_firewall_rules_config", Name: "firewall_rules_config"}, |
| 440 | {ID: "stack_memory_mysql_threads", Name: "mysql_threads"}, |
| 441 | {ID: "stack_memory_admin_threads", Name: "admin_threads"}, |
| 442 | {ID: "stack_memory_cluster_threads", Name: "cluster_threads"}, |
| 443 | }, |
| 444 | } |
| 445 | uptimeChart = collectorapi.Chart{ |
| 446 | ID: "proxysql_uptime", |
| 447 | Title: "Uptime", |
| 448 | Units: "seconds", |
| 449 | Fam: "uptime", |
| 450 | Ctx: "proxysql.uptime", |
| 451 | Priority: prioUptime, |
| 452 | Dims: collectorapi.Dims{ |
| 453 | {ID: "ProxySQL_Uptime", Name: "uptime"}, |
| 454 | }, |
| 455 | } |
| 456 | ) |
| 457 | |
| 458 | var ( |
| 459 | mySQLCommandChartsTmpl = collectorapi.Charts{ |
| 460 | mySQLCommandExecutionRateChartTmpl.Copy(), |
| 461 | mySQLCommandExecutionTimeChartTmpl.Copy(), |
| 462 | mySQLCommandExecutionDurationHistogramChartTmpl.Copy(), |
| 463 | } |
| 464 | |
| 465 | mySQLCommandExecutionRateChartTmpl = collectorapi.Chart{ |
| 466 | ID: "mysql_command_%s_execution_rate", |
| 467 | Title: "MySQL command execution", |
| 468 | Units: "commands/s", |
| 469 | Fam: "command exec", |
| 470 | Ctx: "proxysql.mysql_command_execution_rate", |
| 471 | Priority: prioMySQLCommandExecutionsRate, |
| 472 | Dims: collectorapi.Dims{ |
| 473 | {ID: "mysql_command_%s_Total_cnt", Name: "commands", Algo: collectorapi.Incremental}, |
| 474 | }, |
| 475 | } |
| 476 | mySQLCommandExecutionTimeChartTmpl = collectorapi.Chart{ |
| 477 | ID: "mysql_command_%s_execution_time", |
| 478 | Title: "MySQL command execution time", |
| 479 | Units: "microseconds", |
| 480 | Fam: "command exec time", |
| 481 | Ctx: "proxysql.mysql_command_execution_time", |
| 482 | Priority: prioMySQLCommandExecutionTime, |
| 483 | Dims: collectorapi.Dims{ |
| 484 | {ID: "mysql_command_%s_Total_Time_us", Name: "time", Algo: collectorapi.Incremental}, |
| 485 | }, |
| 486 | } |
| 487 | mySQLCommandExecutionDurationHistogramChartTmpl = collectorapi.Chart{ |
| 488 | ID: "mysql_command_%s_execution_duration", |
| 489 | Title: "MySQL command execution duration histogram", |
| 490 | Units: "commands/s", |
| 491 | Fam: "command exec duration", |
| 492 | Ctx: "proxysql.mysql_command_execution_duration", |
| 493 | Type: collectorapi.Stacked, |
| 494 | Priority: prioMySQLCommandExecutionDurationHistogram, |
| 495 | Dims: collectorapi.Dims{ |
| 496 | {ID: "mysql_command_%s_cnt_100us", Name: "100us", Algo: collectorapi.Incremental}, |
| 497 | {ID: "mysql_command_%s_cnt_500us", Name: "500us", Algo: collectorapi.Incremental}, |
| 498 | {ID: "mysql_command_%s_cnt_1ms", Name: "1ms", Algo: collectorapi.Incremental}, |
| 499 | {ID: "mysql_command_%s_cnt_5ms", Name: "5ms", Algo: collectorapi.Incremental}, |
| 500 | {ID: "mysql_command_%s_cnt_10ms", Name: "10ms", Algo: collectorapi.Incremental}, |
| 501 | {ID: "mysql_command_%s_cnt_50ms", Name: "50ms", Algo: collectorapi.Incremental}, |
| 502 | {ID: "mysql_command_%s_cnt_100ms", Name: "100ms", Algo: collectorapi.Incremental}, |
| 503 | {ID: "mysql_command_%s_cnt_500ms", Name: "500ms", Algo: collectorapi.Incremental}, |
| 504 | {ID: "mysql_command_%s_cnt_1s", Name: "1s", Algo: collectorapi.Incremental}, |
| 505 | {ID: "mysql_command_%s_cnt_5s", Name: "5s", Algo: collectorapi.Incremental}, |
| 506 | {ID: "mysql_command_%s_cnt_10s", Name: "10s", Algo: collectorapi.Incremental}, |
| 507 | {ID: "mysql_command_%s_cnt_INFs", Name: "+Inf", Algo: collectorapi.Incremental}, |
| 508 | }, |
| 509 | } |
| 510 | ) |
| 511 | |
| 512 | func newMySQLCommandCountersCharts(command string) *collectorapi.Charts { |
| 513 | charts := mySQLCommandChartsTmpl.Copy() |
| 514 | |
| 515 | for _, chart := range *charts { |
| 516 | chart.ID = fmt.Sprintf(chart.ID, strings.ToLower(command)) |
| 517 | chart.Labels = []collectorapi.Label{{Key: "command", Value: command}} |
| 518 | for _, dim := range chart.Dims { |
| 519 | dim.ID = fmt.Sprintf(dim.ID, command) |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | return charts |
| 524 | } |
| 525 | |
| 526 | func (c *Collector) addMySQLCommandCountersCharts(command string) { |
| 527 | charts := newMySQLCommandCountersCharts(command) |
| 528 | |
| 529 | if err := c.Charts().Add(*charts...); err != nil { |
| 530 | c.Warning(err) |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | func (c *Collector) removeMySQLCommandCountersCharts(command string) { |
| 535 | prefix := "mysql_command_" + strings.ToLower(command) |
| 536 | |
| 537 | for _, chart := range *c.Charts() { |
| 538 | if strings.HasPrefix(chart.ID, prefix) { |
| 539 | chart.MarkRemove() |
| 540 | chart.MarkNotCreated() |
| 541 | } |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | var ( |
| 546 | mySQLUserChartsTmpl = collectorapi.Charts{ |
| 547 | mySQLUserConnectionsUtilizationChartTmpl.Copy(), |
| 548 | mySQLUserConnectionsCountChartTmpl.Copy(), |
| 549 | } |
| 550 | |
| 551 | mySQLUserConnectionsUtilizationChartTmpl = collectorapi.Chart{ |
| 552 | ID: "mysql_user_%s_connections_utilization", |
| 553 | Title: "MySQL user connections utilization", |
| 554 | Units: "percentage", |
| 555 | Fam: "user conns", |
| 556 | Ctx: "proxysql.mysql_user_connections_utilization", |
| 557 | Priority: prioMySQLUserConnectionsUtilization, |
| 558 | Dims: collectorapi.Dims{ |
| 559 | {ID: "mysql_user_%s_frontend_connections_utilization", Name: "used"}, |
| 560 | }, |
| 561 | } |
| 562 | mySQLUserConnectionsCountChartTmpl = collectorapi.Chart{ |
| 563 | ID: "mysql_user_%s_connections_count", |
| 564 | Title: "MySQL user connections used", |
| 565 | Units: "connections", |
| 566 | Fam: "user conns", |
| 567 | Ctx: "proxysql.mysql_user_connections_count", |
| 568 | Priority: prioMySQLUserConnectionsCount, |
| 569 | Dims: collectorapi.Dims{ |
| 570 | {ID: "mysql_user_%s_frontend_connections", Name: "used"}, |
| 571 | }, |
| 572 | } |
| 573 | ) |
| 574 | |
| 575 | func newMySQLUserCharts(username string) *collectorapi.Charts { |
| 576 | charts := mySQLUserChartsTmpl.Copy() |
| 577 | |
| 578 | for _, chart := range *charts { |
| 579 | chart.ID = fmt.Sprintf(chart.ID, username) |
| 580 | chart.Labels = []collectorapi.Label{{Key: "user", Value: username}} |
| 581 | for _, dim := range chart.Dims { |
| 582 | dim.ID = fmt.Sprintf(dim.ID, username) |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | return charts |
| 587 | } |
| 588 | |
| 589 | func (c *Collector) addMySQLUsersCharts(username string) { |
| 590 | charts := newMySQLUserCharts(username) |
| 591 | |
| 592 | if err := c.Charts().Add(*charts...); err != nil { |
| 593 | c.Warning(err) |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | func (c *Collector) removeMySQLUserCharts(user string) { |
| 598 | prefix := "mysql_user_" + user |
| 599 | |
| 600 | for _, chart := range *c.Charts() { |
| 601 | if strings.HasPrefix(chart.ID, prefix) { |
| 602 | chart.MarkRemove() |
| 603 | chart.MarkNotCreated() |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | var ( |
| 609 | hostgroupChartsTmpl = collectorapi.Charts{ |
| 610 | hostgroupBackendsStatusChartTmpl.Copy(), |
| 611 | } |
| 612 | |
| 613 | hostgroupBackendsStatusChartTmpl = collectorapi.Chart{ |
| 614 | ID: "hostgroup_%s_backends_status", |
| 615 | Title: "Hostgroup backends count in each status", |
| 616 | Units: "backends", |
| 617 | Fam: "hostgroup backends", |
| 618 | Ctx: "proxysql.hostgroup_backends_status", |
| 619 | Priority: prioHostgroupStatus, |
| 620 | Dims: collectorapi.Dims{ |
| 621 | {ID: "hostgroup_%s_backends_ONLINE", Name: "online"}, |
| 622 | {ID: "hostgroup_%s_backends_SHUNNED", Name: "shunned"}, |
| 623 | {ID: "hostgroup_%s_backends_OFFLINE_SOFT", Name: "offline_soft"}, |
| 624 | {ID: "hostgroup_%s_backends_OFFLINE_HARD", Name: "offline_hard"}, |
| 625 | }, |
| 626 | } |
| 627 | ) |
| 628 | |
| 629 | func newHostgroupCharts(hg string) *collectorapi.Charts { |
| 630 | charts := hostgroupChartsTmpl.Copy() |
| 631 | |
| 632 | for _, chart := range *charts { |
| 633 | chart.ID = fmt.Sprintf(chart.ID, hg) |
| 634 | chart.Labels = []collectorapi.Label{ |
| 635 | {Key: "hostgroup", Value: hg}, |
| 636 | } |
| 637 | for _, dim := range chart.Dims { |
| 638 | dim.ID = fmt.Sprintf(dim.ID, hg) |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | return charts |
| 643 | } |
| 644 | |
| 645 | func (c *Collector) addHostgroupCharts(hg string) { |
| 646 | charts := newHostgroupCharts(hg) |
| 647 | |
| 648 | if err := c.Charts().Add(*charts...); err != nil { |
| 649 | c.Warning(err) |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | func (c *Collector) removeHostgroupCharts(hg string) { |
| 654 | prefix := "hostgroup_" + hg + "_" |
| 655 | |
| 656 | for _, chart := range *c.Charts() { |
| 657 | if strings.HasPrefix(chart.ID, prefix) { |
| 658 | chart.MarkRemove() |
| 659 | chart.MarkNotCreated() |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | var ( |
| 665 | backendChartsTmpl = collectorapi.Charts{ |
| 666 | backendStatusChartTmpl.Copy(), |
| 667 | backendConnectionsUsageChartTmpl.Copy(), |
| 668 | backendConnectionsRateChartTmpl.Copy(), |
| 669 | backendQueriesRateRateChartTmpl.Copy(), |
| 670 | backendTrafficChartTmpl.Copy(), |
| 671 | backendLatencyChartTmpl.Copy(), |
| 672 | } |
| 673 | |
| 674 | backendStatusChartTmpl = collectorapi.Chart{ |
| 675 | ID: "backend_%s_status", |
| 676 | Title: "Backend status", |
| 677 | Units: "status", |
| 678 | Fam: "backend status", |
| 679 | Ctx: "proxysql.backend_status", |
| 680 | Priority: prioBackendStatus, |
| 681 | Dims: collectorapi.Dims{ |
| 682 | {ID: "backend_%s_status_ONLINE", Name: "online"}, |
| 683 | {ID: "backend_%s_status_SHUNNED", Name: "shunned"}, |
| 684 | {ID: "backend_%s_status_OFFLINE_SOFT", Name: "offline_soft"}, |
| 685 | {ID: "backend_%s_status_OFFLINE_HARD", Name: "offline_hard"}, |
| 686 | }, |
| 687 | } |
| 688 | backendConnectionsUsageChartTmpl = collectorapi.Chart{ |
| 689 | ID: "backend_%s_connections_usage", |
| 690 | Title: "Backend connections usage", |
| 691 | Units: "connections", |
| 692 | Fam: "backend conns usage", |
| 693 | Ctx: "proxysql.backend_connections_usage", |
| 694 | Type: collectorapi.Stacked, |
| 695 | Priority: prioBackendConnectionsUsage, |
| 696 | Dims: collectorapi.Dims{ |
| 697 | {ID: "backend_%s_ConnFree", Name: "free"}, |
| 698 | {ID: "backend_%s_ConnUsed", Name: "used"}, |
| 699 | }, |
| 700 | } |
| 701 | backendConnectionsRateChartTmpl = collectorapi.Chart{ |
| 702 | ID: "backend_%s_connections_rate", |
| 703 | Title: "Backend connections established", |
| 704 | Units: "connections/s", |
| 705 | Fam: "backend conns established", |
| 706 | Ctx: "proxysql.backend_connections_rate", |
| 707 | Priority: prioBackendConnectionsRate, |
| 708 | Dims: collectorapi.Dims{ |
| 709 | {ID: "backend_%s_ConnOK", Name: "succeed", Algo: collectorapi.Incremental}, |
| 710 | {ID: "backend_%s_ConnERR", Name: "failed", Algo: collectorapi.Incremental}, |
| 711 | }, |
| 712 | } |
| 713 | backendQueriesRateRateChartTmpl = collectorapi.Chart{ |
| 714 | ID: "backend_%s_queries_rate", |
| 715 | Title: "Backend queries", |
| 716 | Units: "queries/s", |
| 717 | Fam: "backend queries", |
| 718 | Ctx: "proxysql.backend_queries_rate", |
| 719 | Priority: prioBackendQueriesRateRate, |
| 720 | Dims: collectorapi.Dims{ |
| 721 | {ID: "backend_%s_Queries", Name: "queries", Algo: collectorapi.Incremental}, |
| 722 | }, |
| 723 | } |
| 724 | backendTrafficChartTmpl = collectorapi.Chart{ |
| 725 | ID: "backend_%s_traffic", |
| 726 | Title: "Backend traffic", |
| 727 | Units: "B/s", |
| 728 | Fam: "backend traffic", |
| 729 | Ctx: "proxysql.backend_traffic", |
| 730 | Priority: prioBackendTraffic, |
| 731 | Dims: collectorapi.Dims{ |
| 732 | {ID: "backend_%s_Bytes_data_recv", Name: "recv", Algo: collectorapi.Incremental}, |
| 733 | {ID: "backend_%s_Bytes_data_sent", Name: "sent", Algo: collectorapi.Incremental}, |
| 734 | }, |
| 735 | } |
| 736 | backendLatencyChartTmpl = collectorapi.Chart{ |
| 737 | ID: "backend_%s_latency", |
| 738 | Title: "Backend latency", |
| 739 | Units: "microseconds", |
| 740 | Fam: "backend latency", |
| 741 | Ctx: "proxysql.backend_latency", |
| 742 | Priority: prioBackendLatency, |
| 743 | Dims: collectorapi.Dims{ |
| 744 | {ID: "backend_%s_Latency_us", Name: "latency"}, |
| 745 | }, |
| 746 | } |
| 747 | ) |
| 748 | |
| 749 | func newBackendCharts(hg, host, port string) *collectorapi.Charts { |
| 750 | charts := backendChartsTmpl.Copy() |
| 751 | |
| 752 | for _, chart := range *charts { |
| 753 | chart.ID = fmt.Sprintf(chart.ID, backendID(hg, host, port)) |
| 754 | chart.Labels = []collectorapi.Label{ |
| 755 | {Key: "hostgroup", Value: hg}, |
| 756 | {Key: "host", Value: host}, |
| 757 | {Key: "port", Value: port}, |
| 758 | } |
| 759 | for _, dim := range chart.Dims { |
| 760 | dim.ID = fmt.Sprintf(dim.ID, backendID(hg, host, port)) |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | return charts |
| 765 | } |
| 766 | |
| 767 | func (c *Collector) addBackendCharts(hg, host, port string) { |
| 768 | charts := newBackendCharts(hg, host, port) |
| 769 | |
| 770 | if err := c.Charts().Add(*charts...); err != nil { |
| 771 | c.Warning(err) |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | func (c *Collector) removeBackendCharts(hg, host, port string) { |
| 776 | prefix := "backend_" + backendID(hg, host, port) |
| 777 | |
| 778 | for _, chart := range *c.Charts() { |
| 779 | if strings.HasPrefix(chart.ID, prefix) { |
| 780 | chart.MarkRemove() |
| 781 | chart.MarkNotCreated() |
| 782 | } |
| 783 | } |
| 784 | } |