Chart Renderer for AWS CloudWatch Datapoints and Uploader to Slack
Last updated 3 years ago by tsakuma .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install aws-cloudwatch-chart-slack 
SYNC missed versions from official npm registry.

README Build Status

This module is a chart renderer and uploader to Slack. It's easy to share charts of CloudWatch on Slack. You can render charts for datapoints of CloudWatch, and can upload chart images to channels of Slack.

Getting Started

Tested with node-4.3.1 and npm-2.14.12.

$ npm install [--no-spin]

NOTE: v0.1.2 doesn't work with npm-3.x due to here

Set four environment variables.

export AWS_DEFAULT_REGION=ap-northeast-1                                                                                    │~
export SLACK_API_TOKEN=bbbb-xxxxxxxxxx-yyyyyyyyyy-zzzzzzzzzzz-aaaaaaaaaa

Try this, of course change channel name as you have.

SLACK_CHANNEL_NAME=#api-test ./bin/slack-cloudwatch-chart <EC2-instance-id>

A few seconds later, You can see a chart on the channel.

Hubot Integration

Please add the below snippet.

chart = require "aws-cloudwatch-chart-slack"
module.exports = (robot) ->
  robot.respond /cloudwatch (.+)/i, (msg) ->
    [id, params...] = msg.match[1].split(" ").map (e) -> e.trim()
    console.log "cloudwatch: #{id}"
    console.log " #{}" "#{}", [id, params...], (err, file)->
      if (err)
        console.error err.stack
        msg.send err.message

For arguments and available options, see here.

How to give arguments

By default, metric is CPUUtilization and namespace is AWS/EC2.

cloudwatch i-12345678

You can give metric and namespace at 2nd and 3rd arguments.

cloudwatch main-db FreeableMemory AWS/RDS

Multiple IDs can be given seperated with ,.

cloudwatch i-xyza5678,i-abcd1234

--region is to specify a AWS region.

cloudwatch i-abcd4567 --region us-west-2

--statistics has Maximum, Minimum, Average, Sum and SampleCount.

cloudwatch i-abcd1234 --statistics Maximum

Duration and period also can be given with --duration and period options.

cloudwatch i-abcd1234 --duration 3days --period 1hour

Regarding AWS/EC2, you can filter EC2 instances with some tags. Next example is that site is dev and role is webapp or db.

cloudwatch "tag:site=dev,role=webapp|db"


$ gulp

The gulp default task is to complie watching change of sources. src/*.js are compiled and saved under dist.

$ npm test
$ gulp test

The 1st one is to run test once, the 2nd one watches change of sources.

$ npm run lint

Linting with ESLint.

$ npm run typecheck

Run type check with flow.

How it works

    dist/render.js    Generate a png file
        dist/print-stats.js         Retrieve stats with aws-sdk CloudWatch.
        | stdin
        spawn: dist/gen-chart.js    Generate a .js file for c3 and a .html file.
        |                           Load the .html file with phantomjs and render a chart as .png
        | filename
    dist/upload.js    Read file.
    |                 Upload it to Slack with a REST API.
    unlink the file

Sub modules

Print statistics

Print stats using aws-sdk. Environment variables for AWS are referred.

$ node ./dist/print-stats.js [options] <instance-id>

Generating chart image in .png

Generate a png image and show the path.

$ cat <stats-file> | phantomjs ./dist/gen-chart.js


render.js calls print-stats.js and gen-chart.js.

$ node dist/render.js <instance-id>

Upload to a channel of Slack

$ node dist/upload.js ./.97516-1454216914841.png
{ ok: true,

How to debug for rendered charts

You can prevent removing temporary files with two options.

$ node dist/render.js i-003bb906 --filename a.png --keep-html --keep-js

The options preserve temporary files a.png.html and a.png.js. You can open the html file and see the chart rendered by c3.js.

$ open a.png.html


  1. Fork me (
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Pass npm run typecheck
  5. Pass npm run lint
  6. Add test cases for your changes
  7. Pass npm test
  8. Push to the branch (git push origin my-new-feature)
  9. Create your new pull request


MIT License

Current Tags

  • 0.1.3                                ...           latest (3 years ago)

4 Versions

  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 5
Dependencies (9)
Dev Dependencies (18)
Dependents (1)

Copyright 2014 - 2016 © |