From d4374e74cd075377fcaf4ee4399d3b5292bf68a8 Mon Sep 17 00:00:00 2001 From: till Date: Sat, 14 Jan 2017 18:39:37 +0100 Subject: [PATCH 1/2] Enhancement: bootstrap config and start statsd --- bin/statsd-librato | 31 +++++++++++++++++++++++++++++++ package.json | 3 +++ 2 files changed, 34 insertions(+) create mode 100755 bin/statsd-librato 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 85ff8f2..f3206f3 100644 --- a/package.json +++ b/package.json @@ -21,5 +21,8 @@ "main": "lib/librato.js", "scripts": { "test": "nodeunit test" + }, + "bin": { + "statsd-librato": "./bin/statsd-librato" } } From 1633c1908b8cce820e2fd2cf6ed24e85d2ba31de Mon Sep 17 00:00:00 2001 From: till Date: Mon, 6 Feb 2017 23:31:18 +0100 Subject: [PATCH 2/2] Update: README for docker/bootstrap --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index ab9c9ce..6054b8c 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,21 @@ published by statsd. You can use the API pattern DELETE route to mass delete metrics. To delete only counter metrics, add the parameter `metric_type=counter`. +## 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)