File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -415,6 +415,30 @@ curl -XPOST "http://${deepflow_server_node_ip}:${port}/v1/query/" \
415415 --data-urlencode "sql=select attribute.cluster, body from log where attribute.cluster='Production'"
416416```
417417
418+ ### 基于日志构建指标序列
419+
420+ 如果应用里带了一些运行时指标信息,比如 ` nginx ` 记录了请求时延,同样地,也可以使用 Transforms 的 Remap 模块,写一段注入指标的代码,其中,我们要求自定义标签必须写入 ` .metrics ` 结构体内,才能被存储、查询,示例如下:
421+
422+ ``` yaml
423+ transforms :
424+ inject_json_tags :
425+ type : remap
426+ inputs :
427+ - remap_kubernetes_logs
428+ source : |-
429+ .metrics = {
430+ "response_duration": xxx, # FIXME: 把从日志中提取到的指定数据添加到此处
431+ }
432+ ` ` `
433+
434+ 然后,在使用 [SQL API](../../output/query/sql) 查询时,我们可以使用如下语句搜索指定的指标,同样,指标也支持此文档中的 [聚合算子](../../../features/universal-map/metrics-and-operators):
435+
436+ ` ` ` bash
437+ curl -XPOST "http://${deepflow_server_node_ip}:${port}/v1/query/" \
438+ --data-urlencode "db=application_log" \
439+ --data-urlencode "sql=select metrics.response_duration from log"
440+ ```
441+
418442### 提取分布式追踪 ID
419443
420444如果应用具有分布式追踪能力,无论是做了 [ OTel] ( https://opentelemetry.io/docs/concepts/instrumentation/ ) 插桩或者应用中天然存在具有唯一性的全局流水号,且输出到日志中,同样可以上报到后端,把分布式追踪请求链路与日志关联起来。例如:将日志中的 ` TID:xxx ` 提取为 trace_id 的示例如下:
@@ -476,6 +500,9 @@ transforms:
476500 "cluster": "Production",
477501 "module": "nginx"
478502 }
503+ .metrics = {
504+ "ready_status": 1,
505+ }
479506sinks :
480507 http :
481508 encoding :
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ DeepFlow 的指标对外提供 PromQL 查询时,指标名称遵循 `${database
7676基于 PromQL 直接查询或编写告警规则时,目前已知的限制如下:
7777
7878- 无法通过` ~/!~ ` 正则搜索 metrics 名称
79- - 对 DeepFlow 提供的指标,必须先通过 [ appregation operator] ( https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators ) 确定聚合求值方式,再进行具体的指标查询。其中,` stdvar ` 、` topk ` 、 ` bottomk ` 、 ` quantile ` 这几个函数尚未支持,将会在后续的迭代中继续支持。
79+ - 对 DeepFlow 提供的指标,必须先通过 [ appregation operator] ( https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators ) 确定聚合求值方式,再进行具体的指标查询。其中,` stdvar ` 、` quantile ` 这几个函数尚未支持,将会在后续的迭代中继续支持。
8080
8181# 基于 PromQL 查询 DeepFlow 指标
8282
You can’t perform that action at this time.
0 commit comments