Skip to content

Instantly share code, notes, and snippets.

@tksugimoto
Created February 21, 2018 04:46
Show Gist options
  • Save tksugimoto/154029772f41b547d642690acb487a34 to your computer and use it in GitHub Desktop.
Save tksugimoto/154029772f41b547d642690acb487a34 to your computer and use it in GitHub Desktop.
#!/bin/bash
host=$(hostname --short)
catbon_host=localhost
catbon_port=2003
echo "send metric of '$host' to $catbon_host:$catbon_port"
metric_name="sample"
send()
{
# echo "$1"
echo "$1" | nc $catbon_host $catbon_port -w1
}
while :
do
time=$(date +%s)
avg1=$(awk '{ print $1 }' < /proc/loadavg)
send "stats.$metric_name.$host.load1 $avg1 $time"
mem=$(free |
grep --line-buffered Mem: |
awk --assign=host=${host} '{ print $3 }')
send "stats.$metric_name.$host.memory.used $mem $time"
sleep 2s
done
# ssh target -N
Host target
# remote側port 転送先port(localから見える場所)
RemoteForward 2003 graphite.intra.example.com:2003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment