Windshaft-cartodb/lib/stats/reporter/renderer.js

49 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
// - Reports stats about:
// * Total number of renderers
// * For mapnik renderers:
// - the mapnik-pool status: count, unused and waiting
// - the internally cached objects: png and grid
2019-10-22 01:07:24 +08:00
function RendererStatsReporter (rendererCache, statsInterval) {
this.rendererCache = rendererCache;
this.statsInterval = statsInterval || 6e4;
this.renderersStatsIntervalId = null;
}
module.exports = RendererStatsReporter;
2019-10-22 01:07:24 +08:00
RendererStatsReporter.prototype.start = function () {
this.renderersStatsIntervalId = setInterval(() => {
const rendererStats = this.rendererCache.getStats();
2020-03-23 17:07:24 +08:00
for (const [stat, value] of rendererStats) {
2020-03-22 01:30:38 +08:00
if (stat.startsWith('rendercache')) {
global.statsClient.gauge(`windshaft.${stat}`, value);
} else {
global.statsClient.gauge(`windshaft.mapnik-${stat}`, value);
}
2019-10-22 01:07:24 +08:00
}
}, this.statsInterval);
this.rendererCache.on('err', rendererCacheErrorListener);
this.rendererCache.on('gc', gcTimingListener);
};
2019-10-22 01:07:24 +08:00
function rendererCacheErrorListener () {
global.statsClient.increment('windshaft.rendercache.error');
}
2019-10-22 01:07:24 +08:00
function gcTimingListener (gcTime) {
global.statsClient.timing('windshaft.rendercache.gc', gcTime);
}
2019-10-22 01:07:24 +08:00
RendererStatsReporter.prototype.stop = function () {
this.rendererCache.removeListener('err', rendererCacheErrorListener);
this.rendererCache.removeListener('gc', gcTimingListener);
clearInterval(this.renderersStatsIntervalId);
this.renderersStatsIntervalId = null;
};