DataKit 主配置¶
DataKit 主配置用来配置 DataKit 自己的运行行为。
Datakit 主配置示例¶
Datakit 主配置示例如下,我们可以根据该示例来开启各种功能(当前版本 1.16.0):
datakit.conf
################################################
# Global configures
################################################
# Default enabled input list.
default_enabled_inputs = [
"cpu",
"disk",
"diskio",
"host_processes",
"hostobject",
"mem",
"net",
"swap",
"system",
]
# enable_pprof: bool
# If pprof enabled, we can profiling the running datakit
enable_pprof = true
pprof_listen = "localhost:6060" # pprof listen
# protect_mode: bool, default false
# When protect_mode eanbled, we can set radical collect parameters, these may cause Datakit
# collect data more frequently.
protect_mode = true
################################################
# ulimit: set max open-files limit(Linux only)
################################################
ulimit = 64000
################################################
# DCA configure
################################################
[dca]
# Enable or disable DCA
enable = false
# set DCA HTTP api server
listen = "0.0.0.0:9531"
# DCA client white list(raw IP or CIDR ip format)
# Example: [ "1.2.3.4", "192.168.1.0/24" ]
white_list = []
################################################
# Pipeline
################################################
[pipeline]
# IP database type, support iploc and geolite2
ipdb_type = "iploc"
# How often to sync remote pipeline
remote_pull_interval = "1m"
#
# reftab configures
#
# Reftab remote HTTP URL(https/http)
refer_table_url = ""
# How often reftab sync the remote
refer_table_pull_interval = "5m"
# use sqlite to store reftab data to release memory usage
use_sqlite = false
# or use pure memory to cache the reftab data
sqlite_mem_mode = false
# Offload data processing tasks to post-level data processors.
[pipeline.offload]
receiver = "datakit-http"
addresses = [
# "http://<ip>:<port>"
]
################################################
# HTTP server(9529)
################################################
[http_api]
# HTTP server address
listen = "localhost:9529"
# Disable 404 page to hide detailed Datakit info
disable_404page = false
# only enable these APIs. If list empty, all APIs are enabled.
public_apis = []
# Datakit server-side timeout
timeout = "30s"
close_idle_connection = false
#
# RUM related: we should port these configures to RUM inputs(TODO)
#
# When serving RUM(/v1/write/rum), extract the IP address from this HTTP header
rum_origin_ip_header = "X-Forwarded-For"
# When serving RUM(/v1/write/rum), only accept requests from these app-id.
# If the list empty, all app's requests accepted.
rum_app_id_white_list = []
################################################
# io configures
################################################
[io]
# How often Datakit flush data to dataway.
# Datakit will upload data points if cached(in memory) points
# reached(>=) the max_cache_count or the flush_interval triggered.
max_cache_count = 1000
flush_workers = 0 # default to (cpu_core * 2 + 1)
flush_interval = "10s"
# We can write these data points into file in line-proto format(truncated at 32MB).
output_file = ""
# only these input data points write to file. If list empy and output_file set,
# all points are write to the file.
output_file_inputs = []
# Disk cache on datakit upload failed
enable_cache = false
# Cache all categories data point into disk
cache_all = false
# Max disk cache size(in GB), if cache size reached
# the limit, old data dropped(FIFO).
cache_max_size_gb = 10
# Cache clean interval: Datakit will try to clean these
# failed-data-point at specified interval.
cache_clean_interval = "5s"
# Data point filter configures.
# NOTE: Most of the time, you should use web-side filter, it's a debug helper for developers.
#[io.filters]
# logging = [
# "{ source = 'datakit' or f1 IN [ 1, 2, 3] }"
# ]
# metric = [
# "{ measurement IN ['datakit', 'disk'] }",
# "{ measurement CONTAIN ['host.*', 'swap'] }",
# ]
# object = [
# { class CONTAIN ['host_.*'] }",
# ]
# tracing = [
# "{ service = re("abc.*") AND some_tag CONTAIN ['def_.*'] }",
# ]
################################################
# Dataway configure
################################################
[dataway]
# urls: Dataway URL list
# NOTE: do not configure multiple URLs here, it's a deprecated feature.
urls = ["https://openway.guance.com?token=tkn_xxxxxxxxxxx"]
# Dataway HTTP timeout
timeout_v2 = "30s"
# HTTP Proxy(IP:Port)
http_proxy = ""
max_idle_conns = 0 # limit idle TCP connections for HTTP request to Dataway
enable_httptrace = false # enable trace HTTP metrics(connection/NDS/TLS and so on)
idle_timeout = "90s" # not-set, default 90s
# Customer tag or field keys that will extract from exist points
# to build the X-Global-Tags HTTP header value.
global_customer_keys = []
enable_sinker = false # disable sinker
################################################
# Datakit logging configure
################################################
[logging]
# log path
log = "/var/log/datakit/log"
# HTTP access log
gin_log = "/var/log/datakit/gin.log"
# level level(info/debug)
level = "info"
# Disable log color
disable_color = false
# log rotate size(in MB)
# DataKit will always keep at most n+1(n backup log and 1 writing log) splited log files on disk.
rotate = 32
# Upper limit count of backup log
rotate_backups = 5
################################################
# Global tags
################################################
# We will try to add these tags to every collected data point if these
# tags do not exist in orignal data.
#
# NOTE: we can get the real IP of current note, we just need
# to set "$datakit_ip" or "__datakit_ip" here. Same for the hostname.
[global_host_tags]
ip = "$datakit_ip"
host = "$datakit_hostname"
[election]
# Enable election
enable = false
# Election namespace.
# NOTE: for single workspace, there can be multiple election namespace.
namespace = "default"
# If enabled, every data point will add a tag with election_namespace = <your-election-namespace>
enable_namespace_tag = false
# Like global_host_tags, but only for data points that are remotely collected(such as MySQL/Nginx).
[election.tags]
# project = "my-project"
# cluster = "my-cluster"
###################################################
# Tricky: we can rename the default hostname here
###################################################
[environments]
ENV_HOSTNAME = ""
################################################
# resource limit configures
################################################
[resource_limit]
# enable or disable resource limit
enable = true
# Linux only, cgroup path
path = "/datakit"
# set max CPU usage(%, max 100.0, no matter how many CPU cores here)
cpu_max = 30.0
# set max memory usage(MB)
mem_max_mb = 4096
################################################
# git_repos configures
################################################
# We can hosting all input configures on git server
[git_repos]
# git pull interval
pull_interval = "1m"
# git repository settings
[[git_repos.repo]]
# enable the repository or not
enable = false
# the branch name to pull
branch = "master"
# git repository URL. There are 3 formats here:
# - HTTP(s): such as "https://github.datakit.com/path/to/datakit-conf.git"
# - Git: such as "git@github.com:path/to/datakit.git"
# - SSH: such as "ssh://git@github.com:9000/path/to/repository.git"
url = ""
# For formats Git and SSH, we need extra configures:
ssh_private_key_path = ""
ssh_private_key_password = ""
HTTP 服务的配置¶
DataKit 会开启 HTTP 服务,用来接收外部数据,或者对外提供基础的数据服务。
修改 HTTP 服务地址¶
默认的 HTTP 服务地址是 localhost:9529
,如果 9529 端口被占用,或希望从外部访问 DataKit 的 HTTP 服务(比如希望接收 RUM 或 Tracing 数据),可将其修改成:
注意,IPv6 支持需 Datakit 升级到 1.5.7。
使用 Unix domain socket¶
Datakit 支持 UNIX domain sockets 访问。开启方式如下:listen
字段配置为一个不存在文件的全路径,这里以 datakit.sock
举例,可以为任意文件名。
curl
命令测试是否配置成功:sudo curl --no-buffer -XGET --unix-socket /tmp/datakit.sock http:/localhost/v1/ping
。更多关于 curl
的测试命令的信息可以参阅这里。
HTTP 请求频率控制¶
由于 DataKit 需要大量接收外部数据写入,为了避免给所在节点造成巨大开销,可修改如下 HTTP 配置(默认不开启):
其它设置¶
参见这里
全局标签(Tag)修改¶
Datakit 允许给其采集的所有数据配置全局标签,全局标签分为两类:
- 主机类全局标签:采集的数据跟当前主机绑定,比如 CPU/内存等指标数据
- 选举类全局标签:采集的数据来自某个公共(远程)实体,比如 MySQL/Redis 等,这些采集一般都参与选举,故这些数据上不会带上当前主机相关的标签
[global_host_tags]
ip = "__datakit_ip"
host = "__datakit_hostname"
[election]
[election.tags]
project = "my-project"
cluster = "my-cluster"
加全局 Tag 时,有几个地方要注意:
-
这些全局 Tag 的值可以用 DataKit 目前已经支持的几个变量(双下划线(
__
)前缀和$
都是可以的):__datakit_ip/$datakit_ip
:标签值会设置成 DataKit 获取到的第一个主网卡 IP__datakit_hostname/$datakit_hostname
:标签值会设置成 DataKit 的主机名
-
由于 DataKit 数据传输协议限制,不要在全局标签(Tag)中出现任何指标(Field)字段,否则会因为违反协议导致数据处理失败。具体参见具体采集器的字段列表。当然,也不要加太多 Tag,而且每个 Tag 的 Key 以及 Value 长度都有限制。
- 如果被采集上来的数据中,本来就带有同名的 Tag,那么 DataKit 不会再追加这里配置的全局 Tag
- 即使
global_host_tags
不配置任何全局 Tag,DataKit 仍然会在所有数据上尝试添加一个host=$HOSTNAME
的全局 Tag - 这俩类全局标签是可以有交集的,比如都可以在其中设置一个
project = "my-project"
的标签
全局 Tag 在远程采集时的设置¶
因为 DataKit 会默认给采集到的所有数据追加标签 host=<DataKit 所在主机名>
,但某些情况这个默认追加的 host
会带来困扰。
以 MySQL 为例,如果 MySQL 不在 DataKit 所在机器,但又希望这个 host
标签是被采集的 MySQL 的真实主机名(或云数据库的其它标识字段),而非 DataKit 所在的主机名。
对这种情况,我们有两种方式可以绕过 DataKit 上的全局 tag:
- 在具体采集器中,一般都有一个如下配置,我们可以在这里面新增 Tag,比如,如果不希望 DataKit 默认添加
host=xxx
这个 Tag,可以在这里覆盖这个 Tag,以 MySQL 为例:
- 以 HTTP API 方式往 DataKit 推送数据时,可以通过 API 参数
ignore_global_tags
来屏蔽所有全局 Tag
Tip
自 1.4.20 之后,DataKit 默认会以被采集服务的 IP/Host 等字段为 host
字段,故这一问题升级之后将得到改善。建议大家升级到该版本来避免这一问题。
DataKit 自身运行日志配置¶
DataKit 自身日志有两个,一个是自身运行日志(/var/log/datakit/log),一个是 HTTP Access 日志(/var/log/datakit/gin.log)。
DataKit 默认日志等级为 info
。编辑 datakit.conf
,可修改日志等级以及分片大小:
level
:置为debug
后,即可看到更多日志(目前只支持debug/info
两个级别)。rotate
:DataKit 默认会对日志进行分片,默认分片大小为 32MB,总共 6 个分片(1 个当前写入分片加上 5 个切割分片,分片个数尚不支持配置)。如果嫌弃 DataKit 日志占用太多磁盘空间(最多 32 x 6 = 192MB),可减少rotate
大小(比如改成 4,单位为 MB)。HTTP 访问日志也按照同样的方式自动切割。
高级配置¶
下面涉及的内容涉及一些高级配置,如果对配置不是很有把握,建议咨询我们的技术专家。
IO 模块调参¶
某些情况下,DataKit 的单机数据采集量非常大,如果网络带宽有限,可能导致部分数据的采集中断或丢弃。可以通过配置 io 模块的一些参数来缓解这一问题:
[io]
feed_chan_size = 4096 # 数据处理队列(一个 job 一般都有多个 point)长度
max_cache_count = 512 # 数据批量发送点数的阈值,缓存中超过该值即触发发送
flush_interval = "10s" # 数据发送的间隔阈值,每隔 10s 至少发送一次
flush_workers = 8 # 数据上传 worker 数(默认 CPU-core * 2 + 1)
阻塞模式参见 k8s 中的对应说明
参见这里
IO 磁盘缓存¶
当 DataKit 发送数据失败后,为了不丢失关键数据,可以开启磁盘缓存。磁盘缓存的目的在于将发送失败的数据暂时存入磁盘,待条件允许时,再将数据发送出去。
参见这里
Attention
这里的 cache_max_size_gb
指每个分类(Category)的缓存大小,总共 10 个分类的话,如果每个指定 5GB,理论上会占用 50GB 左右的空间。
资源限制¶
由于 DataKit 上处理的数据量无法估计,如果不对 DataKit 消耗的资源做物理限制,将有可能消耗所在节点大量资源。这里我们可以借助 Linux 的 cgroup 和 Windows 的 job object 来限制,在 datakit.conf 中有如下配置:
[resource_limit]
path = "/datakit" # Linux cgroup 限制目录,如 /sys/fs/cgroup/memory/datakit, /sys/fs/cgroup/cpu/datakit
# 允许 CPU 最大使用率(百分制)
cpu_max = 20.0
# 默认允许 4GB 内存(memory + swap)占用
# 如果置为 0 或负数,则不启用内存限制
mem_max_mb = 4096
如果 DataKit 超出内存限制后,会被操作系统强制杀掉,通过命令可以看到如下结果,此时需要手动启动服务:
$ systemctl status datakit
● datakit.service - Collects data and upload it to DataFlux.
Loaded: loaded (/etc/systemd/system/datakit.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: signal) since Fri 2022-02-30 16:39:25 CST; 1min 40s ago
Process: 3474282 ExecStart=/usr/local/datakit/datakit (code=killed, signal=KILL)
Main PID: 3474282 (code=killed, signal=KILL)
Attention
- 资源限制只在宿主机安装的时候会默认开启
- 只支持 CPU 使用率和内存使用量(mem+swap)控制,且只支持 Linux 和 windows ( Version-1.15.0) 操作系统。
Tip
Datakit 自 1.5.8 开始支持 cgroup v2。如果不确定 cgroup 版本,可通过命令 mount | grep cgroup
来确认。
选举配置¶
参见这里
DataWay Sinker 配置¶
参见这里
使用 Git 管理 DataKit 配置¶
参见这里
设置打开的文件描述符的最大值¶
Linux 环境下,可以在 Datakit 主配置文件中配置 ulimit
项,以设置 Datakit 的最大可打开文件数,如下:
ulimit 默认配置为 64000。在 Kubernetes 中,通过设置 ENV_ULIMIT
即可。
资源限制 CPU 使用率说明¶
CPU 使用率是百分比制(最大值 100.0),以一个 8 核心的 CPU 为例,如果限额 cpu_max
为 20.0(即 20%),则 DataKit 最大的 CPU 消耗,在 top 命令上将显示为 160% 左右。