@@ -13,6 +13,8 @@ const stats_aggregator = require('../system_services/stats_aggregator');
13
13
const AggregatorRegistry = require ( 'prom-client' ) . AggregatorRegistry ;
14
14
const aggregatorRegistry = new AggregatorRegistry ( ) ;
15
15
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' ) ;
16
18
17
19
// Currenty supported reprots
18
20
const reports = Object . seal ( {
@@ -48,6 +50,15 @@ async function export_all_metrics() {
48
50
return all_metrics . join ( '\n\n' ) ;
49
51
}
50
52
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
+
51
62
/**
52
63
* Start Noobaa metrics server for http and https server
53
64
*
@@ -68,6 +79,21 @@ async function start_server(
68
79
if ( ! config . PROMETHEUS_ENABLED ) {
69
80
return ;
70
81
}
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
+
71
97
const metrics_request_handler = async ( req , res ) => {
72
98
// Serve all metrics on the root path for system that do have one or more fork running.
73
99
if ( fork_enabled ) {
@@ -77,7 +103,8 @@ async function start_server(
77
103
const nsfs_report = {
78
104
nsfs_counters : io_stats_complete ,
79
105
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 ) ,
81
108
} ;
82
109
res . end ( JSON . stringify ( nsfs_report ) ) ;
83
110
return ;
@@ -209,7 +236,8 @@ async function metrics_nsfs_stats_handler() {
209
236
const nsfs_report = {
210
237
nsfs_counters : nsfs_io_stats ,
211
238
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 ) ,
213
241
} ;
214
242
dbg . log1 ( '_create_nsfs_report: nsfs_report' , nsfs_report ) ;
215
243
return JSON . stringify ( nsfs_report ) ;
0 commit comments