npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

aws-cloudwatch-chart-slack

v0.1.3

Published

Chart Renderer for AWS CloudWatch Datapoints and Uploader to Slack

Readme

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 AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
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 "message.room: #{msg.message.room}"

    chart.slack.post "#{msg.room}", [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"

Development

$ gulp

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

$ npm test
or
$ 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/index.js
    |
    v
    dist/render.js    Generate a png file
        |
        v
        dist/print-stats.js         Retrieve stats with aws-sdk CloudWatch.
        |
        | stdin
        v
        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
        |
    +<--+
    |
    v
    dist/upload.js    Read file.
    |                 Upload it to Slack with a REST API.
    |
    v
    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>
[{"Namespace":"AWS/EC2","InstanceId":"i-003bb906","Label":"CPUUtilization","Respon...

Generating chart image in .png

Generate a png image and show the path.

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

Render

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

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

Upload to a channel of Slack

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

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
a.png

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

Contribution

  1. Fork me (https://github.com/tmtk75/aws-cloudwatch-chart-slack)
  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

License

MIT License