Change metric names to follow prometheus naming guide

This commit is contained in:
Calvin Montgomery 2017-08-12 13:12:58 -07:00
parent 92f0a956b9
commit d0c1e8cbd9
7 changed files with 22 additions and 22 deletions

View File

@ -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"
},

View File

@ -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) {

View File

@ -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);

View File

@ -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());
});
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);