diff --git a/README.md b/README.md index 189977e..07a17c5 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,21 @@ None Please use this [branch](https://github.com/librato/statsd-librato-backend/tree/branch-0.1.x). +## Docker + +You may use `bin/statsd-librato` to easily bootstrap the daemon inside +a container. + +Invoking this via `CMD` or `ENTRYPOINT` will create a simple +configuration and run the statsd daemon with this backend enabled, +listening on `8125`. + +The following environment variables are available to customize: + + - `LIBRATO_EMAIL` + - `LIBRATO_TOKEN` + - `LIBRATO_SOURCE` + ## Development - [Librato Backend](https://github.com/librato/statsd-librato-backend) diff --git a/bin/statsd-librato b/bin/statsd-librato new file mode 100755 index 0000000..17a8349 --- /dev/null +++ b/bin/statsd-librato @@ -0,0 +1,31 @@ +#!/usr/bin/env node +var fs = require('fs'), + rootPath = require('path').resolve(__dirname, './../../..'); + +if (!fs.existsSync(rootPath + '/stats.js')) { + console.error('This should run as a dependency inside etsy/statsd'); + if (process.env.DEBUG) { + console.log('rootPath: ' + rootPath); + console.log('__dirname: ' + __dirname); + } + process.exit(1); +} + +var configPath = rootPath + '/config.js'; + +if (!fs.existsSync(configPath)) { + var configFile = ''; + configFile += '{' + "\n"; + configFile += " librato: {\n"; + configFile += " email: process.env.LIBRATO_EMAIL || 'default',\n"; + configFile += " token: process.env.LIBRATO_TOKEN || 'token',\n"; + configFile += " source: process.env.LIBRATRO_SOURCE || 'env'\n"; + configFile += ' },' + "\n"; + configFile += " backends: [\"statsd-librato-backend\"],\n"; + configFile += " port: 8125\n"; + configFile += '}'; + + fs.writeFileSync(configPath, configFile, 'utf-8'); +} + +require(rootPath + '/bin/statsd'); diff --git a/package.json b/package.json index afd5b5b..057f73a 100644 --- a/package.json +++ b/package.json @@ -23,5 +23,8 @@ "main": "lib/librato.js", "scripts": { "test": "nodeunit test" + }, + "bin": { + "statsd-librato": "./bin/statsd-librato" } }