Add named map providers reporter to gather some stats
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user