MetricsHub
MetricsHub Community Connectors 1.0.24
-
Home
- Connector Developer Guide Computes 27
sort (Compute)
When To Use
Use sort to order the lines of a table on one of its columns: the processes by CPU, the files by size, the entries by name. Followed by head[1], it keeps the top lines.
Syntax
sources:
processes:
type: wmi
query: SELECT Name, IDProcess, WorkingSetPrivate FROM Win32_PerfFormattedData_PerfProc_Process WHERE Name <> '_Total'
namespace: root\CIMv2
computes:
# The processes that use the most memory first
- type: sort
column: 3
numeric: true
descending: true
Properties
| Property | Required | Default | Description |
|---|---|---|---|
type |
Yes | None | sort. |
column |
Yes | None | The 1-based column to sort on. |
numeric |
No | false |
true compares the values as numbers (9.5 before 10), false alphabetically (10 before 9.5). Numbers may be negative, decimal, or written with an exponent (1.5E3), but not with a unit or a thousands separator (12%, 1,024). |
ignoreCase |
No | false |
true makes the alphabetical comparison ignore the case (alpha before Beta). By default, the values compare by their characters' code, which puts uppercase letters before lowercase ones (Beta before alpha). Without effect when numeric is true. |
descending |
No | false |
true sorts from the largest value to the smallest. |
The sort is stable: lines with equal values keep their order. The lines that lack the column, and, in a numeric sort, those whose value is not a number (n/a, an empty value, a header), go last, in their original order, in both directions.
Table Transformation Example
With column: 3, numeric: true and descending: true:
Input
| Name | PID | Memory |
|---|---|---|
| svchost | 880 | 9452 |
| sqlservr | 2140 | 812004 |
| Idle | 0 | n/a |
| w3wp | 5012 | 125340 |
Result
| Name | PID | Memory |
|---|---|---|
| sqlservr | 2140 | 812004 |
| w3wp | 5012 | 125340 |
| svchost | 880 | 9452 |
| Idle | 0 | n/a |
Recommended Pattern
Common Mistakes
- Counting columns from 0:
columnis 1-based, andcolumn: 0leaves the table unchanged. - Leaving a header line in the table: a numeric sort moves it last, an alphabetical sort moves it among the data. Remove it with
excludeMatchingLines[5] first. - Expecting a locale-aware alphabetical order: accented letters come after
z.
sort
compute
order
numeric
alphabetical
descending
ignoreCase
metricshub
community
connector
hardware
system
Links:
- [1] head.html
- [2] tail.html
- [3] replace.html
- [4] awk.html
- [5] exclude-matching-lines.html
Search Results for {{siteSearch | truncate:'50'}}
{{resultArray.length}}
Searching...
No results.
