From d0c1e8cbd97b6bf63ab933e48c96b5cad7c8967b Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sat, 12 Aug 2017 13:12:58 -0700 Subject: [PATCH] Change metric names to follow prometheus naming guide --- package.json | 2 +- src/channel/chat.js | 8 ++++---- src/channel/playlist.js | 4 ++-- src/database.js | 6 +++--- src/get-info.js | 4 ++-- src/io/ioserver.js | 12 ++++++------ src/web/webserver.js | 8 ++++---- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index a69a4a7a..69a1231f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.45.0", + "version": "3.46.0", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/channel/chat.js b/src/channel/chat.js index b8e378e9..6ccd3c4e 100644 --- a/src/channel/chat.js +++ b/src/channel/chat.js @@ -151,13 +151,13 @@ ChatModule.prototype.restrictNewAccount = function restrictNewAccount(user, data }; const chatIncomingCount = new Counter({ - name: 'cytube_chat_incoming_count', + name: 'cytube_chat_incoming_total', help: 'Number of incoming chatMsg frames' }); ChatModule.prototype.handleChatMsg = function (user, data) { var self = this; counters.add("chat:incoming"); - chatIncomingCount.inc(); + chatIncomingCount.inc(1, new Date()); if (!this.channel || !this.channel.modules.permissions.canChat(user)) { return; @@ -288,7 +288,7 @@ ChatModule.prototype.handlePm = function (user, data) { }; const chatSentCount = new Counter({ - name: 'cytube_chat_sent_count', + name: 'cytube_chat_sent_total', help: 'Number of broadcast chat messages' }); ChatModule.prototype.processChatMsg = function (user, data) { @@ -360,7 +360,7 @@ ChatModule.prototype.processChatMsg = function (user, data) { } this.sendMessage(msgobj); counters.add("chat:sent"); - chatSentCount.inc(); + chatSentCount.inc(1, new Date()); }; ChatModule.prototype.formatMessage = function (username, data) { diff --git a/src/channel/playlist.js b/src/channel/playlist.js index a493b97e..c778cbb2 100644 --- a/src/channel/playlist.js +++ b/src/channel/playlist.js @@ -283,7 +283,7 @@ PlaylistModule.prototype.sendPlaylist = function (users) { }; const changeMediaCounter = new Counter({ - name: 'cytube_playlist_played_count', + name: 'cytube_playlist_plays_total', help: 'Counter for number of playlist items played', labelNames: ['shortCode'] }); @@ -301,7 +301,7 @@ PlaylistModule.prototype.sendChangeMedia = function (users) { var m = this.current.media; this.channel.logger.log("[playlist] Now playing: " + m.title + " (" + m.type + ":" + m.id + ")"); - changeMediaCounter.labels(m.type).inc(); + changeMediaCounter.labels(m.type).inc(1, new Date()); } else { users.forEach(function (u) { u.socket.emit("setCurrent", uid); diff --git a/src/database.js b/src/database.js index 695202b1..9ac47194 100644 --- a/src/database.js +++ b/src/database.js @@ -11,11 +11,11 @@ import { Summary, Counter } from 'prom-client'; const LOGGER = require('@calzoneman/jsli')('database'); const queryLatency = new Summary({ - name: 'cytube_db_query_latency', + name: 'cytube_db_query_duration_seconds', help: 'DB query latency (including time spent acquiring connections)' }); const queryCount = new Counter({ - name: 'cytube_db_query_count', + name: 'cytube_db_queries_total', help: 'DB query count' }); @@ -54,7 +54,7 @@ class Database { return this.knex.transaction(fn).finally(() => { end(); Metrics.stopTimer(timer); - queryCount.inc(); + queryCount.inc(1, new Date()); }); } } diff --git a/src/get-info.js b/src/get-info.js index a16fad88..033ba5f8 100644 --- a/src/get-info.js +++ b/src/get-info.js @@ -18,7 +18,7 @@ import { lookup as lookupCustomMetadata } from './custom-media'; const LOGGER = require('@calzoneman/jsli')('get-info'); const lookupCounter = new Counter({ - name: 'cytube_media_lookup_count', + name: 'cytube_media_lookups_total', help: 'Count of media lookups', labelNames: ['shortCode'] }); @@ -558,7 +558,7 @@ module.exports = { getMedia: function (id, type, callback) { if(type in this.Getters) { LOGGER.info("Looking up %s:%s", type, id); - lookupCounter.labels(type).inc(); + lookupCounter.labels(type).inc(1, new Date()); this.Getters[type](id, callback); } else { callback("Unknown media type '" + type + "'", null); diff --git a/src/io/ioserver.js b/src/io/ioserver.js index 66410946..ae159cc7 100644 --- a/src/io/ioserver.js +++ b/src/io/ioserver.js @@ -196,11 +196,11 @@ class IOServer { } const incomingEventCount = new Counter({ - name: 'cytube_socketio_incoming_events', + name: 'cytube_socketio_incoming_events_total', help: 'Number of received socket.io events from clients' }); const outgoingPacketCount = new Counter({ - name: 'cytube_socketio_outgoing_packets', + name: 'cytube_socketio_outgoing_packets_total', help: 'Number of outgoing socket.io packets to clients' }); function patchSocketMetrics() { @@ -209,12 +209,12 @@ function patchSocketMetrics() { Socket.prototype.onevent = function patchedOnevent() { onevent.apply(this, arguments); - incomingEventCount.inc(); + incomingEventCount.inc(1, new Date()); }; Socket.prototype.packet = function patchedPacket() { packet.apply(this, arguments); - outgoingPacketCount.inc(); + outgoingPacketCount.inc(1, new Date()); }; } @@ -266,11 +266,11 @@ const promSocketCount = new Gauge({ labelNames: ['transport'] }); const promSocketAccept = new Counter({ - name: 'cytube_sockets_accept_count', + name: 'cytube_sockets_accepts_total', help: 'Counter for number of connections accepted. Excludes rejected connections.' }); const promSocketDisconnect = new Counter({ - name: 'cytube_sockets_disconnect_count', + name: 'cytube_sockets_disconnects_total', help: 'Counter for number of connections disconnected.' }); function emitMetrics(sock) { diff --git a/src/web/webserver.js b/src/web/webserver.js index 7bb36d99..f1540c55 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -32,13 +32,13 @@ function initializeLog(app) { function initPrometheus(app) { const latency = new Summary({ - name: 'cytube_http_req_latency', + name: 'cytube_http_req_duration_seconds', help: 'HTTP Request latency from execution of the first middleware ' + 'until the "finish" event on the response object.', labelNames: ['method', 'statusCode'] }); const requests = new Counter({ - name: 'cytube_http_req_count', + name: 'cytube_http_req_total', help: 'HTTP Request count', labelNames: ['method', 'statusCode'] }); @@ -48,8 +48,8 @@ function initPrometheus(app) { res.on('finish', () => { try { const diff = process.hrtime(startTime); - const diffMs = diff[0]*1e3 + diff[1]*1e-6; - latency.labels(req.method, res.statusCode).observe(diffMs); + const diffSec = diff[0] + diff[1]*1e-9; + latency.labels(req.method, res.statusCode).observe(diffSec); requests.labels(req.method, res.statusCode).inc(1, new Date()); } catch (error) { LOGGER.error('Failed to record HTTP Prometheus metrics: %s', error.stack);