amazon-cloudwatch - AWS CloudWatch Insights - 简单三元 IF 或一些类似函数
问题描述
考虑到我的日志中有许多带有时间测量的属性。我想计算它们每个比我的超时限制大多少次,例如 10 秒。
我目前能够多次运行非常相似的查询,如下所示:
fields context
| filter context.time_to_prepare > 10
| count(*) as count_slow_time_to_prepare by bin(10m)
fields context
| filter context.time_to_shine > 10
| count(*) as count_slow_time_to_shine by bin(10m)
.. 每个属性一个查询
如果我们可以在同一个查询中提取所有这些指标,那么绘图会更好也更容易。为此,所缺少的只是一些三元运算符或类似的东西。
我希望这样的事情会起作用:
fields context
| filter context.total_time > 0
| stats sum(if(context.time_to_prepare > 10,1,0)) as slow_time_to_prepare,
| sum(if(context.time_to_shine > 10,1,0)) as slow_time_to_shine ,
# .. one row for each attribute
| sum(if(context.time_to_move > 10,1,0)) as slow_time_to_move by bin(10m)
但这没有用。“如果”函数不存在。
那么,有什么办法可以制作三元if呢?
解决方案
我很接近,
这段代码应该可以完成这项工作:
fields context
| filter context.total_time > 0
| stats sum(context.time_to_prepare > 10) as slow_time_to_prepare,
| sum(context.time_to_shine > 10) as slow_time_to_shine ,
# .. one row for each attribute
| sum(context.time_to_move > 10) as slow_time_to_move by bin(10m)
True 和 Falsea > b
变为 1 和 0,可用于 sum、avg 等分组函数。
推荐阅读
- python - 我无法运行 streamlit
- javascript - 时间间隔未重置,但是相同的代码在另一个站点上运行良好
- gradle - Gradle:如何使用单个命令发布所有子项目?
- r - 关于在 Shiny 中在数据库和 selectinput 之间进行同步的疑问
- google-cloud-platform - 如何从云函数连接到云 sql 并且不返回 ENOENT 错误?
- r - 重新编码放置在列中的向量中的几个变量
- c# - Azure AD B2C 租户 ID 空
- push-notification - onesignal 通知在手机网络浏览器而不是应用程序中打开
- typescript - 在不使用 Record<> 的情况下定义 Typescript Mapped Type 的值类型(允许使用任何键)
- python - 从列表中删除包含至少 x 个值的所有数据帧行