简体   繁体   English

如何在见解查询中按其值拆分 Cloudwatch 字段

[英]How to split Cloudwatch field by its value in insights query

I'm trying to create an AWS dashboard visualization that displays the counts of cache hits vs. misses over a period of time.我正在尝试创建一个 AWS 仪表板可视化,显示一段时间内缓存命中与未命中的计数。 To do this, I'm setting up a log type dashboard with an insights query on the log.为此,我正在设置一个log类型仪表板,其中包含对日志的见解查询。 To be as simple as possible, my log is either:为了尽可能简单,我的日志是:

{"cache.hit", true} or {"cache.hit", false} . {"cache.hit", true}{"cache.hit", false}

I would like for my dashboard to track both possibilities on the same graph, but it seems like I can't without breaking my log up into distinct rows for these values.我希望我的仪表板在同一个图表上跟踪这两种可能性,但似乎我不能不将我的日志分成这些值的不同行。 For example, if my logs were simply:例如,如果我的日志只是:

{"cache.hit.true", true} or {"cache.hit.false", true} , then I could create 2 separate graphs to track these values independently in the dashboard, but that's not as clean. {"cache.hit.true", true}{"cache.hit.false", true} ,然后我可以创建 2 个单独的图表来在仪表板中独立跟踪这些值,但这并不那么干净。

To get them on one dash, I've tried this, but all it does is display the two fields, and the values for both display fields are the same, when they definitely shouldn't be:为了将它们放在一个破折号上,我已经尝试过了,但它所做的只是显示两个字段,并且两个显示字段的值是相同的,但它们绝对不应该是:

fields @timestamp, @message, cache.hit as cache_hits
| filter cache_hits IN [0, 1]
| display cache_hits = 0 as in_cache_false
| display cache_hits = 1 as in_cache_true
| stat count (in_cache_true), count(in_cache_false) by bin(30s)
| sort @timestamp desc
| limit 20

This query below extracts out the cache hits and cache misses and then works out the cache hit percentage.下面的这个查询提取出缓存命中和缓存未命中,然后计算出缓存命中百分比。

fields @timestamp, @message
| filter @message like /cache.hit/
| fields strcontains(@message, "true") as @CacheHit,
         strcontains(@message, "false") as @CacheMiss
| stats sum(@CacheHit) as CacheHits, sum(@CacheMiss) as CacheMisses, sum(@CacheHit) / (sum(@CacheMiss) + sum(@CacheHit)) * 100 as HitPercentage by bin(30s)
| sort @timestamp desc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM