Hi,
I have a problem with executing an command to get the output into grafana.
For background, I have a router and want to monitor the cpu and memory usage for that router.
Unfortunatly the SNMP requests have no single command for getting cpu or memory usage.
There is only an command thats listing me variuos information and the cpu & memory usage.
If I run
snmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0
the output is:
SNMPv2-MIB::sysDescr.0 = STRING: DrayTek Corporation, Router Model: Vigor165 Series, Version: 4.0.2_STD, Build Date/Time:Jan 21 2019 11:27:27, CPU Usage: 2%, Memory Usage:66%
Now I used the following command to extract only the the value for the cpu usage:
âsnmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0 | awk âBEGIN { FS = â,â } ; {print $5}â | awk â{ print $3 }â | cut -d â%â -f 1â
the output is: 2
and for memory:
âsnmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0 | awk âBEGIN { FS = â,â } ; {print $6}â | awk âBEGIN { FS = â:â } ; {print $2}â | cut -d â%â -f 1â
the output is: 66
The question for me is now, how can I use that information that it can be imported into grafana.
My thought was, I use the âinputs.execâ command but unfortunatly that is not working.
I tried either
[[inputs.exec]]
commands = [âsh -c âsnmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0 | awk âBEGIN { FS = â,â } ; {print $5}â | awk â{ print $3 }â | cut -d â%â -f 1ââ]
timeout = â4sâ
name_override = âCPU_routerâ
name_suffix = ârouter_cpuâ
[inputs.exec.tags]
metrics_source = âCPUâ
data_format = âvalueâ
data_type = âintegerâ
or
[[inputs.exec]]
commands = [â/home/thomas/cpu.shâ]
(the script contains the command mentioned above and is working)
but that doesnât work.
The output is either:
(command)
[inputs.exec]: Error in plugin: exec: exec: â}â: executable file not found in $PATH for command â } ; {print $5}â | awk â{ print $3 }â | cut -d â%â -f 1â':
2019-11-09T20:13:14Z E! [inputs.exec]: Error in plugin: exec: exit status 127 for command 'sh -C 'snmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0 | awk 'BEGIN { FS = ': sh: 0: Canât open snmpwalk -v2c -c snmp 192.168.x.x SNMPv2-MIB::sysDescr.0 | awk BEGIN
or
(script)
[inputs.exec]: Error in plugin: must be an object or an array of objects
hopefully some of you can help me to solve my issue.
Thanks.