Merge allow-piping (
#1) into master
Allow piping data directly to the script with '-'
i.e. if `some-command` generates data like:
Then you can send that directly to graphite with
some-command | ./pipe-to-graphite.sh -
Loading branch information
2 changed files
and 2 deletions.
@@ -39,7 +39,12 @@ Your script (lets say `~/glork-stats.sh`) would look something like this:
To get that regularly reported to Graphite, run this command
- pipe-to-graphite.sh ~/glork-stats.sh >> /var/log/glork-stats.log
+ ./pipe-to-graphite.sh ~/glork-stats.sh >> /var/log/glork-stats.log
+Or to report it to graphite at any time, if you want to use cron or something.
+The '-' argument indicates input should be read form stdin
+ ~/glork-stats.sh | ./pipe-to-graphite.sh -
Output from each run is prepended with a timestamp and echoed to stdout
@@ -20,9 +20,20 @@ if [ -f graphite.conf ]; then
# '-' indicates we should read from stdin
if [ " $1 " = ] "- " ; then
# Get a timestamp for sending to graphite
`date +%s `
# Pipe the output through sed, using a regex to
# append a $ts timestamp to the end of each line,
# and then to the correct server and port using netcat
+ sed -e
-e '/ [0-9]\+$/!d ' "s/ \$/ $ts/ " |
+ nc -w 1
# Normal usage just passes the command as the only parameter
# This checks if we're on a recursive call.
if [ " $1 " != ] "report-to-graphite " ; then
elif [ " $1 " != ] "report-to-graphite " ; then
command= " $1 "
# No point in attempting to run an empty command
@@ -41,6 +52,8 @@ if [ "$1" != "report-to-graphite" ]; then
<<- EOF >&2
$(basename $0) '/command/to/run' >> /var/log/some-stats.log
Or (for use from cron or other automated invocations):
/command/to/run | $(basename $0) -
* echo 'name number' pairs separated by newlines