[英]How can I create an SLA chart in Grafana?
I have a seriesMetric
, and a constantLine
(the goal/SLA). 我有一个
seriesMetric
和一个constantLine
(目标/ SLA)。 I want to be able to "count" the occurances below the line, and divide by the total to get a % within SLA. 我希望能够“计算”该行下方的出现次数,然后除以总数即可得出SLA中的百分比。 I know how to do the 2nd part, using
asPercent
, but I can't figure out how to count the occurrences below the line in Grafana. 我知道如何使用
asPercent
做第二部分,但是我不知道如何计算Grafana中该行以下的出现次数。 There's no countif
function. 没有
countif
函数。 I tried currentBelow
and averageBelow
, but then nothing appeared on my chart (the two lines disappeared). 我尝试了
currentBelow
和averageBelow
,但是图表上什么都没出现(这两条线消失了)。 I assume I did something wrong. 我认为我做错了。
I think this is a pretty common use case, and I assume someone has done this. 我认为这是一个非常常见的用例,我认为有人这样做了。 Ideally the % would go in a singleStat panel next to the chart.
理想情况下,百分比应放在图表旁边的singleStat面板中。
(We use Gafana with Graphite.) (我们将Gafana与Graphite结合使用。)
We finally figured this out, thanks to a coworker. 多亏了一位同事,我们终于解决了这个问题。 Here's what worked for us:
这是对我们有用的东西:
"A", "target": "averageSeries(stats.timers.rails.production-aws.rack.*.util.mean)"
This is the main metric. 这是主要指标。
"B", "target": "removeAboveValue(#A,25)"
This removes the values that are out of SLA. 这将删除SLA之外的值。 Our SLA is utilization should be <25%.
我们的SLA利用率应小于25%。
"C", "target": "alias(transformNull(asPercent(#B), 0), '% within SLA')"
asPercent
divides the series by itself which creates 1's (and Nulls). asPercent
将序列本身除以创建1(和Null)的序列。
transformNull
operates off the removeAboveValue
function replacing Nulls with 0s. transformNull
关闭removeAboveValue
函数,将removeAboveValue
替换为0。
Finally, under Axis & Grid > Legend > Click Average and Show 2 Decimals. 最后,在“轴与网格”>“图例”下,单击“平均值”并显示2个小数。 Doing this will provide an average SLA attainment for whatever timeframe you're viewing.
这样做将为您查看的任何时间范围提供平均的SLA达到率。
Depending on your what exactly your SLA will measure, this can be solved in a any number of ways. 根据您的SLA实际测量的内容,可以通过多种方法来解决。 A general answer to this question, and also the way I've solved it in projects, is to have an external script pull some relevant metrics from Graphite and simply push the result back (with a new key like xxsla.satisfied) as a pure binary result;
这个问题以及我在项目中解决该问题的方法的一个普遍答案是,让外部脚本从Graphite中提取一些相关指标,然后简单地将结果推回(使用xxsla.satisfied这样的新键)作为纯二进制结果; either 0 or 1. Then it's a simple matter of just averaging the value of the series and displaying that in percentage form.
取0或1。然后,只需对序列值取平均值并以百分比形式显示就可以了。 Because in the end, you either meet the SLA or you don't.
因为最终,您要么符合SLA,要么不满足。 If you want to dig deeper, you can always look at the graphs like the one you had in the picture.
如果您想更深入地进行研究,可以始终像查看图片一样查看这些图形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.