[英]How to debug exec script for collectd
I wrote a little script to collect the power state (standby, actice) of my disk. 我写了一个小脚本来收集磁盘的电源状态(备用,actice)。 It is based on this script: https://github.com/collectd/collectd/blob/master/contrib/exec-smartctl
它基于以下脚本: https : //github.com/collectd/collectd/blob/master/contrib/exec-smartctl
/usr/share/collectd/exec_hddpwrmode.sh
#!/bin/bash
HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
INTERVAL="${COLLECTD_INTERVAL:-60}"
while sleep "$INTERVAL"
do
for disk in sda sdb sdc sdd sde sdf
do
STATE=$(sudo smartctl -i -n standby /dev/$disk | grep -e "Device is in STANDBY mode" -e "Power mode is: ACTIVE or IDLE" 2>/dev/null)
if [ "$STATE" = "Device is in STANDBY mode, exit(2)" ]
then
# STANBY
VALUE="0"
else
if [ "$STATE" = "Power mode is: ACTIVE or IDLE" ]
then
# ACTIVE or IDLE
VALUE="1"
else
# ERROR
VALUE="U"
fi
fi
echo "PUTVAL $HOSTNAME/disk-$disk/disk-state interval=$INTERVAL N:$VALUE" | tee -a /tmp/hddpwrstate.log
done
done
The output in /tmp/hddpwrstate.log
looks good. /tmp/hddpwrstate.log
的输出看起来不错。
PUTVAL magneto/exec-smart/pwrstate_sdf interval=10.000 N:0
PUTVAL magneto/exec-smart/pwrstate_sda interval=10.000 N:0
PUTVAL magneto/exec-smart/pwrstate_sdb interval=10.000 N:1
PUTVAL magneto/exec-smart/pwrstate_sdc interval=10.000 N:0
PUTVAL magneto/exec-smart/pwrstate_sdd interval=10.000 N:0
PUTVAL magneto/exec-smart/pwrstate_sde interval=10.000 N:0
PUTVAL magneto/exec-smart/pwrstate_sdf interval=10.000 N:0
That means I have no permission issue (the script needs to be run by a user that can use sudo). 这意味着我没有权限问题(脚本必须由可以使用sudo的用户运行)。 And it is executed by collectd
并由收集执行
But I get no new rrd-files in /var/lib/collectd/rrd/<hostname>
or new measurements in my InfluxDB. 但是我在
/var/lib/collectd/rrd/<hostname>
没有新的rrd文件,在我的InfluxDB中也没有新的度量。
> show measurements
name: measurements
name
----
cpu_value
df_value
disk_io_time
disk_read
disk_value
disk_weighted_io_time
disk_write
entropy_value
interface_rx
interface_tx
irq_value
load_longterm
load_midterm
load_shortterm
memory_value
processes_value
rrdcached_value
swap_value
uptime_value
users_value
I tried activating debug. 我尝试激活调试。
<Plugin syslog>
LogLevel debug
</Plugin>
But it does not help. 但这无济于事。
Nov 19 12:13:12 magneto collectd[30028]: Exiting normally.
Nov 19 12:13:12 magneto collectd[30028]: collectd: Stopping 5 read threads.
Nov 19 12:13:12 magneto collectd[30028]: exec plugin: Sent SIGTERM to 30042
Nov 19 12:13:12 magneto collectd[30028]: collectd: Stopping 5 write threads.
Nov 19 12:13:13 magneto collectd[31752]: Stopping statistics collection and monitoring daemon: collectd.
Nov 19 12:13:13 magneto collectd[31767]: syslog: invalid loglevel [debug] defaulting to 'info'
Nov 19 12:13:13 magneto collectd[31768]: syslog: invalid loglevel [debug] defaulting to 'info'
Nov 19 12:13:13 magneto collectd[31769]: Initialization complete, entering read-loop.
Nov 19 12:13:13 magneto collectd[31764]: Starting statistics collection and monitoring daemon: collectd.
So, why does my script not work? 那么,为什么我的脚本不起作用? Is there something wrong?
有什么不对? Or how can I debug to find the issue myself?
或者我该如何调试自己找到问题?
My system: Debian 8 with OpenMediaVault. 我的系统:Debian 8和OpenMediaVault。
I got it working. 我知道了
Loks like my PUTVAL was not correct. 像我的PUTVAL这样的错误消息是不正确的。
This is working now: 现在正在工作:
echo "PUTVAL $HOSTNAME/exec-$disk/gauge-disk_state interval=$INTERVAL N:$VALUE" | tee -a /tmp/hddpwrstate.log
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.