Skip to content

Commit e305c57

Browse files
committed
Add disk usage info to nsfs metrics
Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com> missed committing config.js Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
1 parent c247ca1 commit e305c57

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,11 @@ config.NSFS_GLACIER_FORCE_EXPIRE_ON_GET = false;
954954
// interval
955955
config.NSFS_GLACIER_MIGRATE_LOG_THRESHOLD = 50 * 1024;
956956

957+
// NSFS_GLACIER_METRICS_STAT_PATH if set NooBaa will start reporting the statfs info of that
958+
// path as part of its metrics report
959+
config.NSFS_GLACIER_METRICS_STATFS_PATH = '';
960+
config.NSFS_GLACIER_METRICS_STATFS_INTERVAL = 60 * 1000; // Refresh statfs value every minute
961+
957962
/**
958963
* NSFS_GLACIER_RESERVED_BUCKET_TAGS defines an object of bucket tags which will be reserved
959964
* by the system and PUT operations for them via S3 API would be limited - as in they would be

src/server/analytic_services/prometheus_reporting.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const stats_aggregator = require('../system_services/stats_aggregator');
1313
const AggregatorRegistry = require('prom-client').AggregatorRegistry;
1414
const aggregatorRegistry = new AggregatorRegistry();
1515
const http_utils = require('../../util/http_utils');
16+
const nb_native = require('../../util/nb_native');
17+
const { get_process_fs_context } = require('../../util/native_fs_utils');
1618

1719
// Currenty supported reprots
1820
const reports = Object.seal({
@@ -48,6 +50,13 @@ async function export_all_metrics() {
4850
return all_metrics.join('\n\n');
4951
}
5052

53+
/** @type {Record<string, number>} */
54+
let nsfs_metrics_statfs_path_cache = {};
55+
56+
function get_disk_usage(statfs) {
57+
return ((statfs.blocks - statfs.bfree) / statfs.blocks)?.toPrecision(2);
58+
}
59+
5160
/**
5261
* Start Noobaa metrics server for http and https server
5362
*
@@ -68,6 +77,21 @@ async function start_server(
6877
if (!config.PROMETHEUS_ENABLED) {
6978
return;
7079
}
80+
81+
if (config.NSFS_GLACIER_METRICS_STATFS_PATH) {
82+
setInterval(async () => {
83+
try {
84+
nsfs_metrics_statfs_path_cache = await nb_native().fs.statfs(
85+
get_process_fs_context(),
86+
config.NSFS_GLACIER_METRICS_STATFS_PATH
87+
);
88+
dbg.log4('updated \'nsfs_metrics_statfs_path_cache\' with', nsfs_metrics_statfs_path_cache);
89+
} catch (error) {
90+
dbg.warn('failed to updated \'nsfs_metrics_statfs_path_cache\':', error);
91+
}
92+
}, config.NSFS_GLACIER_METRICS_STATFS_INTERVAL).unref();
93+
}
94+
7195
const metrics_request_handler = async (req, res) => {
7296
// Serve all metrics on the root path for system that do have one or more fork running.
7397
if (fork_enabled) {
@@ -77,7 +101,8 @@ async function start_server(
77101
const nsfs_report = {
78102
nsfs_counters: io_stats_complete,
79103
op_stats_counters: ops_stats_complete,
80-
fs_worker_stats_counters: fs_worker_stats_complete
104+
fs_worker_stats_counters: fs_worker_stats_complete,
105+
disk_usage: get_disk_usage(nsfs_metrics_statfs_path_cache),
81106
};
82107
res.end(JSON.stringify(nsfs_report));
83108
return;
@@ -209,7 +234,8 @@ async function metrics_nsfs_stats_handler() {
209234
const nsfs_report = {
210235
nsfs_counters: nsfs_io_stats,
211236
op_stats_counters: op_stats_counters,
212-
fs_worker_stats_counters: fs_worker_stats_counters
237+
fs_worker_stats_counters: fs_worker_stats_counters,
238+
disk_usage: get_disk_usage(nsfs_metrics_statfs_path_cache),
213239
};
214240
dbg.log1('_create_nsfs_report: nsfs_report', nsfs_report);
215241
return JSON.stringify(nsfs_report);

0 commit comments

Comments
 (0)