Description
openedon Jan 23, 2020
SQL generic module currently collects one event per row, being each field the title of the column, and the value the value in the row for this column.
So for a result like this one:
a | b |
---|---|
0 | 42 |
An event containing these fields is generated:
...
"a": 0,
"b": 42,
...
This is a problem for queries that return the values like this:
variable | value |
---|---|
a | 0 |
b | 42 |
Because they would generate in this case two events containing fields like these ones:
...
"variable": a
"value": 0
...
Enhancement
Add a mode that can be selected with a configuration option and can be used so for the previous example an only event is generated containing fields like this one:
...
"a": 0,
"b": 42,
...
Use case
Some queries, specially some used for monitoring or configuration, use this "key/value" format in responses, for example MySQLs SHOW STATUS
or SHOW VARIABLES
.
This feature would allow to have a configuration like the following one, that would generate a single event mapping each variable to a field:
- module: sql
metricsets: [query]
hosts: ...
driver: mysql
sql_response_format: variables
sql_query: "SHOW STATUS LIKE 'Key%'"
Would generate a single event per fetch with these fields:
"Key_blocks_used": 14955,
"Key_read_requests": 96854827,
"Key_reads": 162040,
"Key_write_requests": 7589728,
"Key_writes": 3813196,
The possible values for sql_response_format
would be:
sql_response_format: table
for current behaviour (default).sql_response_format: variables
for the "key/value" case.