Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code offer: CloudWatch monitoring of job queue size #101

Open
ThrawnCA opened this issue Feb 25, 2020 · 0 comments
Open

Code offer: CloudWatch monitoring of job queue size #101

ThrawnCA opened this issue Feb 25, 2020 · 0 comments

Comments

@ThrawnCA
Copy link
Collaborator

If anyone is interested, we've recently developed a small shell script designed to monitor the job queue and report metrics to Amazon CloudWatch.

#!/bin/sh

LOG_FILE=/var/log/ckan/ckan-worker-queue.log
TEMP_FILE=/tmp/ckan-worker-queue.log
echo "CKAN job queue at $(date):" >> $LOG_FILE
JOB_COUNT=$(/usr/lib/ckan/default/bin/paster --plugin=ckan jobs list -c /etc/ckan/default/production.ini 2>/dev/null | tee -a $LOG_FILE | tee $TEMP_FILE | wc -l)
echo "Total: $JOB_COUNT job(s)" >> $LOG_FILE
if [ "$JOB_COUNT" -gt 0 ]; then
    OLDEST_TIME=$(date -u --date $(head -1 $TEMP_FILE | awk '{print $1}') +'%s')
    MAX_AGE=$(expr $(date -u +'%s') - $OLDEST_TIME)
    echo "Oldest job is from $OLDEST_TIME ($(expr $MAX_AGE / 60) minute(s) ago)" >> $LOG_FILE
else
    MAX_AGE=0
fi
aws cloudwatch put-metric-data --region us-east-1 --namespace CKAN --metric-data "MetricName=job_queue_size,Dimensions=[{Name=Application,Value=MyCKANApplication},{Name=Environment,Value=DEV}],Value=$JOB_COUNT" "MetricName=max_job_age,Dimensions=[{Name=Application,Value=MyCKANApplication},{Name=Environment,Value=DEV}],Value=$MAX_AGE"

Note that LOG_FILE must be in a directory that exists and is writable by the user running the script. Also, the machine where this runs needs to have appropriate AWS credentials set up to allow access to CloudWatch.

The metric dimensions are optional; we use them because we have multiple different CKAN portals, and multiple environments (DEV, STAGING, etc), in the same AWS account.

duttonw pushed a commit that referenced this issue Nov 21, 2024
…dab1141f96ac

[Snyk] Fix for 4 vulnerabilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant