@@ -397,6 +397,8 @@ public static class ProcessStats implements ToXContent, Streamable {
397
397
int count ;
398
398
int cpuPercent ;
399
399
long totalOpenFileDescriptors ;
400
+ long minOpenFileDescriptors = Integer .MAX_VALUE ;
401
+ long maxOpenFileDescriptors = Integer .MIN_VALUE ;
400
402
401
403
public void addNodeStats (NodeStats nodeStats ) {
402
404
if (nodeStats .getProcess () == null ) {
@@ -407,7 +409,10 @@ public void addNodeStats(NodeStats nodeStats) {
407
409
// with no sigar, this may not be available
408
410
cpuPercent += nodeStats .getProcess ().cpu ().getPercent ();
409
411
}
410
- totalOpenFileDescriptors += nodeStats .getProcess ().openFileDescriptors ();
412
+ long fd = nodeStats .getProcess ().openFileDescriptors ();
413
+ totalOpenFileDescriptors += fd ;
414
+ minOpenFileDescriptors = Math .min (minOpenFileDescriptors , fd );
415
+ maxOpenFileDescriptors = Math .max (maxOpenFileDescriptors , fd );
411
416
}
412
417
413
418
/**
@@ -424,6 +429,20 @@ public long getAvgOpenFileDescriptors() {
424
429
return totalOpenFileDescriptors / count ;
425
430
}
426
431
432
+ public long getMaxOpenFileDescriptors () {
433
+ if (count == 0 ) {
434
+ return -1 ;
435
+ }
436
+ return maxOpenFileDescriptors ;
437
+ }
438
+
439
+ public long getMinOpenFileDescriptors () {
440
+ if (count == 0 ) {
441
+ return -1 ;
442
+ }
443
+ return minOpenFileDescriptors ;
444
+ }
445
+
427
446
@ Override
428
447
public void readFrom (StreamInput in ) throws IOException {
429
448
count = in .readVInt ();
@@ -447,13 +466,22 @@ public static ProcessStats readStats(StreamInput in) throws IOException {
447
466
static final class Fields {
448
467
static final XContentBuilderString CPU = new XContentBuilderString ("cpu" );
449
468
static final XContentBuilderString PERCENT = new XContentBuilderString ("percent" );
450
- static final XContentBuilderString AVG_OPEN_FD = new XContentBuilderString ("avg_open_file_descriptors" );
469
+ static final XContentBuilderString OPEN_FILE_DESCRIPTORS = new XContentBuilderString ("open_file_descriptors" );
470
+ static final XContentBuilderString MIN = new XContentBuilderString ("min" );
471
+ static final XContentBuilderString MAX = new XContentBuilderString ("max" );
472
+ static final XContentBuilderString AVG = new XContentBuilderString ("avg" );
451
473
}
452
474
453
475
@ Override
454
476
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
455
477
builder .startObject (Fields .CPU ).field (Fields .PERCENT , cpuPercent ).endObject ();
456
- builder .field (Fields .AVG_OPEN_FD , getAvgOpenFileDescriptors ());
478
+ if (count > 0 ) {
479
+ builder .startObject (Fields .OPEN_FILE_DESCRIPTORS );
480
+ builder .field (Fields .MIN , getMinOpenFileDescriptors ());
481
+ builder .field (Fields .MAX , getMaxOpenFileDescriptors ());
482
+ builder .field (Fields .AVG , getAvgOpenFileDescriptors ());
483
+ builder .endObject ();
484
+ }
457
485
return builder ;
458
486
}
459
487
}
0 commit comments