数据与AI
用 Dynatrace 做时序预测与异常检测时…
在 Dynatrace 中对主机、服务、基础设施做容量预测、趋势/变化点检测与异常判定时,按问题类型选择正确的分析工具与 DQL 模式。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
用 Dynatrace 做时序预测与异常特定
解决思路
- 先判断问题类型:问『这个指标是否发生了变化/何时变化』用 timeseries-novelty-detection;问『当前是否越界/谁在违规』用异常检测器(adaptive、seasonal、static)。
- 当问题包含 changed、shifted、spiked、dropped、started、when did、did anything unusual happen 时,使用 timeseries-novelty-detection,它无需预设阈值即可回答是否变化及何时变化。
- 当问题涉及当前或持续状态(which are highest、who is violating、what is above X)时,使用 adaptive-anomaly-detector、seasonal-baseline-anomaly-detector 或 static-threshold-analyzer,它们在滑动窗口内统计违规样本数以确认持续时长。
- 检测具体变化类型:用 SPIKE / CHANGE_IN_VALUES 找出发生变化的实体和时间戳(稳定信号返回空);用 TREND_IN_VALUES 定位方向性变化的起点。
- 已知固定阈值(如 CPU > 90%)时用 static-threshold-analyzer;判断服务是否高于其常态负载用 adaptive-anomaly-detector;判断是否偏离周模式用 seasonal-baseline-anomaly-detector。
- 避免在大范围集群上直接跑 adaptive-anomaly-detector 来回答『哪个服务负载变化了』,它会标记所有有波动的服务;应先用 timeseries-novelty-detection 找出真正发生特性变化的实体,再用异常检测器量化严重程度。
- 做前瞻性预测时使用 timeseries-forecast 工具(DQL 无原生 forecast 函数),注意 Dynatrace Forecast Analyzer 仅支持单变量预测;多变量预测需借助 Python、R、Azure AutoML 等外部工具。
- 所有分析通过 Dynatrace 工具执行:timeseries-forecast、adaptive-anomaly-detector、seasonal-baseline-anomaly-detector、static-threshold-analyzer、timeseries-novelty-detection;DQL 查询用 execute-dql。
- 始终直接从原始工具输出中分析并汇总结果,所有数字、趋势和结论都在结果内联推导。
- 预测结果统一用结构化表格呈现:Rank(🥇🥈🥉 按紧急度或幅度排序)、Signal/Entity(指标名与实体或维度)、Last Actual(历史序列中最近的非空值)、Forecast(预测期末点预测值)、Range(同一预测点的置信区间上下界)、Trend(Last Actual 到 Forecast 的百分比变化:🔴 >+20% / 🟠 +5–20% / 🟢 ±5% 稳定 / 🔵 −5–20% 下降 / ⚫ <−20% 骤降)、Action(✅ 无需动作 / ⚠️ 监控 / 🔴 立即处理)。
- 表格后必须附 Key Findings 小节,3–5 条按优先级排序的要点。
- 编写 DQL 时遵守关键规则:timeseries 返回数组(每个时间槽每个实体一个值);arrayLast(arr) 取最新值,arrayFirst(arr) 取最旧值;增长率 = (arrayLast - arrayFirst) / 间隔数;排序前先 filter isNotNull(field) 避免空值排序问题;除法涉及 Long 字段时用 toLong() 避免类型错误;显示字段用 dt.smartscape.* 而非已弃用的 dt.entity.*,实体级查询的 by:{} 分组也用 dt.smartscape.*。
- 移动平均趋势模式:timeseries cpu = avg(dt.host.cpu.usage), from: now()-24h, interval: 1h, by: {dt.smartscape.host} | fieldsAdd moving_avg = arrayMovingAvg(cpu, 4) | fieldsAdd current = arrayLast(cpu) | fieldsAdd trend = arrayLast(cpu) - arrayFirst(cpu) | filter isNotNull(current) | sort trend desc | limit 20 | fields dt.smartscape.host, current, trend, moving_avg。
- 饱和风险分类模式:timeseries cpu = avg(dt.host.cpu.usage), from: now()-7d, interval: 1h, by: {dt.smartscape.host} | fieldsAdd p95 = arrayPercentile(cpu, 95) | fieldsAdd saturation_risk = if(p95 > 85, "HIGH", else: if(p95 > 70, "MEDIUM", else: "LOW")) | filter isNotNull(p95) | sort p95 desc | fields dt.smartscape.host, p95, saturation_risk。
- 距饱和天数预测模式:timeseries cpu = avg(dt.host.cpu.usage), from: now()-30d, interval: 1d, by: {dt.smartscape.host} | fieldsAdd current = arrayLast(cpu) | fieldsAdd daily_growth = (arrayLast(cpu) - arrayFirst(cpu)) / 30 | filter isNotNull(current) | fieldsAdd days_to_saturation = if(daily_growth > 0, toLong((90 - current) / daily_growth), else: 9999) | sort days_to_saturation asc | limit 20 | fields dt.smartscape.host, current, daily_growth, days_to_saturation。
- 异常评分模式:timeseries cpu = avg(dt.host.cpu.usage), from: now()-24h, interval: 1h, by: {dt.smartscape.host} | fieldsAdd baseline_avg = arrayAvg(cpu) | fieldsAdd current = arrayLast(cpu) | fieldsAdd anomaly_score = if(isNotNull(current) and isNotNull(baseline_avg), abs(current - baseline_avg), else: 0) | sort anomaly_score desc | limit 20 | fields dt.smartscape.host, current, baseline_avg, anomaly_score。
- 预测前先做指标发现:metrics from: now() - 1h | filter contains(metric.key, "cpu") | summarize count(), by: {metric.key} | sort `count()` desc。
- 参考指南:forecasting-analyzer.md(timeseries-forecast 的数据要求、参数、间隔选择、horizon 限制与常见陷阱)、capacity-forecasting.md(CPU/内存/磁盘/K8s 饱和预测、多资源风险评分、距饱和 DQL 模式)、anomaly-scoring.md(三种异常检测器与 DQL 偏差评分)、novelty-detection.md(spike、drop、step change、trend onset、variability change 全部 novelty 类型与参数)、trend-detection.md(趋势起点与变化点、周同比 join、增长率与加速度检测)。
适用边界 · 注意事项
- 需要多变量预测(用多个指标作为输入)时,Dynatrace Forecast Analyzer 不支持,需改用 Python、R、Azure AutoML 等外部工具。
- 在大范围集群上直接跑 adaptive-anomaly-detector 来回答『哪个服务负载变化了』,会标记所有有波动的服务,产生低信号结果。
- DQL 没有原生 forecast 函数,不要试图用 DQL 直接做前瞻性预测,应使用 timeseries-forecast 工具。