1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.platform;
import java.lang.reflect.Method;
/**
* Operating System Metrics class
*
* @implNote Some of the APIs within this class return metrics for an
* "Isolation Group" or "Container". When the term "Isolation Group"
* is used in the API description, this refers to either:
*
*<ol>
*<li> All processes, including the current process within a container.
*
*<li> All processes, including the current process running together
* isolated from other non-isolated processes.
*
*<li> All processes running on a host when that there is no isolation
* in effect.
*</ol>
*
* @author bobv
* @since 11
*/
public interface Metrics {
/**
* Returns an instance of the Metrics class.
*
* @return Metrics object or null if not supported on this platform.
*/
public static Metrics systemMetrics() {
return SystemMetrics.instance();
}
/**
* Returns the interface responsible for providing the
* platform metrics.
*
* @implNote
* Metrics are currently only supported Linux.
* The provider for Linux is cgroups (version 1 or 2).
*
* @return The name of the provider.
*
*/
public String getProvider();
/*****************************************************************
* CPU Accounting Subsystem
****************************************************************/
/**
* Returns the aggregate time, in nanoseconds, consumed by all
* tasks in the Isolation Group.
*
* @return Time in nanoseconds, -1 if unknown or
* -2 if the metric is not supported.
*
*/
public long getCpuUsage();
/**
* Returns the aggregate time, in nanoseconds, consumed by all tasks in
* the Isolation Group, separated by CPU. If the current process
* is running within a container, the reported time will only be
* valid for processes running within the same container. The values
* are returned in an array, one entry for each physical processor
* on the system. Time values for processors unavailable to this
* Group are undefined.
*
* @return long array of time values. The size of the array is equal
* to the total number of physical processors in the system. If
* this metric is not supported or not available, null will be
* returned.
*
*/
public long[] getPerCpuUsage();
/**
* Returns the aggregate user time, in nanoseconds, consumed by all
* tasks in the Isolation Group.
*
* @return User time in nanoseconds, -1 if the metric is not available or
* -2 if the metric is not supported.
*
*/
public long getCpuUserUsage();
/**
* Returns the aggregate system time, in nanoseconds, consumed by
* all tasks in the Isolation Group.
*
* @return System time in nanoseconds, -1 if the metric is not available or
* -2 if the metric is not supported.
*
*/
public long getCpuSystemUsage();
/*****************************************************************
* CPU Scheduling Metrics
****************************************************************/
/**
* Returns the length of the scheduling period, in
* microseconds, for processes within the Isolation Group.
*
* @return time in microseconds, -1 if the metric is not available or
* -2 if the metric is not supported.
*
*/
public long getCpuPeriod();
/**
* Returns the total available run-time allowed, in microseconds,
* during each scheduling period for all tasks in the Isolation
* Group.
*
* @return time in microseconds, -1 if the quota is unlimited or
* -2 if not supported.
*
*/
public long getCpuQuota();
/**
* Returns the relative weighting of processes with the Isolation
* Group used for prioritizing the scheduling of processes across
* all Isolation Groups running on a host.
*
* @implNote
* Popular container orchestration systems have standardized shares
* to be multiples of 1024, where 1024 is interpreted as 1 CPU share
* of execution. Users can distribute CPU resources to multiple
* Isolation Groups by specifying the CPU share weighting needed by
* each process. To request 2 CPUS worth of execution time, CPU shares
* would be set to 2048.
*
* @return shares value, -1 if the metric is not available or
* -2 if cpu shares are not supported.
*
*/
public long getCpuShares();
/**
* Returns the number of time-slice periods that have elapsed if
* a CPU quota has been setup for the Isolation Group
*
* @return count of elapsed periods, -1 if the metric is not available
* or -2 if the metric is not supported.
*
*/
public long getCpuNumPeriods();
/**
* Returns the number of time-slice periods that the group has
* been throttled or limited due to the group exceeding its quota
* if a CPU quota has been setup for the Isolation Group.
*
* @return count of throttled periods, -1 if the metric is not available or
* -2 if it is not supported.
*
*/
public long getCpuNumThrottled();
/**
* Returns the total time duration, in nanoseconds, that the
* group has been throttled or limited due to the group exceeding
* its quota if a CPU quota has been setup for the Isolation Group.
*
* @return Throttled time in nanoseconds, -1 if the metric is not available
* or -2 if it is not supported.
*
*/
public long getCpuThrottledTime();
/**
* Returns the number of effective processors that this Isolation
* group has available to it. This effective processor count is
* computed based on the number of dedicated CPUs, CPU shares and
* CPU quotas in effect for this isolation group.
*
* This method returns the same value as
* {@link java.lang.Runtime#availableProcessors()}.
*
* @return The number of effective CPUs.
*
*/
public long getEffectiveCpuCount();
/*****************************************************************
* CPU Sets
****************************************************************/
/**
* Returns the CPUS that are available for execution of processes
* in the current Isolation Group. The size of the array is equal
* to the total number of CPUs and the elements in the array are the
* physical CPU numbers that are available. Some of the CPUs returned
* may be offline. To get the current online CPUs, use
* {@link getEffectiveCpuSetCpus()}.
*
* @return An array of available CPUs. Returns null if the metric is not
* available or the metric is not supported.
*
*/
public int[] getCpuSetCpus();
/**
* Returns the CPUS that are available and online for execution of
* processes within the current Isolation Group. The size of the
* array is equal to the total number of CPUs and the elements in
* the array are the physical CPU numbers.
*
* @return An array of available and online CPUs. Returns null
* if the metric is not available or the metric is not supported.
*
*/
public int[] getEffectiveCpuSetCpus();
/**
* Returns the memory nodes that are available for use by processes
* in the current Isolation Group. The size of the array is equal
* to the total number of nodes and the elements in the array are the
* physical node numbers that are available. Some of the nodes returned
* may be offline. To get the current online memory nodes, use
* {@link getEffectiveCpuSetMems()}.
*
* @return An array of available memory nodes or null
* if the metric is not available or is not supported.
*
*/
public int[] getCpuSetMems();
/**
* Returns the memory nodes that are available and online for use by
* processes within the current Isolation Group. The size of the
* array is equal to the total number of nodes and the elements in
* the array are the physical node numbers.
*
* @return An array of available and online nodes or null
* if the metric is not available or is not supported.
*
*/
public int[] getEffectiveCpuSetMems();
/*****************************************************************
* Memory Subsystem
****************************************************************/
/**
* Returns the number of times that user memory requests in the
* Isolation Group have exceeded the memory limit.
*
* @return The number of exceeded requests or -1 if the metric
* is not available. Returns -2 if the metric is not
* supported.
*
*/
public long getMemoryFailCount();
/**
* Returns the maximum amount of physical memory, in bytes, that
* can be allocated in the Isolation Group.
*
* @return The maximum amount of memory in bytes or -1 if
* there is no limit or -2 if this metric is not supported.
*
*/
public long getMemoryLimit();
/**
* Returns the amount of physical memory, in bytes, that is currently
* allocated in the current Isolation Group.
*
* @return The amount of memory in bytes allocated or -1 if
* the metric is not available or -2 if the metric is not
* supported.
*
*/
public long getMemoryUsage();
/**
* Returns the amount of networking physical memory, in bytes, that
* is currently allocated in the current Isolation Group.
*
* @return The amount of memory in bytes allocated or -1 if the metric
* is not available. Returns -2 if this metric is not supported.
*
*/
public long getTcpMemoryUsage();
/**
* Returns the maximum amount of physical memory and swap space,
* in bytes, that can be allocated in the Isolation Group.
*
* @return The maximum amount of memory in bytes or -1 if
* there is no limit set or -2 if this metric is not supported.
*
*/
public long getMemoryAndSwapLimit();
/**
* Returns the amount of physical memory and swap space, in bytes,
* that is currently allocated in the current Isolation Group.
*
* @return The amount of memory in bytes allocated or -1 if
* the metric is not available. Returns -2 if this metric is not
* supported.
*
*/
public long getMemoryAndSwapUsage();
/**
* Returns the hint to the operating system that allows groups
* to specify the minimum amount of physical memory that they need to
* achieve reasonable performance in low memory systems. This allows
* host systems to provide greater sharing of memory.
*
* @return The minimum amount of physical memory, in bytes, that the
* operating system will try to maintain under low memory
* conditions. If this metric is not available, -1 will be
* returned. Returns -2 if the metric is not supported.
*
*/
public long getMemorySoftLimit();
/*****************************************************************
* pids subsystem
****************************************************************/
/**
* Returns the maximum number of tasks that may be created in the Isolation Group.
*
* @return The maximum number of tasks, -1 if the quota is unlimited or
* -2 if not supported.
*
*/
public long getPidsMax();
/**
* Returns the current number of tasks in the Isolation Group.
*
* @return The current number of tasks or -2 if not supported
*
*/
public long getPidsCurrent();
/*****************************************************************
* BlKIO Subsystem
****************************************************************/
/**
* Returns the number of block I/O requests to the disk that have been
* issued by the Isolation Group.
*
* @return The count of requests or -1 if the metric is not available.
* Returns -2 if this metric is not supported.
*
*/
public long getBlkIOServiceCount();
/**
* Returns the number of block I/O bytes that have been transferred
* to/from the disk by the Isolation Group.
*
* @return The number of bytes transferred or -1 if the metric is not
* available. Returns -2 if this metric is not supported.
*
*/
public long getBlkIOServiced();
}
|