8
8
9
9
package org .elasticsearch .monitor .fs ;
10
10
11
+ import org .elasticsearch .Version ;
11
12
import org .elasticsearch .common .Nullable ;
12
13
import org .elasticsearch .common .io .stream .StreamInput ;
13
14
import org .elasticsearch .common .io .stream .StreamOutput ;
@@ -166,6 +167,8 @@ public static class DeviceStats implements Writeable, ToXContentFragment {
166
167
final long previousWritesCompleted ;
167
168
final long currentSectorsWritten ;
168
169
final long previousSectorsWritten ;
170
+ final long currentIOTime ;
171
+ final long previousIOTime ;
169
172
170
173
public DeviceStats (
171
174
final int majorDeviceNumber ,
@@ -175,6 +178,7 @@ public DeviceStats(
175
178
final long currentSectorsRead ,
176
179
final long currentWritesCompleted ,
177
180
final long currentSectorsWritten ,
181
+ final long currentIOTime ,
178
182
final DeviceStats previousDeviceStats ) {
179
183
this (
180
184
majorDeviceNumber ,
@@ -187,7 +191,9 @@ public DeviceStats(
187
191
currentSectorsRead ,
188
192
previousDeviceStats != null ? previousDeviceStats .currentSectorsRead : -1 ,
189
193
currentWritesCompleted ,
190
- previousDeviceStats != null ? previousDeviceStats .currentWritesCompleted : -1 );
194
+ previousDeviceStats != null ? previousDeviceStats .currentWritesCompleted : -1 ,
195
+ currentIOTime ,
196
+ previousDeviceStats != null ? previousDeviceStats .currentIOTime : -1 );
191
197
}
192
198
193
199
private DeviceStats (
@@ -201,7 +207,9 @@ private DeviceStats(
201
207
final long currentSectorsRead ,
202
208
final long previousSectorsRead ,
203
209
final long currentWritesCompleted ,
204
- final long previousWritesCompleted ) {
210
+ final long previousWritesCompleted ,
211
+ final long currentIOTime ,
212
+ final long previousIOTime ) {
205
213
this .majorDeviceNumber = majorDeviceNumber ;
206
214
this .minorDeviceNumber = minorDeviceNumber ;
207
215
this .deviceName = deviceName ;
@@ -213,6 +221,8 @@ private DeviceStats(
213
221
this .previousSectorsRead = previousSectorsRead ;
214
222
this .currentSectorsWritten = currentSectorsWritten ;
215
223
this .previousSectorsWritten = previousSectorsWritten ;
224
+ this .currentIOTime = currentIOTime ;
225
+ this .previousIOTime = previousIOTime ;
216
226
}
217
227
218
228
public DeviceStats (StreamInput in ) throws IOException {
@@ -227,6 +237,13 @@ public DeviceStats(StreamInput in) throws IOException {
227
237
previousSectorsRead = in .readLong ();
228
238
currentSectorsWritten = in .readLong ();
229
239
previousSectorsWritten = in .readLong ();
240
+ if (in .getVersion ().onOrAfter (Version .V_8_0_0 )) {
241
+ currentIOTime = in .readLong ();
242
+ previousIOTime = in .readLong ();
243
+ } else {
244
+ currentIOTime = 0 ;
245
+ previousIOTime = 0 ;
246
+ }
230
247
}
231
248
232
249
@ Override
@@ -242,6 +259,10 @@ public void writeTo(StreamOutput out) throws IOException {
242
259
out .writeLong (previousSectorsRead );
243
260
out .writeLong (currentSectorsWritten );
244
261
out .writeLong (previousSectorsWritten );
262
+ if (out .getVersion ().onOrAfter (Version .V_8_0_0 )) {
263
+ out .writeLong (currentIOTime );
264
+ out .writeLong (previousIOTime );
265
+ }
245
266
}
246
267
247
268
public long operations () {
@@ -275,6 +296,12 @@ public long writeKilobytes() {
275
296
return (currentSectorsWritten - previousSectorsWritten ) / 2 ;
276
297
}
277
298
299
+ public long ioTimeInMillis () {
300
+ if (previousIOTime == -1 ) return -1 ;
301
+
302
+ return (currentIOTime - previousIOTime );
303
+ }
304
+
278
305
@ Override
279
306
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
280
307
builder .field ("device_name" , deviceName );
@@ -283,6 +310,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
283
310
builder .field (IoStats .WRITE_OPERATIONS , writeOperations ());
284
311
builder .field (IoStats .READ_KILOBYTES , readKilobytes ());
285
312
builder .field (IoStats .WRITE_KILOBYTES , writeKilobytes ());
313
+ builder .field (IoStats .IO_TIMEMS , ioTimeInMillis ());
286
314
return builder ;
287
315
}
288
316
@@ -295,13 +323,16 @@ public static class IoStats implements Writeable, ToXContentFragment {
295
323
private static final String WRITE_OPERATIONS = "write_operations" ;
296
324
private static final String READ_KILOBYTES = "read_kilobytes" ;
297
325
private static final String WRITE_KILOBYTES = "write_kilobytes" ;
326
+ private static final String IO_TIMEMS = "io_time_in_millis" ;
327
+
298
328
299
329
final DeviceStats [] devicesStats ;
300
330
final long totalOperations ;
301
331
final long totalReadOperations ;
302
332
final long totalWriteOperations ;
303
333
final long totalReadKilobytes ;
304
334
final long totalWriteKilobytes ;
335
+ final long totalIOTimeInMillis ;
305
336
306
337
public IoStats (final DeviceStats [] devicesStats ) {
307
338
this .devicesStats = devicesStats ;
@@ -310,18 +341,21 @@ public IoStats(final DeviceStats[] devicesStats) {
310
341
long totalWriteOperations = 0 ;
311
342
long totalReadKilobytes = 0 ;
312
343
long totalWriteKilobytes = 0 ;
344
+ long totalIOTimeInMillis = 0 ;
313
345
for (DeviceStats deviceStats : devicesStats ) {
314
346
totalOperations += deviceStats .operations () != -1 ? deviceStats .operations () : 0 ;
315
347
totalReadOperations += deviceStats .readOperations () != -1 ? deviceStats .readOperations () : 0 ;
316
348
totalWriteOperations += deviceStats .writeOperations () != -1 ? deviceStats .writeOperations () : 0 ;
317
349
totalReadKilobytes += deviceStats .readKilobytes () != -1 ? deviceStats .readKilobytes () : 0 ;
318
350
totalWriteKilobytes += deviceStats .writeKilobytes () != -1 ? deviceStats .writeKilobytes () : 0 ;
351
+ totalIOTimeInMillis += deviceStats .ioTimeInMillis () != -1 ? deviceStats .ioTimeInMillis () : 0 ;
319
352
}
320
353
this .totalOperations = totalOperations ;
321
354
this .totalReadOperations = totalReadOperations ;
322
355
this .totalWriteOperations = totalWriteOperations ;
323
356
this .totalReadKilobytes = totalReadKilobytes ;
324
357
this .totalWriteKilobytes = totalWriteKilobytes ;
358
+ this .totalIOTimeInMillis = totalIOTimeInMillis ;
325
359
}
326
360
327
361
public IoStats (StreamInput in ) throws IOException {
@@ -336,6 +370,11 @@ public IoStats(StreamInput in) throws IOException {
336
370
this .totalWriteOperations = in .readLong ();
337
371
this .totalReadKilobytes = in .readLong ();
338
372
this .totalWriteKilobytes = in .readLong ();
373
+ if (in .getVersion ().onOrAfter (Version .V_8_0_0 )) {
374
+ this .totalIOTimeInMillis = in .readLong ();
375
+ } else {
376
+ this .totalIOTimeInMillis = 0 ;
377
+ }
339
378
}
340
379
341
380
@ Override
@@ -349,6 +388,9 @@ public void writeTo(StreamOutput out) throws IOException {
349
388
out .writeLong (totalWriteOperations );
350
389
out .writeLong (totalReadKilobytes );
351
390
out .writeLong (totalWriteKilobytes );
391
+ if (out .getVersion ().onOrAfter (Version .V_8_0_0 )) {
392
+ out .writeLong (totalIOTimeInMillis );
393
+ }
352
394
}
353
395
354
396
public DeviceStats [] getDevicesStats () {
@@ -375,6 +417,10 @@ public long getTotalWriteKilobytes() {
375
417
return totalWriteKilobytes ;
376
418
}
377
419
420
+ public long getTotalIOTimeMillis () {
421
+ return totalIOTimeInMillis ;
422
+ }
423
+
378
424
@ Override
379
425
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
380
426
if (devicesStats .length > 0 ) {
@@ -392,6 +438,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
392
438
builder .field (WRITE_OPERATIONS , totalWriteOperations );
393
439
builder .field (READ_KILOBYTES , totalReadKilobytes );
394
440
builder .field (WRITE_KILOBYTES , totalWriteKilobytes );
441
+ builder .field (IO_TIMEMS , totalIOTimeInMillis );
395
442
builder .endObject ();
396
443
}
397
444
return builder ;
0 commit comments