Skip to content

[NC | NSFS | GLACIER] Add disk usage info to nsfs metrics #9094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,11 @@ config.NSFS_GLACIER_FORCE_EXPIRE_ON_GET = false;
// interval
config.NSFS_GLACIER_MIGRATE_LOG_THRESHOLD = 50 * 1024;

// NSFS_GLACIER_METRICS_STAT_PATH if set NooBaa will start reporting the statfs info of that
// path as part of its metrics report
config.NSFS_GLACIER_METRICS_STATFS_PATH = '';
config.NSFS_GLACIER_METRICS_STATFS_INTERVAL = 60 * 1000; // Refresh statfs value every minute

/**
* NSFS_GLACIER_RESERVED_BUCKET_TAGS defines an object of bucket tags which will be reserved
* by the system and PUT operations for them via S3 API would be limited - as in they would be
Expand Down
32 changes: 30 additions & 2 deletions src/server/analytic_services/prometheus_reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const stats_aggregator = require('../system_services/stats_aggregator');
const AggregatorRegistry = require('prom-client').AggregatorRegistry;
const aggregatorRegistry = new AggregatorRegistry();
const http_utils = require('../../util/http_utils');
const nb_native = require('../../util/nb_native');
const { get_process_fs_context } = require('../../util/native_fs_utils');

// Currenty supported reprots
const reports = Object.seal({
Expand Down Expand Up @@ -48,6 +50,15 @@ async function export_all_metrics() {
return all_metrics.join('\n\n');
}

/** @type {Record<string, number>} */
let nsfs_metrics_statfs_path_cache = {};

function get_disk_usage_perc(statfs) {
if (!statfs || !statfs.blocks) return undefined;
const ratio = (statfs.blocks - statfs.bfree) / statfs.blocks;
return Number((ratio * 100)?.toPrecision(5));
}

/**
* Start Noobaa metrics server for http and https server
*
Expand All @@ -68,6 +79,21 @@ async function start_server(
if (!config.PROMETHEUS_ENABLED) {
return;
}

if (config.NSFS_GLACIER_METRICS_STATFS_PATH) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move the internal logic to a function?

setInterval(async () => {
try {
nsfs_metrics_statfs_path_cache = await nb_native().fs.statfs(
get_process_fs_context(),
config.NSFS_GLACIER_METRICS_STATFS_PATH
);
dbg.log4('updated \'nsfs_metrics_statfs_path_cache\' with', nsfs_metrics_statfs_path_cache);
} catch (error) {
dbg.warn('failed to updated \'nsfs_metrics_statfs_path_cache\':', error);
}
}, config.NSFS_GLACIER_METRICS_STATFS_INTERVAL).unref();
}

const metrics_request_handler = async (req, res) => {
// Serve all metrics on the root path for system that do have one or more fork running.
if (fork_enabled) {
Expand All @@ -77,7 +103,8 @@ async function start_server(
const nsfs_report = {
nsfs_counters: io_stats_complete,
op_stats_counters: ops_stats_complete,
fs_worker_stats_counters: fs_worker_stats_complete
fs_worker_stats_counters: fs_worker_stats_complete,
disk_usage: get_disk_usage_perc(nsfs_metrics_statfs_path_cache),
};
res.end(JSON.stringify(nsfs_report));
return;
Expand Down Expand Up @@ -209,7 +236,8 @@ async function metrics_nsfs_stats_handler() {
const nsfs_report = {
nsfs_counters: nsfs_io_stats,
op_stats_counters: op_stats_counters,
fs_worker_stats_counters: fs_worker_stats_counters
fs_worker_stats_counters: fs_worker_stats_counters,
disk_usage: get_disk_usage_perc(nsfs_metrics_statfs_path_cache),
};
dbg.log1('_create_nsfs_report: nsfs_report', nsfs_report);
return JSON.stringify(nsfs_report);
Expand Down