├── .gitignore ├── Dockerfile ├── README.md ├── client.js ├── docker-compose.yml ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build 2 | # docker build -t chamerling/lazyguy-monitoring . 3 | 4 | FROM node:0.10.36 5 | 6 | MAINTAINER Christophe Hamerling 7 | 8 | # Cache NPM install of package.json has not been changed 9 | # cf http://www.clock.co.uk/blog/a-guide-on-how-to-cache-npm-install-with-docker 10 | ADD package.json /src/package.json 11 | RUN cd /src && npm install --production --unsafe-perm 12 | 13 | ADD . /src 14 | 15 | EXPOSE 3000 16 | 17 | WORKDIR /src 18 | CMD ["npm", "start"] 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Layguy-monitoring 2 | ================= 3 | 4 | This repo shows how to get metrics from an Expressjs application with the help of statsd and Grafana. It uses Docker and docker-compose to make things easy. 5 | 6 | ``` 7 | docker-compose up 8 | ``` 9 | 10 | Will start the express application, statsd, graphite and grafana. 11 | 12 | Details are available on https://medium.com/@chamerling/getting-metrics-from-your-express-app-without-effort-with-docker-and-grafana-ac8f6c42cbfb 13 | -------------------------------------------------------------------------------- /client.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var http = require('http'); 4 | var request = require('request'); 5 | 6 | 7 | function get() { 8 | request('http://boot2docker:3000', function (error, response, body) { 9 | if (!error && response.statusCode == 200) { 10 | console.log(body) 11 | } 12 | }); 13 | } 14 | 15 | function init() { 16 | var loop = function() { 17 | get(); 18 | var rand = Math.round(Math.random() * 1000); 19 | setTimeout(myFunction, rand); 20 | } 21 | loop(); 22 | } 23 | 24 | init(); 25 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | app: 2 | build: . 3 | links: 4 | - statsd:statsd 5 | ports: 6 | - "3000:3000" 7 | statsd: 8 | image: hopsoft/graphite-statsd 9 | ports: 10 | - "3002:80" 11 | - "2003:2003" 12 | - "8125:8125/udp" 13 | grafana: 14 | image: grafana/grafana 15 | ports: 16 | - "3001:3000" 17 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var express = require('express'); 4 | var statsd = require('express-statsd'); 5 | var app = express(); 6 | 7 | app.use(statsd({host: 'statsd', port: 8125})); 8 | 9 | app.get('/', function (req, res) { 10 | res.json(200, {yo: 'lo'}); 11 | }); 12 | 13 | app.get('/err', function (req, res) { 14 | res.json(500, {err: 'You failed!'}); 15 | }); 16 | 17 | app.listen(3000, function(err) { 18 | console.log('LazyGuy Application is now started'); 19 | }); 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "lazyguy-monitoring", 3 | "version": "0.0.0", 4 | "description": "Monitor an Express App with statsd and Grafana", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/chamerling/lazyguy-monitoring" 13 | }, 14 | "keywords": [ 15 | "monitoring", 16 | "express", 17 | "statsd", 18 | "grafana" 19 | ], 20 | "author": "Christophe Hamerling ", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/chamerling/lazyguy-monitoring/issues" 24 | }, 25 | "homepage": "https://github.com/chamerling/lazyguy-monitoring", 26 | "dependencies": { 27 | "express": "^4.12.3", 28 | "express-statsd": "^0.3.0" 29 | }, 30 | "devDependencies": { 31 | "request": "^2.55.0" 32 | } 33 | } 34 | --------------------------------------------------------------------------------