customfield

Sometimes you need to display/warn against a field that is needs to be created from other WMI fields.
A custom field is some other fields (WMI or other custom fields) that has some functions applied to it.

You can then use the custom field in your display, performance data or to warn against.

———— sample.ini extract —————
create custom fields that can be used for display, perf data or testing warn/crit criteria
for example you might want to average to readings of a WMI Raw counter
the format of this field is
NEWFIELDNAME,FUNCTION,FUNCTIONPARAMETERS
where FUNCTIONPARAMETERS itself is a comma delimited list and specific to the FUNCTION
we like to start our NEWFIELDNAMEs with an _ as you will see in the samples
where we take 2 WMI values and calculate a percentage from them like this percentage=100* PARAM1/PARAM2
we then apply the sprintf format string %.1f to give 1 decimal place
we can then use the new field, _FreeMemPercent in test=, display= and perf= settings
in this particular example we have
NEWFIELDNAME FUNCTION PARAM1 PARAM2 PARAM3
customfield=_FreeMemPercent,percent,FreePhysicalMemory,TotalVisibleMemorySize,%.1f,
———— end sample.ini extract —————

Custom Field Example

For example to create a field that is 8 times a WMI field, you would create a custom field using the basicmaths function.

You’ll need to do something like
1. query the data
2. create the custom field
3. use the custom field

You might have something like:
query=Select BytesTotalPersec from Win32_PerfRawData_Tcpip_NetworkInterface
customfield=_NewField,basicmaths,BytesTotalPersec,*,8,%.1f,
display=NewField

Custom Field Functions

These are the functions that can be applied to create custom fields.

This is an extract from the sample.ini file that :

# —— basic maths
# it requires one completed WMI queries
# the parameters for this “function” are
# SOURCEFIELD1,OPERATOR,SOURCEFIELD2,SPRINTF_SPEC
# where
# SOURCEFIELD1 [0] is a WMI field name which contains some number or just a number
# OPERATOR [1] is one of + – * /
# SOURCEFIELD2 [2] is a WMI field name which contains some number or just a number
# SPRINTF_SPEC [3] – a format specification passed directly to sprintf to format the result (can leave blank)
# Formula is SOURCEFIELD1 OPERATOR SOURCEFIELD2
# eg 2 * 3
# —– percent
# it requires one completed WMI queries
# the parameters for this “function” are
# SOURCEFIELD1,SOURCEFIELD2,SPRINTF_SPEC
# where
# SOURCEFIELD1 [0] is some number
# SOURCEFIELD2 [1] is some number
# SPRINTF_SPEC [2] – a format specification passed directly to sprintf to format the result (can leave blank)
# INVERT [3] take the resulting value away from this number. Useful in the following example eg set this value to 100 to show busy percentage where counter value is an idle percentage.
# Formula is 100 * SOURCEFIELD1/SOURCEFIELD2
# —– WMITimestampToAgeSec
# it requires one completed WMI query
# the parameters for this “function” are
# SOURCEFIELD1
# where
# SOURCEFIELD1 [0] is a WMI timestamp like 20100528105127.000000+600
# This timestamp is a GMT time, we convert it to an age in seconds
# —– SectoDay
# converts a number of seconds to days
# it requires one completed WMI query
# the parameters for this “function” are
# SOURCEFIELD1,SPRINTF_SPEC
# where
# SOURCEFIELD1 [0] is a number of seconds
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
# —— KBtoB
# converts a number of kilo bytes to bytes – then we can use our standard scaling routine on the number for a niver display
# BYTEFACTOR is used in this calculation
# it requires one completed WMI query
# the parameters for this “function” are
# SOURCEFIELD1,SPRINTF_SPEC
# where
# SOURCEFIELD1 [0] is a number of KB
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
#
# —— HYPERV_TOTALVM_MEMORY
# used for calculating HyperV memory
# customfield=_almost_total_vm_memory,HYPERV_TOTALVM_MEMORY,Value1GGPApages,Value2MGPApages,Value4KGPApages,DepositedPages
# select Name,Value1GGPApages,Value2MGPApages,Value4KGPApages,DepositedPages from Win32_PerfRawData_HvStats_HyperVHypervisorPartition
# it requires 1 completed WMI queries (sample=1)
# almost_total_vm_memory = “1G GPA Pages” * 1024 + (“2M GPA Pages” * 2) + ((“4K GPA Pages” + “Deposited pages”) / 256)
#
# the parameters for this “function” are
# Value1GGPApages,Value2MGPApages,Value4KGPApages,DepositedPages,SPRINTF_SPEC
# where
# Value1GGPApages [0] is the WMI Field for 1G pages – required
# Value2MGPApages [1] is the WMI Field for 2M pages – required
# Value4KGPApages [2] is the WMI Field for 4K pages – required
# DepositedPages [3] is the WMI Field for Deposited pages – required
# SPRINTF_SPEC [4] – a format specification passed directly to sprintf to format the result (can leave blank)

# these next function types actually directly related to the WMI raw data type. See the http references.
# References:
# http://include.wutils.com/wmi/ROOT%5Ccimv2/CIM_StatisticalInformation/Wi…
# http://msdn.microsoft.com/en-us/library/aa389383%28v=VS.85%29.aspx
# —– PERF_COUNTER_RAWCOUNT – Counter Type #65536
# Does not need any additional calculation – just use the value direct from WMI
# —– PERF_100NSEC_TIMER_INV – CounterType #558957824
# refer http://technet.microsoft.com/en-us/library/cc757283%28WS.10%29.aspx
# this is a calculation like for checkcpu found on
# it requires two completed WMI queries (sample=2)
# Formula = (1- ( (N2 – N1) / (D2 – D1) /F )) x 100
# we assume that the Timefield (D) we need is Timestamp_Sys100NS
#
# the parameters for this “function” are
# SOURCEFIELD,SPRINTF_SPEC,MAX
# where
# SOURCEFIELD [0] is the WMI Field to base this on eg PercentProcessorTime – required
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
# MAXIMUM VALUE [2] – the maximum value that this “function” will return (optional)
# —– PERF_100NSEC_TIMER – CounterType #542180608
# refer http://technet.microsoft.com/en-us/library/cc728274%28WS.10%29.aspx
# it requires two completed WMI queries (sample=2)
# (Nx – N0) / (Dx – D0) x 100
# we assume that the Timefield (D) we need is Timestamp_Sys100NS
#
# the parameters for this “function” are
# SOURCEFIELD,SPRINTF_SPEC,MAX
# where
# SOURCEFIELD [0] is the WMI Field to base this on eg PercentProcessorTime – required
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
# MAXIMUM VALUE [2] – the maximum value that this “function” will return (optional)
# —– PERF_COUNTER_COUNTER and PERF_COUNTER_BULK_COUNT – CounterType #272696320 and #272696576
# refer http://technet.microsoft.com/en-us/library/cc740048%28WS.10%29.aspx
# it requires two completed WMI queries (sample=2)
# Formula = (Nx – N0) / ((Dx – D0) / F)
# we assume that the Timefield (D) we need is Timestamp_Sys100NS
# we assume that the Frequency (F) we need is Frequency_Sys100NS
#
# the parameters for this “function” are
# SOURCEFIELD,SPRINTF_SPEC
# where
# SOURCEFIELD [0] is the WMI Field to base this on eg PercentProcessorTime – required
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
# —– PERF_PRECISION_100NS_TIMER and PERF_COUNTER_100NS_QUEUELEN_TYPE – CounterType #542573824 and #5571840
# refer http://technet.microsoft.com/en-us/library/cc756128%28WS.10%29.aspx
# it requires two completed WMI queries (sample=2)
# Formula = N1 – N0 / D1 – D0
# we assume that the Timefield (D) we need is Timestamp_Sys100NS
#
# REfer http://technet.microsoft.com/en-us/library/cc781696%28WS.10%29.aspx for PERF_COUNTER_100NS_QUEUELEN_TYPE
# This one seems to give correct results calculated like this but has a slightly different formula on the reference page?
#
# the parameters for this “function” are
# SOURCEFIELD,MULTIPLIER,SPRINTF_SPEC
# where
# SOURCEFIELD [0] is the WMI Field to base this on eg PercentProcessorTime – required
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
# MULTIPLIER [2] is a multiplier useful to make the fraction a percentage eg 100
# INVERT [3] take the value away from this number. Useful in the following example eg set this value to 100 to show busy percentage where counter value is an idle percentage. Applied after the multiplier
# —– PERF_ELAPSED_TIME – CounterType #807666944
# refer http://technet.microsoft.com/en-us/library/cc756820%28WS.10%29.aspx
# it requires two completed WMI queries (sample=2)
# Formula = (D0 – N0) / F
# we assume that the Timefield (D) we need is Timestamp_Object
# we assume that the Frequency (F) we need is Frequency_Sys100NS
#
# the parameters for this “function” are
# SOURCEFIELD,SPRINTF_SPEC
# where
# SOURCEFIELD [0] is the WMI Field to base this on eg PercentProcessorTime – required
# SPRINTF_SPEC [1] – a format specification passed directly to sprintf to format the result (can leave blank)
#