@@ -205,6 +205,34 @@ private void registerJobs(UsageComputation uc) throws IOException, InterruptedEx
205
205
}
206
206
}
207
207
208
+ private File getJenkinsBaseDirectory () throws NullPointerException {
209
+ // finds the lowest non-null value of parent.
210
+ // for example, would return "/" for "/var/jenkins_home"
211
+ Jenkins jenkins = Jenkins .get ();
212
+ Path basePath = jenkins .getRootDir ().toPath ();
213
+ try {
214
+ while (basePath .getParent () != null ) {
215
+ basePath = basePath .getParent ();
216
+ }
217
+ }
218
+ catch (NullPointerException e ){
219
+ logger .log (Level .WARNING , "cloudbees-disk-usage-plugin: Could not find Jenkins Base Directory" );
220
+ }
221
+ return basePath .toFile ();
222
+ }
223
+
224
+ private void registerDirectoriesFS (UsageComputation uc ) throws IOException , InterruptedException {
225
+ Map <File , String > directoriesToProcess = new HashMap <>();
226
+ // Display JENKINS_FS size
227
+ File rootPath = getJenkinsBaseDirectory ();
228
+ directoriesToProcess .put (rootPath , "JENKINS_FS" );
229
+
230
+ // Add or update entries for directories
231
+ for (Map .Entry <File , String > item : directoriesToProcess .entrySet ()) {
232
+ uc .addListener (item .getKey ().toPath (), new DirectoryUsageListener (item .getValue ()));
233
+ }
234
+ }
235
+
208
236
private void registerDirectories (UsageComputation uc ) throws IOException , InterruptedException {
209
237
Jenkins jenkins = Jenkins .get ();
210
238
Map <File , String > directoriesToProcess = new HashMap <>();
@@ -256,7 +284,17 @@ public void run() {
256
284
registerDirectories (uc );
257
285
total .set (uc .getItemsCount ());
258
286
uc .compute ();
287
+
288
+ // Adds JENKINS_FS section with relevant disk usage info
289
+ File rootPath = getJenkinsBaseDirectory ();
290
+ UsageComputation ucfs = new UsageComputation (Arrays .asList (rootPath .toPath ()));
291
+ registerJobs (ucfs );
292
+ registerDirectoriesFS (ucfs );
293
+ total .set (ucfs .getItemsCount ());
294
+ ucfs .computeFS ();
295
+
259
296
logger .fine ("Finished re-estimating disk usage." );
297
+
260
298
lastRunEnd = System .currentTimeMillis ();
261
299
} catch (IOException | InterruptedException e ) {
262
300
logger .log (Level .WARNING , "Unable to run disk usage check" , e );
0 commit comments