mirror of https://github.com/calzoneman/sync.git
Add metric for yt cached result age
This commit is contained in:
parent
83fd8f11b2
commit
47bb3e47a2
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.69.0",
|
"version": "3.70.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import { Summary } from 'prom-client';
|
||||||
import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update';
|
import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update';
|
||||||
|
|
||||||
const Media = require('cytube-mediaquery/lib/media');
|
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
|
// TODO: these fullname-vs-shortcode hacks really need to be abolished
|
||||||
function mediaquery2cytube(type) {
|
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 {
|
class MetadataCacheDB {
|
||||||
constructor(db) {
|
constructor(db) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
|
@ -55,6 +62,15 @@ class MetadataCacheDB {
|
||||||
return null;
|
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);
|
let metadata = JSON.parse(row.metadata);
|
||||||
metadata.type = cytube2mediaquery(metadata.type);
|
metadata.type = cytube2mediaquery(metadata.type);
|
||||||
return new Media(metadata);
|
return new Media(metadata);
|
||||||
|
|
Loading…
Reference in New Issue