'Where' 带有石墨查询的子句
'Where' clause with graphite queries
我在 Graphite 中保存了大量时间序列度量数据。假设我有 2 个不同的指标 X 和 Y 代表两种不同产品的价格。
我现在想从一个应用程序中查询数据并做这样的事情(当然,这是伪sql):
Select all points of metric X where value is smaller than value of metric Y during a time frame
如果不编写自己的脚本或一些 map-reduce 作业,我找不到任何合理的方法来做到这一点。
例如,我可以绘制图表并尝试从视觉上很容易地理解它。但它不能用于应用程序。
我也考虑过使用一些函数,比如 currentBelow
和 currentAbove
,但看起来我不能提供两个不同的系列来比较,而是在整个时间段内只能提供一个特定的整数.
免责声明:我希望有更好的解决方案;)。
解决方法是:
指标:
product.X.price
product.Y.price
创建过滤掩码 - 值 0 不大于,1 大于
diffSeries - 设置边界 0 - 上面的点我们要包括,下面要排除。
diffSeries(product.X.price, product.Y.price)
removeBelowValue - 删除所有排除的 - 低于 0,
removeBelowValue(diffSeries(product.X.price, product.Y.price), 0)
divideSeries - 将上述系列除以自身以创建 0 和 1 的掩码 - 幸运的是在石墨的函数中 0/0 = 0(原文如此!),
divideSeries(removeBelowValue(diffSeries(product.X.price, product.Y.price), 0), removeBelowValue(diffSeries(product.X.price, product.Y.price), 0))
使用multiplySeries准备好的掩码过滤掉,因为
0 * 数据点 = 0
1 * 数据点 = 数据点
multiplySeries(product.X.price, divideSeries(removeBelowValue(diffSeries(product.X.price, product.Y.price), 0), removeBelowValue(diffSeries(product.X.price, product.Y.price), 0)))
我在 Graphite 中保存了大量时间序列度量数据。假设我有 2 个不同的指标 X 和 Y 代表两种不同产品的价格。
我现在想从一个应用程序中查询数据并做这样的事情(当然,这是伪sql):
Select all points of metric X where value is smaller than value of metric Y during a time frame
如果不编写自己的脚本或一些 map-reduce 作业,我找不到任何合理的方法来做到这一点。
例如,我可以绘制图表并尝试从视觉上很容易地理解它。但它不能用于应用程序。
我也考虑过使用一些函数,比如 currentBelow
和 currentAbove
,但看起来我不能提供两个不同的系列来比较,而是在整个时间段内只能提供一个特定的整数.
免责声明:我希望有更好的解决方案;)。
解决方法是:
指标:
product.X.price
product.Y.price
创建过滤掩码 - 值 0 不大于,1 大于
diffSeries - 设置边界 0 - 上面的点我们要包括,下面要排除。
diffSeries(product.X.price, product.Y.price)
removeBelowValue - 删除所有排除的 - 低于 0,
removeBelowValue(diffSeries(product.X.price, product.Y.price), 0)
divideSeries - 将上述系列除以自身以创建 0 和 1 的掩码 - 幸运的是在石墨的函数中 0/0 = 0(原文如此!),
divideSeries(removeBelowValue(diffSeries(product.X.price, product.Y.price), 0), removeBelowValue(diffSeries(product.X.price, product.Y.price), 0))
使用multiplySeries准备好的掩码过滤掉,因为
0 * 数据点 = 0
1 * 数据点 = 数据点
multiplySeries(product.X.price, divideSeries(removeBelowValue(diffSeries(product.X.price, product.Y.price), 0), removeBelowValue(diffSeries(product.X.price, product.Y.price), 0)))