From 804088009eeb45c2b5838a75299ec08e2d22ddf4 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Tue, 14 Oct 2014 22:12:35 +0200 Subject: [PATCH] Report to statsd the status of redis pools --- NEWS.md | 3 +++ app.js | 14 ++++++++++---- config/environments/development.js.example | 3 +++ config/environments/production.js.example | 3 +++ config/environments/staging.js.example | 3 +++ config/environments/test.js.example | 3 +++ 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index d4448129..439acd10 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,9 @@ 1.19.1 -- 2014-mm-dd -------------------- +New features: + - Report to statsd the status of redis pools + Enhancements: - Share one redis-mpool across the application diff --git a/app.js b/app.js index a3d27f97..e8d5ea44 100755 --- a/app.js +++ b/app.js @@ -70,10 +70,7 @@ if ( global.environment.rollbar ) { log4js.configure(log4js_config, { cwd: __dirname }); global.logger = log4js.getLogger(); -var redisOpts = _.extend(global.environment.redis, { - name: 'windshaft_cartodb', - reportInterval: 5000 - }), +var redisOpts = _.extend(global.environment.redis, { name: 'windshaft' }), redisPool = new RedisPool(redisOpts); // Include cartodb_windshaft only _after_ the "global" variable is set @@ -83,6 +80,15 @@ var CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft'), ws = CartodbWindshaft(serverOptions); +if (global.statsClient) { + redisPool.on('status', function(status) { + var keyPrefix = status.name + '.db' + status.db + '.'; + global.statsClient.gauge(keyPrefix + 'count', status.count); + global.statsClient.gauge(keyPrefix + 'unused', status.unused); + global.statsClient.gauge(keyPrefix + 'waiting', status.waiting); + }); +} + // Maximum number of connections for one process // 128 is a good number if you have up to 1024 filedescriptors // 4 is good if you have max 32 filedescriptors diff --git a/config/environments/development.js.example b/config/environments/development.js.example index d0ec046b..0205603c 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -108,6 +108,9 @@ var config = { slowPool: { log: true, // whether a slow acquire must be logged or not elapsedThreshold: 25 // the threshold to determine an slow acquire must be reported or not + }, + emitter: { + statusInterval: 5000 } } ,sqlapi: { diff --git a/config/environments/production.js.example b/config/environments/production.js.example index 794f7dfc..0bd36d57 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -102,6 +102,9 @@ var config = { slowPool: { log: true, // whether a slow acquire must be logged or not elapsedThreshold: 25 // the threshold to determine an slow acquire must be reported or not + }, + emitter: { + statusInterval: 5000 } } ,sqlapi: { diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index c07d17cb..13651d1f 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -102,6 +102,9 @@ var config = { slowPool: { log: true, // whether a slow acquire must be logged or not elapsedThreshold: 25 // the threshold to determine an slow acquire must be reported or not + }, + emitter: { + statusInterval: 5000 } } ,sqlapi: { diff --git a/config/environments/test.js.example b/config/environments/test.js.example index f91e36a4..a016e0ac 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -102,6 +102,9 @@ var config = { slowPool: { log: true, // whether a slow acquire must be logged or not elapsedThreshold: 25 // the threshold to determine an slow acquire must be reported or not + }, + emitter: { + statusInterval: 5000 } } ,sqlapi: {