awslabs / collectd-cloudwatch

A collectd plugin for sending data to Amazon CloudWatch
MIT License
200 stars 132 forks source link

Using Exec Plugin to Push Custom Metrics to CloudWatch Plugin? #17

Closed scott-wood-vgh closed 7 years ago

scott-wood-vgh commented 7 years ago

I've written a short Bash script (below) to get the status of the Tomcat7 service on a box, and return a 1 if it is running, or a 0 if it isn't (ALARM_STATUS). The script resides in /home/ubuntu/tomcat_status.sh and is owned by the ubuntu user:

#!/bin/bash

set -o pipefail
set -o errexit

SERVICE=tomcat7
SERVICE_NAME=Tomcat
ALARM_STATUS=0
HOSTNAME="${COLLECTD_HOSTNAME:-$(hostname -f)}"
INTERVAL="${COLLECTD_INTERVAL:-60}"

while sleep "${INTERVAL}"
do

if (( $(ps -ef | grep -v grep | grep $SERVICE | wc -l) > 0 ))
then
    ALARM_STATUS=1
    #echo "$SERVICE is running"
else
    ALARM_STATUS=0
    #echo "$SERVICE is not running"
fi

 echo -n "PUTVAL \"${HOSTNAME}/$SERVICE_NAME/gauge-tomcat_status\"      interval=${INTERVAL} N:$ALARM_STATUS"  
done

exit 0

Here is my whitelist.conf (processes, load and df-percent_bytes-used data is all sending successfully to CloudWatch):

df-.*-percent_bytes-used
load-.*
processes-.*
exec-.*

and the relevant part of collectd.conf:

<Plugin exec>
    Exec ubuntu "/home/ubuntu/tomcat_status.sh"
</Plugin>

Am I doing something wrong? I don't see any errors in the logfile, but nor do I see the data I expect getting pushed to CloudWatch. I've been in contact with AWS Support, and so far, they too are mystified and able to reproduce my problem on their end. Does the CloudWatch plugin support pushing metrics via Exec plugin/PUTVAL statement?

sebasrp commented 7 years ago

Hi Scott, We need to first rule out whether the problem is from the collection (collectd side of things) or publication.

Few things to try to narrow down the problem:

e-moshaya commented 5 years ago

@scott-wood-vgh did you figure this out in the end? I'm also trying to send collectd metrics via the exec plugin to CloudWatch and I'm really struggling. Can't find enough info in the documentation

koshkin-ccna commented 4 years ago

for those who found this page while troubleshooting issue with cloudwatch agent and collectd exec plugin. Don't use "echo" with "-n" parameter, it breaks cwagent data delivery for some reason. So the line should look like that: echo "PUTVAL \"${HOSTNAME}/$SERVICE_NAME/gauge-tomcat_status\" interval=${INTERVAL} N:$ALARM_STATUS"