Skip to content

Commit b58fed7

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 b58fed7

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-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: 31 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,16 @@ 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+
if (!statfs || !statfs.blocks) return undefined;
58+
if (statfs.blocks === 0) return undefined;
59+
const ratio = (statfs.blocks - statfs.bfree) / statfs.blocks;
60+
return Number(ratio?.toPrecision(2));
61+
}
62+
5163
/**
5264
* Start Noobaa metrics server for http and https server
5365
*
@@ -68,6 +80,21 @@ async function start_server(
6880
if (!config.PROMETHEUS_ENABLED) {
6981
return;
7082
}
83+
84+
if (config.NSFS_GLACIER_METRICS_STATFS_PATH) {
85+
setInterval(async () => {
86+
try {
87+
nsfs_metrics_statfs_path_cache = await nb_native().fs.statfs(
88+
get_process_fs_context(),
89+
config.NSFS_GLACIER_METRICS_STATFS_PATH
90+
);
91+
dbg.log4('updated \'nsfs_metrics_statfs_path_cache\' with', nsfs_metrics_statfs_path_cache);
92+
} catch (error) {
93+
dbg.warn('failed to updated \'nsfs_metrics_statfs_path_cache\':', error);
94+
}
95+
}, config.NSFS_GLACIER_METRICS_STATFS_INTERVAL).unref();
96+
}
97+
7198
const metrics_request_handler = async (req, res) => {
7299
// Serve all metrics on the root path for system that do have one or more fork running.
73100
if (fork_enabled) {
@@ -77,7 +104,8 @@ async function start_server(
77104
const nsfs_report = {
78105
nsfs_counters: io_stats_complete,
79106
op_stats_counters: ops_stats_complete,
80-
fs_worker_stats_counters: fs_worker_stats_complete
107+
fs_worker_stats_counters: fs_worker_stats_complete,
108+
disk_usage: get_disk_usage(nsfs_metrics_statfs_path_cache),
81109
};
82110
res.end(JSON.stringify(nsfs_report));
83111
return;
@@ -209,7 +237,8 @@ async function metrics_nsfs_stats_handler() {
209237
const nsfs_report = {
210238
nsfs_counters: nsfs_io_stats,
211239
op_stats_counters: op_stats_counters,
212-
fs_worker_stats_counters: fs_worker_stats_counters
240+
fs_worker_stats_counters: fs_worker_stats_counters,
241+
disk_usage: get_disk_usage(nsfs_metrics_statfs_path_cache),
213242
};
214243
dbg.log1('_create_nsfs_report: nsfs_report', nsfs_report);
215244
return JSON.stringify(nsfs_report);

0 commit comments

Comments
 (0)