Metric Stream Methods
IsEmpty
- IsEmpty()
- return true if the stream has no data series
cpu.IsEmpty()
Sort
- Sort(limit, "AggregationType1", "AggregationType2"…)
- sort the stream by aggregation(s)
// top 10 CPU utilizations
cpu.Sort(10, "Average")
ReplaceKey
- ReplaceKey(keyValueMap)
- replace metric key based on a key/value map
// replace compoment metric key (compoment.id) with compoment name
let idMap = {}
let components = Platform_LoadComponent()
components.Each( (_, c) => {
idMap[c.id] = c.name
})
let {table:sources, histogram: sourceHistogram} = groupByBytes(from, to, "platform_component_bytes", `component="datasource"`, "id", 10)
sources.NewColumnLambda("name", "", (row) => idMap[row.id])
sourceHistogram.ReplaceKey(idMap)
SummaryTable
- SummaryTable(column, unit, aggregationType)
- create a new table with a new column which holds the aggreation results for each data series
- aggregationType: Sum | Average | Min | Max | Count | Last
// create a new table "invocationSummary" with a column "Total_Invocations"
let invocationSummary = lambdaInvocations.SummaryTable("Total_Invocations", "Count", "Sum")
TimeTable
- TimeTable(timeFormat, unit)
- creates a new table where each column is a time slot rendered with timeFormat.
- timeFormat follows the Golang Time Format
let timeTable = balance.TimeTable("Jan 02 15:04:05", "Percent")
DimensionTable
- DimensionTable(dimension, unit, aggregationType)
- for metric stream with two dimensions. choose one dimension as the key dimension. the value of the other dimension will become a new column in the created new table
function getS3BucketSize(assetTable) {
let options = {from:"-48h@d", to:"@d", dimensions=["BucketName","StorageType"], namespace:"AWS/S3", period:"24h", stat:"Average"}
let filters = {BucketName:assetTable}
let size = AWS_GetMetric("BucketSizeBytes", options, filters)
let objCount = AWS_GetMetric("NumberOfObjects", options, filters)
return {size, objCount}
}
function main() {
return AWS_AccountRegionLambda("*", "*", (account, region) => {
let buckets = AWS_LoadAsset("s3:bucket", (obj) => { return {ID: obj.Name} })
let {size, objCount} = getS3BucketSize(buckets)
let bucketTable = size.DimensionTable("StorageType","Byte","Last")
let countTable = objCount.DimensionTable("StorageType","Count","Last")
return {bucketTable, countTable}
})
}
SetTags
- SetTags(assetTable)
- convert asset table columns into tags for the metric stream key
SetUnit
- SetUnit(unit)
- set unit for metric stream