Skip to content

Instantly share code, notes, and snippets.

@HeinrichHartmann
Last active January 18, 2019 15:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HeinrichHartmann/45856245941c5ed826767f281c404fd2 to your computer and use it in GitHub Desktop.
Save HeinrichHartmann/45856245941c5ed826767f281c404fd2 to your computer and use it in GitHub Desktop.
Publish dropbox "files remaining" as statsd metrics
statsd=localhost:8125
dropbox=$HOME/bin/dropbox.py
socat=/usr/bin/socat
grep=/bin/grep
sed=/bin/sed
# Example output of `drobox.py status`
# ```
# Syncing (51,938 files remaining, 2 mins left)
# Downloading 51,938 files (3,069 KB/sec, 2 mins left)
# ```
# The line below picks out the number "51938" in a crude way
N=$($dropbox status | $grep remaining | $sed -e 's/remaining.*//g' -e 's/[^0-9]//g')
# Not found?
[[ "x$N" == "x" ]] && exit 1
# Emit metric
printf 'dropbox`files_remaining:%d|g\n' $N | $socat -t 0 STDIN UDP:$statsd
@HeinrichHartmann
Copy link
Author

HeinrichHartmann commented Jan 29, 2018

Put that into your user's cron:

$ crontab -l
* * * * * /path/to/dropbox-statsd.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment