I'm trying to parse and rewrite the output of the "resolvectl statistics" command in the hope of producing a munin plugin to monitor resolvectl processing. The output looks like this:
Transactions
Current Transactions: 0
Total Transactions: 65277
Cache
Current Cache Size: 13
Cache Hits: 20422
Cache Misses: 70974
Failure Transactions
Total Timeouts: 32
Total Timeouts (Stale Data Served): 0
Total Failure Responses: 5203
Total Failure Responses (Stale Data Served): 0
DNSSEC Verdicts
Secure: 0
Insecure: 0
Bogus: 0
Indeterminate: 0
I need to rewrite this output to produce something that looks like this:
current-transactions.value 0
total-transactions.value 65277
cache-size.value 13
cache-hits.value 20422
cache-misses.value 70974
total-timeouts.value 32
total-timeouts-stale.value 0
total-failures.value 5203
total-failures-stale.value 0
dnssec-secure.value 0
dnssec-insecure.value 0
dnssec-bogus.value 0
dnssec-indeterminate.value 0
I've been able to isolate the values using this awk script:
$ sudo resolvectl statistics|awk -F ":" {'print $2'}|awk NF
0
65227
13
20422
70974
32
0
5203
0
0
0
0
0
How can I alter the awk output to add to labels described above?
resolvectlsupport a--jsonoutput format? if so, it might be more robust to use that (ex. something likesudo resolvectl --json=short statistics | mlr --ijson --flatsep '-' --oxtab cat)awk '/Current Transactions/{print "current-transactions.value " $NF; /Total transactions/{print "total-transactions.value " $NF};/etc.etc/{}' file