From 39587a8448eba50be5c657cb4409f894a54dbc26 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 6 Dec 2017 22:13:07 -0800 Subject: [PATCH] Add DB query error count metric --- package.json | 2 +- src/database.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 38803915..d95547ad 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.51.6", + "version": "3.51.7", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/database.js b/src/database.js index b3b316b6..1f8e09f3 100644 --- a/src/database.js +++ b/src/database.js @@ -18,6 +18,10 @@ const queryCount = new Counter({ name: 'cytube_db_queries_total', help: 'DB query count' }); +const queryErrorCount = new Counter({ + name: 'cytube_db_query_errors_total', + help: 'DB query error count' +}); setInterval(() => { queryLatency.reset(); @@ -55,10 +59,13 @@ class Database { runTransaction(fn) { const timer = Metrics.startTimer('db:queryTime'); const end = queryLatency.startTimer(); - return this.knex.transaction(fn).finally(() => { + return this.knex.transaction(fn).catch(error => { + queryErrorCount.inc(1); + throw error; + }).finally(() => { end(); Metrics.stopTimer(timer); - queryCount.inc(1, new Date()); + queryCount.inc(1); }); } } @@ -129,12 +136,13 @@ module.exports.query = function (query, sub, callback) { .then(res => { process.nextTick(callback, null, res[0]); }).catch(error => { + queryErrorCount.inc(1); LOGGER.error('Legacy DB query failed. Query: %s, Substitutions: %j, Error: %s', query, sub, error); process.nextTick(callback, 'Database failure', null); }).finally(() => { end(); Metrics.stopTimer(timer); - queryCount.inc(1, new Date()); + queryCount.inc(1); }); };