这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

5 趋势函数

历史函数相反,趋势函数使用趋势数据进行计算。

趋势存储每小时的聚合值。趋势函数使用这些每小时的平均值,因此对于长期分析很有用。

趋势函数的结果会被缓存,因此对于具有相同参数的相同函数的多次调用,只会从数据库中获取信息一次。趋势函数缓存由TrendFunctionCacheSize服务器参数控制。

仅引用趋势函数的触发器在表达式中的最小时间段内评估一次。例如,像这样的触发器

trendavg(/host/key,1d:now/d) > 1 或 trendavg(/host/key2,1w:now/w) > 2

将每天评估一次。如果触发器同时包含趋势和历史(或基于时间)函数,则按照通常原则进行计算。

这里列出的所有函数都在以下方面得到支持:

这些函数仅列出,未提供额外信息。点击函数可查看完整详情。

函数 描述
baselinedev 返回最后一个数据周期与前几个季节中相同数据周期之间的偏差数(通过 stddevpop 算法)。
baselinewma 使用加权移动平均算法,通过对多个相等时间段(“季节”)中相同时间范围的数据进行平均来计算基线。
trendavg 定义时间段内趋势值的平均值。
trendcount 在定义时间段内用于计算趋势值的成功检索到的历史值的数量。
trendmax 定义时间段内趋势值的最大值。
trendmin 定义时间段内趋势值的最小值。
trendstl 返回检测期间的异常率 - 一个介于 0 和 1 之间的十进制值,即 ((异常值的数量)/(值的总数))
trendsum 定义时间段内趋势值的总和。
常用参数
  • /host/key 是常见的强制第一个参数
  • time period:time shift是常用的第二个参数,其中:
    • time period - 时间段(最小'1h'),定义为<N><time unit> 其中N - 时间单位数,time unit - h(小时) , d(日),w(周),M(月)或 y(年)。
    • time shift -时间段偏移(参见函数示例)

函数详情

关于函数参数的一般性说明:

  • 函数参数用逗号分隔
  • 可选函数参数(或参数部分)由< >表示
  • 每个函数都描述了特定的函数参数
  • /host/key(sec|#num)<:time shift>参数绝对不能加引号
baselinedev(/host/key,data period:time shift,season unit,num seasons)

返回上一个数据周期与前一时间段中相同数据周期之间的偏差数(通过stddevpop算法)。

参数:

  • 参见 常用参数
  • data period - 一个时间段内的数据收集周期,定义为<N><time unit>其中:
    N - 时间单位数
    time unit - h(小时) , d(日),w(周),M(月)或 y(年),必须等于或者小于时间周期
  • season unit - 一个时间段的持续时间 (h, d, w, M, y), 不能小于数据周期;
  • num seasons - 要评估的时间段数量。

示例:

baselinedev(/host/key,1d:now/d,"M",6) #calculating the number of standard deviations (population) between the previous day and the same day in the previous 6 months. If the date doesn't exist in a previous month, the last day of the month will be used (Jul,31 will be analysed against Jan,31, Feb, 28,... June, 30)
       baselinedev(/host/key,1h:now/h,"d",10)  #calculating the number of standard deviations (population) between the previous hour and the same hours over the period of ten days before yesterday
baselinewma(/host/key,data period:time shift,season unit,num seasons)

使用加权移动平均算法通过对多个相等时间段(‘seasons’)中的相同时间范围内的数据进行平均来计算基线。

参数:

  • 参见 常用参数
  • data period - 一个时间段内的数据收集周期,定义为<N><time unit>其中:
    N - 时间单位数
    time unit - h(小时) , d(日),w(周),M(月)或 y(年),必须等于或者小于时间周期
    Time shift - 时间段偏移,以时间周期为单位定义数据收集的结束时间(见示例);
  • season unit - 一个时间段的持续时间 (h, d, w, M, y), 不能小于数据周期;
  • num seasons - 要评估的时间周期数量。

示例:

baselinewma(/host/key,1h:now/h,"d",3) #calculating the baseline based on the last full hour within a 3-day period that ended yesterday. If "now" is Monday 13:30, the data for 12:00-12:59 on Friday, Saturday, and Sunday will be analyzed
       baselinewma(/host/key,2h:now/h,"d",3) #calculating the baseline based on the last two hours within a 3-day period that ended yesterday. If "now" is Monday 13:30, the data for 11:00-12:59 on Friday, Saturday, and Sunday will be analyzed
       baselinewma(/host/key,1d:now/d,"M",4) #calculating the baseline based on the same day of month as 'yesterday' in the 4 months preceding the last full month. If the required date doesn't exist, the last day of month is taken. If today is September 1st, the data for July 31st, June 30th, May 31st, April 30th will be analyzed.
trendavg(/host/key,time period:time shift)

在定义的时间段内趋势值的平均值。

参数:

示例:

trendavg(/host/key,1h:now/h) #the average for the previous hour (e.g. 12:00-13:00)
       trendavg(/host/key,1h:now/h-1h) #the average for two hours ago (11:00-12:00)
       trendavg(/host/key,1h:now/h-2h) #the average for three hours ago (10:00-11:00)
       trendavg(/host/key,1M:now/M-1y) #the average for the previous month a year ago
trendcount(/host/key, 时间周期:时间偏移)

在定义的时间段内用于计算趋势值的成功检索到的历史值的数量。

参数:

示例:

trendcount(/host/key,1h:now/h) # 上一小时的值数量(例如 12:00 - 13:00)
       trendcount(/host/key,1h:now/h - 1h) # 两小时前的值数量(11:00 - 12:00)
       trendcount(/host/key,1h:now/h - 2h) # 三小时前的值数量(10:00 - 11:00)
       trendcount(/host/key,1M:now/M - 1y) # 一年前的上一个月的值数量 
trendmax(/host/key,time period:time shift)

在定义的时间段内趋势值的最大值。

参数:

示例:

trendmax(/host/key,1h:now/h) #the maximum for the previous hour (e.g. 12:00-13:00)
       trendmax(/host/key,1h:now/h) - trendmin(/host/key,1h:now/h) → calculate the difference between the maximum and minimum values (trend delta) for the previous hour (12:00-13:00)
       trendmax(/host/key,1h:now/h-1h) #the maximum for two hours ago (11:00-12:00)
       trendmax(/host/key,1h:now/h-2h) #the maximum for three hours ago (10:00-11:00)
       trendmax(/host/key,1M:now/M-1y) #the maximum for the previous month a year ago
trendmin(/host/key,time period:time shift)

在定义的时间段内趋势值的最小值。

参数:

示例:

trendmin(/host/key,1h:now/h) #the minimum for the previous hour (e.g. 12:00-13:00)
       trendmax(/host/key,1h:now/h) - trendmin(/host/key,1h:now/h) → calculate the difference between the maximum and minimum values (trend delta) for the previous hour (12:00-13:00)
       trendmin(/host/key,1h:now/h-1h) #the minimum for two hours ago (11:00-12:00)
       trendmin(/host/key,1h:now/h-2h) #the minimum for three hours ago (10:00-11:00)
       trendmin(/host/key,1M:now/M-1y) #the minimum for the previous month a year ago
trendstl(/host/key,eval period:time shift,detection period,season,<deviations>,<devalg>,<s window>)

返回检测期间的异常率 - 一个介于 0 和 1 之间的十进制值,即((异常值的数量)/(值的总数))

参数:

  • 参见 常用参数
  • eval period - 必须分解的时间段 (最小 '1h'),定义为<N><time unit>其中:
    N - 时间单位数
    time unit - h(小时) , d(日),w(周),M(月)或 y(年)
  • detection period - 计算异常的评估期结束前的时间段(最小 '1h',不能长于评估期), 定义为<N><time unit>其中:
    N - 时间单位数
    time unit - h(小时) , d(日),w(周)
  • season - 预期重复模式("season")的最短时间段 (最小 '2h', 不能长于评估期, 评估期中的条目数必须大于结果频率的两倍(season/h)), 定义为<N><time unit>其中:
    N - 时间单位数
    time unit - h(小时) , d(日),w(周)
  • deviations - 要计为异常的偏差数(由devalg计算)(可以是小数),(必须大于或等于1,默认值为3);
  • devalg (必须用双引号括起来)-偏差算法,可以是stddevpop、stddevsamp或mad(默认值);
  • s window - 用于周期性提取的黄土窗口的跨度(滞后)(默认为10乘以评估期的条目数+1)

示例:

trendstl(/host/key,100h:now/h,10h,2h) #analyse the last 100 hours of trend data, find the anomaly rate for the last 10 hours of that period, expecting the periodicity to be 2h, the remainder series values of the evaluation period are considered anomalies if they reach the value of 3 deviations of the MAD of that remainder series
       trendstl(/host/key,100h:now/h-10h,100h,2h,2.1,"mad") #analyse the period of 100 hours of trend data, up to 10 hours ago, find the anomaly rate for that entire period expecting the periodicity to be 2h, the remainder series values of the evaluation period are considered anomalies if they reach the value of 2,1 deviations of the MAD of that remainder series
       trendstl(/host/key,100d:now/d-1d,10d,1d,4,,10) #analyse 100 days of trend data up to a day ago, find the anomaly rate for the period of last 10d of that period, expecting the periodicity to be 1d, the remainder series values of the evaluation period are considered anomalies if they reach the value of 4 deviations of the MAD of that remainder series, overriding the default span of the loess window for seasonal extraction of "10 * number of entries in eval period + 1" with the span of 10 lags
       trendstl(/host/key,1M:now/M-1y,1d,2h,,"stddevsamp") #analyse the previous month a year ago, find the anomaly rate of the last day of that period expecting the periodicity to be 2h, the remainder series values of the evaluation period are considered anomalies if they reach the value of 3 deviation of the sample standard deviation of that remainder series
trendsum(/host/key,time period:time shift)

在定义的时间段内趋势值的总和。

参数:

示例:

trendsum(/host/key,1h:now/h) #the sum for the previous hour (e.g. 12:00-13:00)
       trendsum(/host/key,1h:now/h-1h) #the sum for two hours ago (11:00-12:00)
       trendsum(/host/key,1h:now/h-2h) #the sum for three hours ago (10:00-11:00)
       trendsum(/host/key,1M:now/M-1y) #the sum for the previous month a year ago

参见 所有支持的函数