Package oshi.util.platform.windows
Class PerfCounterQuery
- java.lang.Object
-
- oshi.util.platform.windows.PerfCounterQuery
-
@ThreadSafe public final class PerfCounterQuery extends java.lang.Object
Enables queries of Performance Counters using wild cards to filter instances
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePerfCounterQuery.PdhCounterPropertyContract for Counter Property Enums
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Set<java.lang.String>FAILED_QUERY_CACHEprivate static booleanIS_VISTA_OR_GREATERprivate static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String>LOCALIZE_CACHEprivate static org.slf4j.LoggerLOGstatic java.lang.StringNOT_TOTAL_INSTANCEstatic java.lang.StringNOT_TOTAL_INSTANCESstatic java.lang.StringTOTAL_INSTANCEstatic java.lang.StringTOTAL_INSTANCESstatic java.lang.StringTOTAL_OR_IDLE_INSTANCES
-
Constructor Summary
Constructors Modifier Constructor Description privatePerfCounterQuery()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringlocalizeIfNeeded(java.lang.String perfObject, boolean force)Localize a PerfCounter string.private static java.lang.StringlocalizeUsingPerfIndex(java.lang.String perfObject)static <T extends java.lang.Enum<T>>
java.util.Map<T,java.lang.Long>queryValues(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass)Query the a Performance Counter using PDH, with WMI backup on failure, for values corresponding to the property enum.static <T extends java.lang.Enum<T>>
java.util.Map<T,java.lang.Long>queryValuesFromPDH(java.lang.Class<T> propertyEnum, java.lang.String perfObject)Query the a Performance Counter using PDH for values corresponding to the property enum.static <T extends java.lang.Enum<T>>
java.util.Map<T,java.lang.Long>queryValuesFromWMI(java.lang.Class<T> propertyEnum, java.lang.String wmiClass)Query the a Performance Counter using WMI for values corresponding to the property enum.
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
IS_VISTA_OR_GREATER
private static final boolean IS_VISTA_OR_GREATER
-
FAILED_QUERY_CACHE
private static final java.util.Set<java.lang.String> FAILED_QUERY_CACHE
-
LOCALIZE_CACHE
private static final java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> LOCALIZE_CACHE
-
TOTAL_INSTANCE
public static final java.lang.String TOTAL_INSTANCE
- See Also:
- Constant Field Values
-
TOTAL_OR_IDLE_INSTANCES
public static final java.lang.String TOTAL_OR_IDLE_INSTANCES
- See Also:
- Constant Field Values
-
TOTAL_INSTANCES
public static final java.lang.String TOTAL_INSTANCES
- See Also:
- Constant Field Values
-
NOT_TOTAL_INSTANCE
public static final java.lang.String NOT_TOTAL_INSTANCE
- See Also:
- Constant Field Values
-
NOT_TOTAL_INSTANCES
public static final java.lang.String NOT_TOTAL_INSTANCES
- See Also:
- Constant Field Values
-
-
Method Detail
-
queryValues
public static <T extends java.lang.Enum<T>> java.util.Map<T,java.lang.Long> queryValues(java.lang.Class<T> propertyEnum, java.lang.String perfObject, java.lang.String perfWmiClass)Query the a Performance Counter using PDH, with WMI backup on failure, for values corresponding to the property enum.- Type Parameters:
T- The enum type ofpropertyEnum- Parameters:
propertyEnum- An enum which implementsPerfCounterQuery.PdhCounterPropertyand contains the WMI field (Enum value) and PDH Counter string (instance and counter)perfObject- The PDH object for this counter; all counters on this object will be refreshed at the same timeperfWmiClass- The WMI PerfData_RawData_* class corresponding to the PDH object- Returns:
- An
EnumMapof the values indexed bypropertyEnumon success, or an empty map if both PDH and WMI queries failed.
-
queryValuesFromPDH
public static <T extends java.lang.Enum<T>> java.util.Map<T,java.lang.Long> queryValuesFromPDH(java.lang.Class<T> propertyEnum, java.lang.String perfObject)Query the a Performance Counter using PDH for values corresponding to the property enum.- Type Parameters:
T- The enum type ofpropertyEnum- Parameters:
propertyEnum- An enum which implementsPerfCounterQuery.PdhCounterPropertyand contains the WMI field (Enum value) and PDH Counter string (instance and counter)perfObject- The PDH object for this counter; all counters on this object will be refreshed at the same time- Returns:
- An
EnumMapof the values indexed bypropertyEnumon success, or an empty map if the PDH query failed.
-
queryValuesFromWMI
public static <T extends java.lang.Enum<T>> java.util.Map<T,java.lang.Long> queryValuesFromWMI(java.lang.Class<T> propertyEnum, java.lang.String wmiClass)Query the a Performance Counter using WMI for values corresponding to the property enum.- Type Parameters:
T- The enum type ofpropertyEnum- Parameters:
propertyEnum- An enum which implementsPerfCounterQuery.PdhCounterPropertyand contains the WMI field (Enum value) and PDH Counter string (instance and counter)wmiClass- The WMI PerfData_RawData_* class corresponding to the PDH object- Returns:
- An
EnumMapof the values indexed bypropertyEnumif successful, an empty map if the WMI query failed.
-
localizeIfNeeded
public static java.lang.String localizeIfNeeded(java.lang.String perfObject, boolean force)Localize a PerfCounter string. English counter names should normally be inHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter, but language manipulations may delete the009index. In this case we can assume English must be the language and continue. We may still fail to match the name if the assumption is wrong but it's better than nothing.- Parameters:
perfObject- A String to localizeforce- If true, always localize- Returns:
- The localized string if localization successful, or the original string otherwise.
-
localizeUsingPerfIndex
private static java.lang.String localizeUsingPerfIndex(java.lang.String perfObject)
-
-