Add metric for yt cached result age

This commit is contained in:
Calvin Montgomery 2020-03-20 19:52:36 -07:00
parent 83fd8f11b2
commit 47bb3e47a2
2 changed files with 17 additions and 1 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.69.0",
"version": "3.70.0",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -1,6 +1,8 @@
import { Summary } from 'prom-client';
import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update';
const Media = require('cytube-mediaquery/lib/media');
const LOGGER = require('@calzoneman/jsli')('metadata-cache');
// TODO: these fullname-vs-shortcode hacks really need to be abolished
function mediaquery2cytube(type) {
@ -21,6 +23,11 @@ function cytube2mediaquery(type) {
}
}
const cachedResultAge = new Summary({
name: 'cytube_yt_cache_result_age_seconds',
help: 'Age (in seconds) of cached record'
});
class MetadataCacheDB {
constructor(db) {
this.db = db;
@ -55,6 +62,15 @@ class MetadataCacheDB {
return null;
}
try {
let age = (Date.now() - row.updated_at.getTime())/1000;
if (age > 0) {
cachedResultAge.observe(age);
}
} catch (error) {
LOGGER.error('Failed to record cachedResultAge metric: %s', error.stack);
}
let metadata = JSON.parse(row.metadata);
metadata.type = cytube2mediaquery(metadata.type);
return new Media(metadata);