Statsd and AWS Cloudwatch Integration

Kailash Verma
2 min readApr 18, 2017

StatsD is a smart Node.js package that collects and aggregates statistics from differents apps sent over the UDP protocol. At a set time interval it forwards the aggregated data to a configured backend. We can use AWS Cloudwatch as its backend for monitoring purposes.

AWS cloudwatch have its own metrics, what if we want to have our own application’s metrics on AWS cloudwatch? We can use Statsd, using which we can send our applicaction’s custom metrics to cloudwatch and use those metrics accordingly for alarms and monitoring.

Prerequisites :

  • Before statsd configuration, we need to install :
  • Git, npm, nodejs

Installations :

Install Git :

$ apt-get install git

Install npm :

$ apt-get install npm

(This package normally comes with the nodejs installation, but if its missing please run the command mentioned above)

Install nodejs :

$ wget -qO- https://deb.nodesource.com/setup_7.x | sudo bash -

$sudo apt-get install -y nodejs

Now we have git, npm and node installed on our machine.

  • Clone the statsd project from the website. i.e.

$ git clone https://github.com/etsy/statsd.git

  • The CloudWatch backend is an npm package that can be installed with the npm command.

$ npm install aws-cloudwatch-statsd-backend

Configuration :

The StatsD and its backends are configured in a json object placed in a file supplied to StatsD at the command line. For example, start StatsD with the following :

$ node ./stats.js ./myConfig.js

  • Create the config file inside the folder statsd as myConfig.js and add the following lines :

{

backends: [ “aws-cloudwatch-statsd-backend” ],

cloudwatch:

{

accessKeyId: ‘accessKey’,

secretAccessKey: ‘secretKey’,

region: ‘US_EAST_1’

// namespace: ‘AWS/EC2’,

// metricName: ‘CPUUtilization’

}
}

  • The access keys can be your personal credentials to AWS but it is highly recommended to create an ad hoc user via Amazon’s IAM service and use those credentials.
  • The region is for example EU_WEST_1 or US_EAST_1
  • Keep this on the same folder where stats.js is present.
  • run both .js file by command : node stats.js myConfig.js
  • The statsd sends the metric to cloudwatch.

--

--

Kailash Verma

DevOps Consultant | Cloud Engineer | Security | CI/CD | HA | AWS | Docker | Kubernetes | Aerospike | Cassandra | Rabbitmq | Consul | MongoDB