@@ -303,17 +303,22 @@ public static class OsStats implements ToXContent, Streamable {
303
303
304
304
int availableProcessors ;
305
305
long availableMemory ;
306
- ObjectIntHashMap <OsInfo .Cpu > cpus ;
306
+ final ObjectIntHashMap <String > names ;
307
+ final ObjectIntHashMap <OsInfo .Cpu > cpus ;
307
308
308
309
public OsStats () {
309
310
cpus = new ObjectIntHashMap <>();
311
+ names = new ObjectIntHashMap <>();
310
312
}
311
313
312
314
public void addNodeInfo (NodeInfo nodeInfo ) {
313
315
availableProcessors += nodeInfo .getOs ().availableProcessors ();
314
316
if (nodeInfo .getOs () == null ) {
315
317
return ;
316
318
}
319
+ if (nodeInfo .getOs ().getName () != null ) {
320
+ names .addTo (nodeInfo .getOs ().getName (), 1 );
321
+ }
317
322
if (nodeInfo .getOs ().cpu () != null ) {
318
323
cpus .addTo (nodeInfo .getOs ().cpu (), 1 );
319
324
}
@@ -339,8 +344,13 @@ public void readFrom(StreamInput in) throws IOException {
339
344
availableProcessors = in .readVInt ();
340
345
availableMemory = in .readLong ();
341
346
int size = in .readVInt ();
342
- cpus = new ObjectIntHashMap <>(size );
343
- for (; size > 0 ; size --) {
347
+ names .clear ();
348
+ for (int i = 0 ; i < size ; i ++) {
349
+ names .addTo (in .readString (), in .readVInt ());
350
+ }
351
+ size = in .readVInt ();
352
+ cpus .clear ();
353
+ for (int i = 0 ; i < size ; i ++) {
344
354
cpus .addTo (OsInfo .Cpu .readCpu (in ), in .readVInt ());
345
355
}
346
356
}
@@ -349,12 +359,16 @@ public void readFrom(StreamInput in) throws IOException {
349
359
public void writeTo (StreamOutput out ) throws IOException {
350
360
out .writeVInt (availableProcessors );
351
361
out .writeLong (availableMemory );
362
+ out .writeVInt (names .size ());
363
+ for (ObjectIntCursor <String > name : names ) {
364
+ out .writeString (name .key );
365
+ out .writeVInt (name .value );
366
+ }
352
367
out .writeVInt (cpus .size ());
353
368
for (ObjectIntCursor <OsInfo .Cpu > c : cpus ) {
354
369
c .key .writeTo (out );
355
370
out .writeVInt (c .value );
356
371
}
357
-
358
372
}
359
373
360
374
public static OsStats readOsStats (StreamInput in ) throws IOException {
@@ -365,6 +379,8 @@ public static OsStats readOsStats(StreamInput in) throws IOException {
365
379
366
380
static final class Fields {
367
381
static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString ("available_processors" );
382
+ static final XContentBuilderString NAME = new XContentBuilderString ("name" );
383
+ static final XContentBuilderString NAMES = new XContentBuilderString ("names" );
368
384
static final XContentBuilderString MEM = new XContentBuilderString ("mem" );
369
385
static final XContentBuilderString TOTAL = new XContentBuilderString ("total" );
370
386
static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString ("total_in_bytes" );
@@ -379,6 +395,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
379
395
builder .byteSizeField (Fields .TOTAL_IN_BYTES , Fields .TOTAL , availableMemory );
380
396
builder .endObject ();
381
397
398
+ builder .startArray (Fields .NAMES );
399
+ for (ObjectIntCursor <String > name : names ) {
400
+ builder .startObject ();
401
+ builder .field (Fields .NAME , name .key );
402
+ builder .field (Fields .COUNT , name .value );
403
+ builder .endObject ();
404
+ }
405
+ builder .endArray ();
406
+
382
407
builder .startArray (Fields .CPU );
383
408
for (ObjectIntCursor <OsInfo .Cpu > cpu : cpus ) {
384
409
builder .startObject ();
0 commit comments