1 个不稳定版本

0.1.0 2023年9月21日

#24#datadog

MIT 许可证

22KB
410

狗尾

将 Datadog 日志输出到您的本地机器。

狗尾旨在让您使用您已经熟悉并喜爱的强大命令行工具来探索您项目的日志,因为无论 Datadog 多么好,没有地方比得上 $HOME

用法

运行 pods 并想按 pod 读取日志?(注意 RUST_LOG 的使用会导致 dogtail 日志打印到 stderr)

> RUST_LOG=dogtail=info dogtail "service:my-service env:production" -k attributes.tags.pod_name
2023-09-21 8:16:05.330957357  INFO dogtail Found 60 events to write, total written: 60
2023-09-21 8:16:05.331068639  INFO dogtail Started writing to file: my-service-deployment-bb5d459d4-hf7v9.log
2023-09-21 8:16:15.774211007  INFO dogtail Found 11 events to write, total written: 71

日志很嘈杂?只查看唯一的消息

? dogtail "env:production service:my-service" -m stdout -s | jq .attributes.message | huniq

重构,并想知道哪些日志比它们值得的噪音要多?此示例使用 nushell,并将文件作为中间步骤写入,因为像 uniq 这样的工具在输入流结束之前不能发出计数。

> dogtail "env: production service:my-service" -s
# Run for a while, then kill with ctrl-c
> cat output.log | jq .attributes.message | lines | uniq -c | sort-by count

安装

git clone ...
cargo install --path .

配置

狗尾需要访问一个 Datadog API 密钥和 APP 密钥 来查询日志。这些分别从环境变量 DD_API_KEYDD_APP_KEY 中获取。

用法细节

> dogtail --help
Tail datadog logs to files, or stdout

Usage: dogtail [OPTIONS] <QUERY_STRING>

Arguments:
  <QUERY_STRING>  A query string, the same as you would use in the UI, e.g. "service:my-service"

Options:
  -d, --domain <DOMAIN>            The domain to use for the API [default: api.datadoghq.eu]
  -m, --mode <MODE>                Mode - If file, log events will be partitioned by split_key and written to files, if stdout, logs will be written to stdout [default: file] [possible values: file, stdout]
  -k, --split-key <SPLIT_KEY>      If mode is file, this is the event attribute lookup key to use for partitioning logs. Uses json-pointer syntax, e.g. "attributes.tags.pod_name". Note that event tags are unpacked into a map, so you can use tags "attributes.tags.pod_name" for this purpose
      --format-file <FORMAT_FILE>  A file to load a formatting config from. The formatting config if a newline separated list of json-pointer keys - each output line will be the found value of each of those keys, joined by a space. If none is provided, a default logging format of "timestamp status message" will be used
  -s, --structured                 If true, structured json will be written to the output instead of formatted logs, with one event written per line
  -h, --help                       Print help
  -V, --version                    Print version

依赖项

~13–28MB
~422K SLoC