@@ -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,13 @@ 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 ( statfs ) {
57
+ return ( ( statfs . blocks - statfs . bfree ) / statfs . blocks ) ?. toPrecision ( 2 ) ;
58
+ }
59
+
51
60
/**
52
61
* Start Noobaa metrics server for http and https server
53
62
*
@@ -68,6 +77,21 @@ async function start_server(
68
77
if ( ! config . PROMETHEUS_ENABLED ) {
69
78
return ;
70
79
}
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
+
71
95
const metrics_request_handler = async ( req , res ) => {
72
96
// Serve all metrics on the root path for system that do have one or more fork running.
73
97
if ( fork_enabled ) {
@@ -77,7 +101,8 @@ async function start_server(
77
101
const nsfs_report = {
78
102
nsfs_counters : io_stats_complete ,
79
103
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 ) ,
81
106
} ;
82
107
res . end ( JSON . stringify ( nsfs_report ) ) ;
83
108
return ;
@@ -209,7 +234,8 @@ async function metrics_nsfs_stats_handler() {
209
234
const nsfs_report = {
210
235
nsfs_counters : nsfs_io_stats ,
211
236
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 ) ,
213
239
} ;
214
240
dbg . log1 ( '_create_nsfs_report: nsfs_report' , nsfs_report ) ;
215
241
return JSON . stringify ( nsfs_report ) ;
0 commit comments