Dell Windows Server Peak Amperage Performance Data Source Module

Dell.WindowsServer.PerfDS.PeakAmperage (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Performance.Data

Member Modules:

ID Module Type TypeId RunAs 
PerformanceDS DataSource Microsoft.Windows.TimedScript.PerformanceProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsInterval Seconds

Source Code:

<DataSourceModuleType ID="Dell.WindowsServer.PerfDS.PeakAmperage" Accessibility="Internal">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="PerformanceDS" TypeID="Windows!Microsoft.Windows.TimedScript.PerformanceProvider">
<IntervalSeconds>600</IntervalSeconds>
<SyncTime/>
<ScriptName>GetPeakAmperage.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
'**********************************************************************************
' Script Name - GetPeakAmperage
' Author: Vignesh Pandian
'
' Description:
' This script fetches Peak Amperage counter value from instrumentation.
'
' (c) Copyright &#xA9; 2009&#x2013; 2017 Dell Inc, or its subsidiaries. All Rights Reserved
'**********************************************************************************
Option Explicit
On Error resume next
SetLocale("en-us")

Dim oAPI
Set oAPI = CreateObject("MOM.ScriptAPI")

Dim strComputer, WbemServices, wbemObjectSet, oBag
Dim PeakAmperage, flag
flag = 0
strComputer="."
Dim LogMessage, ErrorMessage

Set WbemServices = GetObject("winmgmts:" &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2\dell")
If IsEmpty(WbemServices) Then
MOMDebugLog 1, "Unable to open WMI Namespace root-cimv2-dell. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists." &amp; Err.Description
Else
Set wbemObjectSet = GetObjectSet(wbemServices, "Select * from DELL_PowerConsumptionData", "CumulativePowerReading", "DELL_PowerConsumptionData")
If Err.Number &lt;&gt; 0 Then
ErrorMessage = "Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
MOMDebugLog 1, ErrorMessage
End If

If (wbemObjectSet is Nothing) or (IsNull(wbemObjectSet)) Then
LogMessage = "Unable to retrieve Peak Amperage detail"
MOMDebugLog 1, LogMessage
Else
LogMessage = "Peak Amperage Value retrieved successfully"
MOMDebugLog 1, LogMessage

Dim objItem
For Each objItem in wbemObjectSet
'Error checking
If Err.Number &lt;&gt; 0 Then
ErrorMessage = "Number:" &amp; Err.Number &amp; "Description:" &amp; Err.Description
MOMDebugLog 1, ErrorMessage
End If
'Object Retrieval
If not objItem is nothing Then
PeakAmperage = objItem.peakAmpReading
' Earlier assumption - instrumentation is returning 10th unit of a Amp. Connections has to show the value in milliAmp
' Modified to - instrumentation is returning 10 times PeakAmperage
PeakAmperage = PeakAmperage / 10
If PeakAmperage &gt; 0 Then
flag = 1
End If
End If
Next
End If
Set wbemObjectSet = Nothing
End If

If flag = 1 Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("PeakAmperage", Round(PeakAmperage,1))
Call oAPI.Return(oBag)
End If

' *** Add double query fix

' Function to retrieve the object

Function GetObjectSet(ByRef objDellConnection, SelectQuery, Attribute, objName)
Dim retry, retryFlag
Dim objItem, arrURL, logMessage

On Error Resume Next
RetryFlag = False
For retry = 0 To 1
MOMDebugLog 1, "Retrying for " &amp; retry &amp; " time..."
Set GetObjectSet = objDellConnection.ExecQuery(SelectQuery)
LogErrorNumber(objName)
If (GetObjectSet is Nothing) Or (IsNull(GetObjectSet)) Then
logMessage = "INFO: Unable to retrieve " &amp; objName &amp; " Attributes"
MOMDebugLog 1, logMessage
WScript.Sleep(1000)
RetryFlag = True
Else
logMessage= "INFO: " &amp; objName &amp; " attributes retrieved successfully"
MOMDebugLog 1, logMessage
If Attribute = "__COUNT__" Then
Exit For
End If
For Each objItem in GetObjectSet
If LogErrorNumber(objName) = 0 Then
If Not objItem is nothing Then
Dim attrVal : attrVal = objItem.Properties_.Item(Attribute)
If IsNull(attrVal) Or Len(attrVal) &lt;= 0 Then
MOMDebugLog 1, Attribute &amp; " value is null or empty"
RetryFlag = True
WScript.Sleep(500)
Exit For
Else
Exit Function
End If
End If
End If
Next
If RetryFlag = False Then
Exit For
End If
End If
Next
End Function

Function LogErrorNumber(objName)
Dim logMessage
LogErrorNumber = Err.Number
If Err.Number &lt;&gt; 0 Then
Select Case Err.Number
Case -2147749904
logMessage = "CIM Object not found"
Case -2147749902
logMessage = "Dell CIM object not found"
Case -2147023169
logMessage = "RPC Failure occurred for namespace root-cimv2-dell"
Case -2147217389
logMessage = "Please Install/Re-Install ServerAdministrator on Dell Server!"
Case -2147217394 '0x8004100E
logMessage = "Not able to find Dell CIM object"
Case -2147217392 '0x8004100C
logMessage = "Not able to find the collection"
Case -2147749890
logMessage = "Object cannot be found"
Case -2147749892
logMessage = "Object cannot be found"
Case Else
logMessage = "Unable to retrieve " &amp; objName
logMessage = logMessage &amp; " Err Number:" &amp; Err.Number
logMessage = logMessage &amp; " Err Descr:" &amp; Err.Description
End Select
MOMDebugLog 1, "ERROR: " &amp; logMessage
End If
End Function
'*** Add MOMDebug
Const DEBUG_LOG_FILENAME = "GetPeakAmperage.log"
Dim loginited: loginited = False
Dim objLogTextFile, objLogFSO

Sub InitLog(strFileName)
' Begin Logheader
If logLevel &lt;&gt; 0 And loginited = False Then
Dim fileSize, strOutFile
Const ForAppending = 8
Const ForWriting = 2
Const MaxFileSize = 524288 'File Size is limited to 512 KB

dim wsShell : Set wsShell = Createobject("WScript.Shell")
dim wshSysEnv : Set wshSysEnv = wsShell.Environment
dim tFolder : tFolder = wshSysEnv("TEMP")
dim wshPrcEnv : Set wshPrcEnv = wsShell.Environment("Process")
tFolder = Replace(tFolder, "%SystemRoot%", wshPrcEnv("SYSTEMROOT"), 1, -1, vbTextCompare)

Set objLogFSO = CreateObject("Scripting.FileSystemObject")
If Not objLogFSO.FolderExists(tFolder) Then
objLogFSO.CreateFolder(tFolder)
End If
strOutFile = tFolder &amp; "\"&amp; strFileName
WScript.Echo strOutFile
If Not objLogFSO.FileExists(strOutFile) Then
Set objLogTextFile = objLogFSO.CreateTextFile(strOutFile)
objLogTextFile.Close()
End If
fileSize = objLogFSO.GetFile(strOutFile).Size
If (fileSize &gt; MaxFileSize) Then
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForWriting, True)
Else
Set objLogTextFile = objLogFSO.OpentextFile(strOutFile, ForAppending, True)
End If
loginited = True
MOMDebugLog 1, "------------------------------------------------------"
MOMDebugLog 1, "INFO: Script - " &amp; strFileName &amp; ": Start()"
Err.Clear
End If
End Sub

Sub MOMDebugLog (ByVal debugLevel, ByVal Message)
'On Error Resume Next
If (debugLevel &gt; 0) and (debugLevel &lt;= logLevel) Then
If loginited = False Then
InitLog DEBUG_LOG_FILENAME
End If
objLogTextFile.WriteLine(Now() &amp; " ---- " &amp; Message)
Err.Clear
End If
End Sub

Sub CloseLog
' Begin Logheader
If loginited = True Then
objLogTextFile.Close
End If
End Sub

CloseLog
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<EventPolicy>
<StdOutMatches/>
</EventPolicy>
<ObjectName>DellServerPeakAmperagePerf</ObjectName>
<CounterName>Peak Amperage</CounterName>
<InstanceName>$Target/Property[Type="Windows!Microsoft.Windows.LogicalDevice"]/DeviceID$</InstanceName>
<Value>$Data/Property[@Name='PeakAmperage']$</Value>
</DataSource>
</MemberModules>
<Composition>
<Node ID="PerformanceDS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Performance!System.Performance.Data</OutputType>
</DataSourceModuleType>