跳转至

Log Streaming



启动一个 HTTP Server,接收日志文本数据,上报到观测云。HTTP URL 固定为:/v1/write/logstreaming,即 http://Datakit_IP:PORT/v1/write/logstreaming

注:如果 DataKit 以 DaemonSet 方式部署在 Kubernetes 中,可以使用 Service 方式访问,地址为 http://datakit-service.datakit:9529

配置

进入 DataKit 安装目录下的 conf.d/log 目录,复制 logstreaming.conf.sample 并命名为 logstreaming.conf。示例如下:

[inputs.logstreaming]
  ignore_url_tags = false

  ## Threads config controls how many goroutines an agent cloud start to handle HTTP request.
  ## buffer is the size of jobs' buffering of worker channel.
  ## threads is the total number fo goroutines at running time.
  # [inputs.logstreaming.threads]
  #   buffer = 100
  #   threads = 8

  ## Storage config a local storage space in hard dirver to cache trace data.
  ## path is the local file path used to cache data.
  ## capacity is total space size(MB) used to store data.
  # [inputs.logstreaming.storage]
  #   path = "./log_storage"
  #   capacity = 5120

配置好后,重启 DataKit 即可。

目前可以通过 ConfigMap 方式注入采集器配置来开启采集器。

支持参数

Log-Streaming 支持在 HTTP URL 中添加参数,对日志数据进行操作。参数列表如下:

  • type:数据格式,目前只支持 influxdbfirelens
    • typeinflxudb 时(/v1/write/logstreaming?type=influxdb),说明数据本身就是行协议格式(默认 precision 是 s),将只添加内置 Tags,不再做其他操作
    • typefirelens 时 (/v1/write/logstreaming?type=firelens),数据格式应是 JSON 格式的多条日志
    • 当此值为空时,会对数据做分行和 Pipeline 等处理
  • source:标识数据来源,即行协议的 measurement。例如 nginx 或者 redis/v1/write/logstreaming?source=nginx
    • typeinfluxdb 时,此值无效
    • 默认为 default
  • service:添加 service 标签字段,例如(/v1/write/logstreaming?service=nginx_service
    • 默认为 source 参数值。
  • pipeline:指定数据需要使用的 pipeline 名称,例如 nginx.p/v1/write/logstreaming?pipeline=nginx.p
  • tags:添加自定义 tag,以英文逗号 , 分割,例如 key1=value1key2=value2/v1/write/logstreaming?tags=key1=value1,key2=value2

FireLens 数据源类型

该类型数据中的 log, source, date 字段将会特殊处理,数据示例:

[
  {
    "date": 1705485197.93957,
    "container_id": "xxxxxxxxxxx-xxxxxxx",
    "container_name": "nginx_demo",
    "source": "stdout",
    "log": "127.0.0.1 - - [19/Jan/2024:11:49:48 +0800] \"GET / HTTP/1.1\" 403 162 \"-\" \"curl/7.81.0\"",
    "ecs_cluster": "Cluster_demo"
  },
  {
    "date": 1705485197.943546,
    "container_id": "f68a9aeb3d64493595e89f8821fa3f86-4093234565",
    "container_name": "javatest",
    "source": "stdout",
    "log": "2024/01/19 11:49:48 [error] 1316#1316: *1 directory index of \"/var/www/html/\" is forbidden, client: 127.0.0.1, server: _, request: \"GET / HTTP/1.1\", host: \"localhost\"",
    "ecs_cluster": "Cluster_Demo"
  }
]

在提取出列表中的两条日志后,其中 log 将作为数据的 message 字段,date 将转换为日志的时间,source 将被重命名为 firelens_source

使用方式

  • Fluentd 使用 Influxdb Output 文档
  • Fluentd 使用 HTTP Output 文档
  • Logstash 使用 Influxdb Output 文档
  • Logstash 使用 HTTP Output 文档

只需要将 Output Host 配置为 Log-Streaming URL(http://Datakit_IP:PORT/v1/write/logstreaming)并添加对应参数即可。

日志

default

Using source field in the config file, default is default.

  • 标签
Tag Description
ip_or_hostname Request IP or hostname.
service Service name. Using the service parameter in the URL.
  • 指标列表
Metric Description Type Unit
message Message text, existed when default. Could use Pipeline to delete this field. string -
status Log status. string -

文档评价

文档内容是否对您有帮助? ×