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 interface  PerfCounterQuery.PdhCounterProperty
    Contract for Counter Property Enums
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String NOT_TOTAL_INSTANCE  
    static java.lang.String NOT_TOTAL_INSTANCES  
    static java.lang.String TOTAL_INSTANCE  
    static java.lang.String TOTAL_INSTANCES  
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String localize​(java.lang.String perfObject)
    Localize a PerfCounter string.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • 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 of propertyEnum
      Parameters:
      propertyEnum - An enum which implements PerfCounterQuery.PdhCounterProperty and 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
      perfWmiClass - The WMI PerfData_RawData_* class corresponding to the PDH object
      Returns:
      An EnumMap of the values indexed by propertyEnum on 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 of propertyEnum
      Parameters:
      propertyEnum - An enum which implements PerfCounterQuery.PdhCounterProperty and 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 EnumMap of the values indexed by propertyEnum on 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 of propertyEnum
      Parameters:
      propertyEnum - An enum which implements PerfCounterQuery.PdhCounterProperty and 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 EnumMap of the values indexed by propertyEnum if successful, an empty map if the WMI query failed.
    • localize

      public static java.lang.String localize​(java.lang.String perfObject)
      Localize a PerfCounter string. English counter names should normally be in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009\Counter, but language manipulations may delete the 009 index. 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 localize
      Returns:
      The localized string if localization successful, or the original string otherwise.