Skip to content

Commit 207cf6d

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> fix stupid coderrabit AI suggestion Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com> change ratio to percentage Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
1 parent c247ca1 commit 207cf6d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-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: 30 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,15 @@ 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_perc(statfs) {
57+
if (!statfs || !statfs.blocks) return undefined;
58+
const ratio = (statfs.blocks - statfs.bfree) / statfs.blocks;
59+
return Number((ratio * 100)?.toPrecision(5));
60+
}
61+
5162
/**
5263
* Start Noobaa metrics server for http and https server
5364
*
@@ -68,6 +79,21 @@ async function start_server(
6879
if (!config.PROMETHEUS_ENABLED) {
6980
return;
7081
}
82+
83+
if (config.NSFS_GLACIER_METRICS_STATFS_PATH) {
84+
setInterval(async () => {
85+
try {
86+
nsfs_metrics_statfs_path_cache = await nb_native().fs.statfs(
87+
get_process_fs_context(),
88+
config.NSFS_GLACIER_METRICS_STATFS_PATH
89+
);
90+
dbg.log4('updated \'nsfs_metrics_statfs_path_cache\' with', nsfs_metrics_statfs_path_cache);
91+
} catch (error) {
92+
dbg.warn('failed to updated \'nsfs_metrics_statfs_path_cache\':', error);
93+
}
94+
}, config.NSFS_GLACIER_METRICS_STATFS_INTERVAL).unref();
95+
}
96+
7197
const metrics_request_handler = async (req, res) => {
7298
// Serve all metrics on the root path for system that do have one or more fork running.
7399
if (fork_enabled) {
@@ -77,7 +103,8 @@ async function start_server(
77103
const nsfs_report = {
78104
nsfs_counters: io_stats_complete,
79105
op_stats_counters: ops_stats_complete,
80-
fs_worker_stats_counters: fs_worker_stats_complete
106+
fs_worker_stats_counters: fs_worker_stats_complete,
107+
disk_usage: get_disk_usage_perc(nsfs_metrics_statfs_path_cache),
81108
};
82109
res.end(JSON.stringify(nsfs_report));
83110
return;
@@ -209,7 +236,8 @@ async function metrics_nsfs_stats_handler() {
209236
const nsfs_report = {
210237
nsfs_counters: nsfs_io_stats,
211238
op_stats_counters: op_stats_counters,
212-
fs_worker_stats_counters: fs_worker_stats_counters
239+
fs_worker_stats_counters: fs_worker_stats_counters,
240+
disk_usage: get_disk_usage_perc(nsfs_metrics_statfs_path_cache),
213241
};
214242
dbg.log1('_create_nsfs_report: nsfs_report', nsfs_report);
215243
return JSON.stringify(nsfs_report);

0 commit comments

Comments
 (0)