Add named map providers reporter to gather some stats

This commit is contained in:
Daniel García Aubert
2019-09-13 20:01:03 +02:00
parent 788cd9d6fb
commit c19c723795
3 changed files with 102 additions and 0 deletions
+8
View File
@@ -29,6 +29,7 @@ const VarnishHttpCacheBackend = require('../cache/backend/varnish_http');
const FastlyCacheBackend = require('../cache/backend/fastly');
const NamedMapProviderCache = require('../cache/named_map_provider_cache');
const NamedMapsCacheEntry = require('../cache/model/named_maps_entry');
const NamedMapProviderReporter = require('../stats/reporter/named-map-provider');
const SqlWrapMapConfigAdapter = require('../models/mapconfig/adapter/sql-wrap-mapconfig-adapter');
const MapConfigNamedLayersAdapter = require('../models/mapconfig/adapter/mapconfig-named-layers-adapter');
@@ -161,6 +162,13 @@ module.exports = class ApiRouter {
layergroupAffectedTablesCache
);
const namedMapProviderReporter = new NamedMapProviderReporter({
namedMapProviderCache,
intervalInMilliseconds: rendererCacheOpts.statsInterval
});
namedMapProviderReporter.start();
const collaborators = {
analysisStatusBackend,
attributesBackend,
@@ -0,0 +1,33 @@
'use strict';
const statKeyTemplate = ctx => `windshaft.named-map-provider-cache.${ctx.metric}`;
module.exports = class NamedMapProviderReporter {
constructor ({ namedMapProviderCache, intervalInMilliseconds } = {}) {
this.namedMapProviderCache = namedMapProviderCache;
this.intervalInMilliseconds = intervalInMilliseconds;
this.intervalId = null;
}
start () {
const { providerCache: cache } = this.namedMapProviderCache;
const { statsClient: stats } = global;
this.intervalId = setInterval(() => {
stats.gauge(statKeyTemplate({ metric: 'named-map.count' }), cache.length);
const providers = cache.dump();
const namedMapIntantiations = providers.reduce((acc, { v: providers }) => {
acc += Object.keys(providers).length;
return acc;
}, 0);
stats.gauge(statKeyTemplate({ metric: 'named-map.intantiation.count' }), namedMapIntantiations);
}, this.intervalInMilliseconds);
}
stop () {
clearInterval(this.intervalId);
this.intervalId = null;
}
};