diff --git a/CountItems/CountManager.js b/CountItems/CountManager.js index 3871dc89..7aab07d7 100644 --- a/CountItems/CountManager.js +++ b/CountItems/CountManager.js @@ -2,7 +2,7 @@ const async = require('async'); const { once } = require('arsenal').jsutil; const { validStorageMetricLevels } = require('./utils/constants'); const { consolidateDataMetrics } = require('./utils/utils'); -const monitoring = require('../utils/monitoring'); +const monitoring = require('../utils/monitoring').getManagerMetrics(); class CountManager { constructor(params) { diff --git a/CountItems/CountWorker.js b/CountItems/CountWorker.js index c56eb4b9..c13f1f32 100644 --- a/CountItems/CountWorker.js +++ b/CountItems/CountWorker.js @@ -1,7 +1,7 @@ const assert = require('assert'); const async = require('async'); const { BucketInfo } = require('arsenal').models; -const monitoring = require('../utils/monitoring'); +const monitoring = require('../utils/monitoring').getWorkerMetrics(); class CountWorker { constructor(params) { diff --git a/utils/monitoring.js b/utils/monitoring.js index fa33098d..7e532307 100644 --- a/utils/monitoring.js +++ b/utils/monitoring.js @@ -5,30 +5,38 @@ const { http } = require('httpagent'); const aggregatorRegistry = new promClient.AggregatorRegistry(); const { collectDefaultMetrics } = promClient; -// Histogram of the bucket processing duration, by the utilization service. -const bucketProcessingDuration = new promClient.Histogram({ - name: 's3_countitems_bucket_listing_duration_seconds', - help: 'Bucket processing duration', - buckets: [1, 10, 60, 600, 3600, 18000, 36000], -}); +function getManagerMetrics() { + // Histogram of the bucket processing duration, by the utilization service. + const bucketProcessingDuration = new promClient.Histogram({ + name: 's3_countitems_bucket_listing_duration_seconds', + help: 'Bucket processing duration', + buckets: [1, 10, 60, 600, 3600, 18000, 36000], + }); -const consolidationDuration = new promClient.Histogram({ - name: 's3_countitems_bucket_merge_duration_seconds', - help: 'Duration of metrics consolidation in seconds', - buckets: [0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10], -}); + const consolidationDuration = new promClient.Histogram({ + name: 's3_countitems_bucket_merge_duration_seconds', + help: 'Duration of metrics consolidation in seconds', + buckets: [0.01, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10], + }); -const bucketsCount = new promClient.Counter({ - name: 's3_countitems_total_buckets_count', - help: 'Total number of buckets processed', - labelNames: ['status'], -}); + return { bucketProcessingDuration, consolidationDuration }; +} + +function getWorkerMetrics() { + const bucketsCount = new promClient.Counter({ + name: 's3_countitems_total_buckets_count', + help: 'Total number of buckets processed', + labelNames: ['status'], + }); -const objectsCount = new promClient.Counter({ - name: 's3_countitems_total_objects_count', - help: 'Total number of objects processed', - labelNames: ['status'], -}); + const objectsCount = new promClient.Counter({ + name: 's3_countitems_total_objects_count', + help: 'Total number of objects processed', + labelNames: ['status'], + }); + + return { bucketsCount, objectsCount }; +} /** * @param {http.ServerResponse} res - http response object @@ -78,8 +86,6 @@ module.exports = { client: promClient, collectDefaultMetrics, metricsHandler, - bucketProcessingDuration, - consolidationDuration, - bucketsCount, - objectsCount, + getManagerMetrics, + getWorkerMetrics, };