From 1c3dbb30634a31e14b7566d58f4dfd469c5fdeda Mon Sep 17 00:00:00 2001 From: Jenia White Date: Thu, 18 Jul 2019 18:11:23 +0300 Subject: [PATCH] Addition of metrics for OCS links --- src/api/stats_api.js | 15 ++++++++++++++- .../analytic_services/prometheus_reporting.js | 4 ++-- src/server/system_services/stats_aggregator.js | 13 ++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/api/stats_api.js b/src/api/stats_api.js index 8847236de4..fc9d2ceca1 100644 --- a/src/api/stats_api.js +++ b/src/api/stats_api.js @@ -522,11 +522,24 @@ module.exports = { type: 'array', items: { type: 'object', - required: ['name', 'capacity', 'reduction_ratio', 'savings', 'total_usage', 'buckets_stats', 'usage_by_project', 'usage_by_bucket_class'], + required: [ + 'name', + 'address', + 'capacity', + 'reduction_ratio', + 'savings', + 'total_usage', + 'buckets_stats', + 'usage_by_project', + 'usage_by_bucket_class', + ], properties: { name: { type: 'string' }, + address: { + type: 'string' + }, capacity: { type: 'number' }, diff --git a/src/server/analytic_services/prometheus_reporting.js b/src/server/analytic_services/prometheus_reporting.js index 7d1cdc1c0a..9efd2fe7b7 100644 --- a/src/server/analytic_services/prometheus_reporting.js +++ b/src/server/analytic_services/prometheus_reporting.js @@ -95,7 +95,7 @@ const METRIC_RECORDS = Object.freeze([{ configuration: { name: get_metric_name('system_info'), help: 'System info', - labelNames: ['system_name'] + labelNames: ['system_name', 'system_address'] } }, { metric_type: 'Gauge', @@ -342,7 +342,7 @@ class PrometheusReporting { set_system_info(info) { if (!this.enabled()) return; - this._metrics.system_info.set({ system_name: info.name }, 0); + this._metrics.system_info.set({ system_name: info.name, system_address: info.address }, 0); } update_providers_bandwidth(type, write_size, read_size) { diff --git a/src/server/system_services/stats_aggregator.js b/src/server/system_services/stats_aggregator.js index 77c6ea661d..d01d16ada5 100644 --- a/src/server/system_services/stats_aggregator.js +++ b/src/server/system_services/stats_aggregator.js @@ -31,6 +31,7 @@ const prom_report = require('../analytic_services/prometheus_reporting').Prometh const HistoryDataStore = require('../analytic_services/history_data_store').HistoryDataStore; const { google } = require('googleapis'); const google_storage = google.storage('v1'); +const addr_utils = require('../../util/addr_utils'); const ops_aggregation = {}; @@ -146,6 +147,7 @@ const PARTIAL_SINGLE_ACCOUNT_DEFAULTS = { const PARTIAL_SINGLE_SYS_DEFAULTS = { name: '', + address: '', capacity: 0, reduction_ratio: 0, savings: { @@ -370,8 +372,16 @@ async function get_partial_systems_stats(req) { const total_usage = size_utils.bigint_to_bytes(storage.used); const capacity = 100 - Math.floor(((free_bytes / total_bytes) || 1) * 100); + const { system_address } = system; + const https_port = process.env.SSL_PORT || 5443; + const address = DEV_MODE ? `https://localhost:${https_port}` : addr_utils.get_base_address(system_address, { + hint: 'EXTERNAL', + protocol: 'https' + }).toString(); + return _.defaults({ name: system.name, + address, capacity, reduction_ratio, savings, @@ -832,6 +842,7 @@ function partial_cycle_parse_prometheus_metrics(payload) { reduction_ratio, savings, name, + address, usage_by_bucket_class, usage_by_project, total_usage, @@ -851,7 +862,7 @@ function partial_cycle_parse_prometheus_metrics(payload) { prom_report.instance().set_num_unhealthy_pools(unhealthy_pool_count); prom_report.instance().set_num_pools(pool_count); prom_report.instance().set_unhealthy_cloud_types(cloud_pool_stats); - prom_report.instance().set_system_info({ name }); + prom_report.instance().set_system_info({ name, address }); prom_report.instance().set_num_buckets(buckets); prom_report.instance().set_num_objects(objects_in_buckets); prom_report.instance().set_num_unhealthy_buckets(unhealthy_buckets);