Telegraf Input Plugin (TIP) to collect resource usage of a QNAP NAS via SNMP. My use case was to create this script to collect resource usage data of my QNAP NAS to be stored in InfluxDB - visualized in Grafana. The script could be used for other uses if you just need the json output.
I used a snmpwalk application to gather the "oid" (Object Identifier) for the snmp values I was interested in tracking.
The script returns the below output:
{
"hostname": "<server name>",
"systemCPU_Usage": 8.40,
"systemTotalMem": 7860.7,
"systemFreeMem": 3873.3,
"systemUptime": 95420670,
"cpu_Temperature": 34,
"systemTemperature": 35,
"hdTemperature_HDD1": 27,
"hdTemperature_HDD2": 26,
"hdTemperature_HDD3": 27,
"hdTemperature_HDD4": 27,
"sysFanSpeed": 522,
"sysVolumeTotalSize": 2.67,
"sysVolumeFreeSize": 775.37
}
Install:
Below is a "one-liner" to download the latest release
LOCATION=$(curl -s https://api.github.com/repos/ninjaserif/TIP-QNAP-resource-usage-snmp/releases/latest \
| grep "tag_name" \
| awk '{print "https://github.com/ninjaserif/TIP-QNAP-resource-usage-snmp/archive/" substr($2, 2, length($2)-3) ".tar.gz"}') \
; curl -L -o TIP-QNAP-resource-usage-snmp_latest.tar.gz $LOCATION
sudo mkdir /usr/local/bin/TIP-QNAP-resource-usage-snmp && sudo tar -xvzf TIP-QNAP-resource-usage-snmp_latest.tar.gz --strip=1 -C /usr/local/bin/TIP-QNAP-resource-usage-snmp
cd /usr/local/bin/TIP-QNAP-resource-usage-snmp/
# this is preferred over renaming to avoid wiping if updating to new release
cp config-sample.sh config.sh
visit your QNAP web interface and log in. Once logged in open the "Control Panel" > navigate to "Network & File Services" > "SNMP". Ensure "Enable SNMP service" is ticked. My QNAP SNMP configuration was as follows:
<set your snmp password here>
edit config.sh and set your configuration - paste your snmp password into the config for QNAP server
HOST_IP="<server IP>" # your QNAP NAS IP
HOST_NAME="<server name>" # your QNAP name
COMMUNITY="<snmp password>" # SNMP password
confirm scripts have the following permissions:
you may also need to modify the ownership of both the script and config.sh to be owned by the telegraf user:group - i.e. sudo chown telegraf:telegraf TIP-QNAP-resource-usage-snmp.sh | sudo chown telegraf:telegraf config.sh
you may also need to modify the permissions of the directory the script and config.sh are stored to be owned by the telegraf user:group and set the read/write/execute permissions accordingly - i.e. sudo chown telegraf:telegraf TIP-QNAP-resource-usage-snmp | sudo chmod 774 /usr/local/bin/TIP-QNAP-resource-usage-snmp
add the following to your telegraf.conf
[[inputs.exec]]
commands = ["/usr/local/bin/TIP-QNAP-resource-usage-snmp/TIP-QNAP-resource-usage-snmp.sh"]
timeout = "10s"
data_format = "json"
name_suffix = "_QNAPsnmp"
tag_keys = ["hostname"]