跳转至

ConfigWatcher


ConfigWatcher 采集器支持监控文件或目录的内容变更,构建变更事件数据并上报观测云平台。

配置

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

[[inputs.configwatcher]]
  ## Require. A name for this collection task for identification.
  source = "default"

  ## The root path to prepend to all monitored paths (e.g., for container host paths).
  ## Use "/rootfs" for the mount point in Kubernetes.
  mount_point = ""

  ## An array of files or directories to monitor for changes.
  ## Note: Wildcards (e.g., '/path/*.log') are not supported.
  paths = [
      # "/var/spool/cron/crontabs/",          # for entire directory
      # "/etc/hosts",                         # for specific file
  ]

  ## The interval at which to check for changes.
  interval = "5m"

  ## Whether to recursively monitor directories in the provided paths.
  recursive = true

  ## The maximum file size (in bytes) for which to compute content diffs, default is 256KiB.
  max_diff_size = 262144

  [inputs.configwatcher.tags]
  # some_tag = "some_value"
  # more_tag = "some_other_value"

配置好后,重启 DataKit 即可。

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

示例配置 Crontab

下面是监控 Crontab 文件的示例,配置如下:

[[inputs.configwatcher]]
  ## Require. A name for this collection task for identification.
  task_name = "Crontab"

  ## An array of file paths to monitor for changes.
  paths = [
      "/var/spool/cron/crontabs",
  ]

  ## The interval at which to check for changes.
  interval = "3m"

  ## Whether to recursively monitor directories in the provided paths.
  recursive = true

  ## The maximum file size (in bytes) for which to compute content diffs, default is 256KiB.
  max_diff_size = 262144

在 Linux 命令行执行 crontab -e 命令修改 Crontab 任务,采集器能发现到对应文件的变更。

FAQ

  • 采集器忽略文件的权限、所有者变更,只监控内容变更
  • 变更事件的时间取自文件的 ModTime,不是系统时间
  • 如果文件 size 超过 max_diff_size,不比较新旧文件的差异

文档评价

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