我试图获取运行 lambda 时使用的内存百分比以显示在 cloudwatch 上的图表中。我知道还有其他方法可以提取数据,但由于本问题范围之外的原因,我想坚持使用搜索来提取指标。
我有以下图表
{
"metrics": [
[ { "expression": "SEARCH('{SomeMetricNamespace} MetricName=\"MemorySize\"', 'Average', 300)", "id": "m1", "visible": "true" } ],
[ { "expression": "SEARCH('{SomeMetricNamespace} MetricName=\"MaxMemoryUsed\"', 'Average', 300)", "id": "m2", "visible": "true" } ],
[ { "expression": "m2/m1*100", "label": "pecentage memory used", "id": "e1", "stat": "Average" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-west-2",
"stat": "Average",
"period": 300,
"title": "Memory",
"yAxis": {
"left": {
"label": "Percentage Usage",
"showUnits": false
}
},
"liveData": false
}
我遇到的错误
Error in expression e1 [Unsupported operand type(s) for /: '[Array[TimeSeries], Array[TimeSeries]]']
有没有办法结合前 2 个表达式来给出使用的内存百分比?
表达式的结果是时间序列数组,因此不能直接应用运算(+ - * / ^)。作为解决方法,您可以将每个时间序列转换为每个表达式的单个值(平均值),然后计算百分比。
来源应该与此类似:
{
"metrics": [
[ { "expression": "SEARCH('{SomeMetricNamespace} MetricName=\"MemorySize\"', 'Average', 300)", "id": "m1", "visible": "false" } ],
[ { "expression": "SEARCH('{SomeMetricNamespace} MetricName=\"MaxMemoryUsed\"', 'Average', 300)", "id": "m2", "visible": "false" } ],
[ { "expression": "AVG(m1)", "label": "AVGMemorySize", "id": "e1", "visible": "false" } ],
[ { "expression": "AVG(m2)", "label": "AVGMaxMemoryUsed", "id": "e2", "visible": "false" } ],
[ { "expression": "e2/e1*100", "label": "pecentage memory used", "id": "e3", "stat": "Average" } ]
],
"view": "timeSeries",
"stacked": false,
"region": "us-west-2",
"stat": "Average",
"period": 300,
"title": "Memory",
"yAxis": {
"left": {
"label": "Percentage Usage",
"showUnits": false
}
},
"liveData": false
}