Skip to content

Instantly share code, notes, and snippets.

@jeremiahsnapp
Last active November 20, 2015 19:00
Show Gist options
  • Save jeremiahsnapp/98a02925ea6a77912535 to your computer and use it in GitHub Desktop.
Save jeremiahsnapp/98a02925ea6a77912535 to your computer and use it in GitHub Desktop.
Easy statsd in Chef Server

Configure the chef server to push statistics in statsd format

cat >>/etc/opscode/chef-server.rb <<EOF
estatsd['protocol'] = 'statsd'
EOF
chef-server-ctl reconfigure

For demonstration purposes view the stats that are being pushed from the chef server

apt-get install socat
socat -u udp-recv:9466 -

Use statsd to aggregate and perform calculations on the stats on a 10 second interval

Download and unpack nodejs binary and statsd on the chef server

cd ~
wget https://nodejs.org/dist/v4.2.2/node-v4.2.2-linux-x64.tar.gz
tar xzf node-v4.2.2-linux-x64.tar.gz
wget https://github.com/etsy/statsd/archive/master.tar.gz
tar xzf master.tar.gz

Configure statsd

cat > localConfig.js <<EOF
{
  console: { prettyprint: true }
, port: 9466
, backends: [ "./backends/console" ]
}
EOF

Run statsd and parse out counter_rates (output will appear on a 10 second interval)

./node-v4.2.2-linux-x64/bin/node ./statsd-master/stats.js localConfig.js | perl -lane 'print localtime. $_ if /counter_rates:/ ... /sets:/'
Fri Nov 20 17:30:17 2015  counter_rates:
Fri Nov 20 17:30:17 2015   { 'statsd.bad_lines_seen': 534.9,
Fri Nov 20 17:30:17 2015     'statsd.packets_received': 534.9,
Fri Nov 20 17:30:17 2015     'statsd.metrics_received': 4362.1,
Fri Nov 20 17:30:17 2015     'bifrost.application.byStatusCode.200': 106.7,
Fri Nov 20 17:30:17 2015     'bifrost.ip-172-31-25-60.byStatusCode.200': 106.7,
Fri Nov 20 17:30:17 2015     'bifrost.application.allRequests': 133.3,
Fri Nov 20 17:30:17 2015     'bifrost.ip-172-31-25-60.allRequests': 133.3,
Fri Nov 20 17:30:17 2015     'bifrost.application.byRequestType.bifrost_wm_acl_member_resource.object.GET': 79.7,
Fri Nov 20 17:30:17 2015     'chefAPI.application.allRequests': 134,
Fri Nov 20 17:30:17 2015     'chefAPI.ip-172-31-25-60.allRequests': 134,
Fri Nov 20 17:30:17 2015     'chefAPI.application.byRequestType.depsolver.POST': 27,
Fri Nov 20 17:30:17 2015     'chefAPI.application.byStatusCode.200': 134.2,
Fri Nov 20 17:30:17 2015     'chefAPI.ip-172-31-25-60.byStatusCode.200': 134.2,
Fri Nov 20 17:30:17 2015     'chefAPI.application.byRequestType.search.GET': 54.2,
Fri Nov 20 17:30:17 2015     'bifrost.application.byRequestType.bifrost_wm_bulk_resource.undefined.POST': 26.7,
Fri Nov 20 17:30:17 2015     'bifrost.application.byStatusCode.204': 26.7,
Fri Nov 20 17:30:17 2015     'bifrost.ip-172-31-25-60.byStatusCode.204': 26.7,
Fri Nov 20 17:30:17 2015     'bifrost.application.byRequestType.bifrost_wm_acl_member_resource.container.GET': 26.9,
Fri Nov 20 17:30:17 2015     'chefAPI.application.byRequestType.nodes.PUT': 26.5,
Fri Nov 20 17:30:17 2015     'chefAPI.application.byRequestType.nodes.GET': 26.3 },
Fri Nov 20 17:30:17 2015  sets: {},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment