我正在尝试解析并重写“resolvectl statistics”命令的输出,希望生成一个 munin 插件来监控 resolvectl 处理。输出如下所示:
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
我需要重写此输出以产生如下所示的内容:
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
我已经能够使用这个 awk 脚本隔离这些值:
$ sudo resolvectl statistics|awk -F ":" {'print $2'}|awk NF
0
65227
13
20422
70974
32
0
5203
0
0
0
0
0
我如何改变 awk 输出以添加到上面描述的标签?
假设/理解:
一般方法:
:
NF==2
)那么...$1
)在数组中查找相关标签模拟OP的
resolvectl
输出:一种
awk
方法:进行试驾:
笔记:
cat resolve.out |
为sudo resolvectl statistics |
labels[]
条目使用任何 awk:
我会用
perl
: