MetricsHub
MetricsHub Community Connectors 1.0.22
-
Home
- Connector Developer Guide Computes 24
divide (Compute)
When To Use
Use divide to divide every value of one column by an operand, row by row. The operand is either a literal number or, with the $n syntax, the value of another column of the same row. Literal divisors handle unit conversion (100-nanosecond intervals to seconds with value: 10000000, milliseconds to seconds with value: 1000); $n divisors compute ratios such as usage / capacity for a utilization metric. The column values must be numeric, and the divisor must not be 0.
Syntax
sources:
processInformation:
type: wmi
namespace: root\CIMv2
query: SELECT Name,ProcessId,KernelModeTime,UserModeTime FROM Win32_Process
computes:
# Convert 100-nanosecond intervals to seconds
- type: divide
column: 3
value: 10000000
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | divide. |
column |
Yes | None | 1-based index of the column to update. Each value in this column is replaced by column value / value. |
value |
Yes | None | Divisor. Either a literal number other than 0 (e.g. 1000) or a $n reference to another column of the same row (e.g. $7 for the 7th column). |
Table Transformation Example
With column: 3 and value: 10000000, column 3 of each row is divided by 10,000,000:
Input
| Name | ProcessId | KernelModeTime (100 ns) | UserModeTime (100 ns) |
|---|---|---|---|
| services.exe | 704 | 156250000 | 93750000 |
| explorer.exe | 4212 | 31250000 | 625000000 |
Result
| Name | ProcessId | KernelModeTime (s) | UserModeTime (100 ns) |
|---|---|---|---|
| services.exe | 704 | 15.625 | 93750000 |
| explorer.exe | 4212 | 3.125 | 625000000 |
Recommended Pattern
- Comment both the source unit and the target unit next to the compute (
# unit = 100-nanosecond intervals,# divide by 10000000 to get seconds). - For utilization metrics, duplicate the usage column first (
duplicateColumn), thendividethe copy by the capacity column withvalue: $n— keeping the raw usage for the usage metric. - Chain one
divideper column when the same divisor applies to several columns of the row.
Common Mistakes
- Dividing by
0, either literally or through a$nreference to a column that can hold0or an empty value. - Reversing the operands:
dividecomputescolumn / value, nevervalue / column. - Converting units twice: check whether the mapping already applies a conversion function before also dividing in the compute pipeline.
- Pointing
columnor$nat indexes that were shifted by an earlier compute such askeepColumnsorawk.
Community Examples
- Windows[1]
- WindowsProcess[2]
- Cassandra[3]
From Windows.yaml, computing memory utilization ratios against the total held in column 7, included directly from the connector source:
# Calculate utilization by dividing usage by total memory
- type: divide
column: 2
value: $7
- type: divide
column: 4
value: $7
- type: divide
column: 6
value: $7
divide
compute
division
arithmetic
ratio
unit conversion
metricshub
community
connector
hardware
system
Links:
- [1] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/Windows/Windows.yaml
- [2] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/system/WindowsProcess/WindowsProcess.yaml
- [3] https://github.com/metricshub/community-connectors/blob/main/src/main/connector/database/Cassandra/Cassandra.yaml
Search Results for {{siteSearch | truncate:'50'}}
{{resultArray.length}}
Searching...
No results.
