search
数据采集 采集源配置 目录监控指标采集

目录监控指标采集

简介

采集目录监控数据指标上报到 DataFlux 中。

前置条件

配置

采集目录监控数据,需要调用系统命令 du,需创建脚本内容(如 /usr/local/cloudcare/dataflux/datakit/metrics-exec_du.sh),并添加当前用户的执行权限。

#!/bin/bash

du -bs "$@" | awk '{if (NR!=1) {printf "\n"};printf "du,path="$2" directory_size_bytes="$1"i";}'
echo

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

[[inputs.exec]]
    ## Commands array
    commands = [
      "/usr/local/cloudcare/dataflux/datakit/metrics-exec_du.sh /home/test/dir1 /home/test/dir2",
    ]

    ## Timeout for each command to complete.
    timeout = "5s"

    ## measurement name suffix (for separating different commands)
    name_suffix = "_dir"

    ## Data format to consume.
    ## Each data format has its own unique set of configuration options, read
    ## more about them here:
    ## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
    data_format = "influx"

关于指标:

measurement 默认为du加配置文件中的name_suffix; 指标path为 tag 类型; 指标directory_size_bytes为 fields 类型,单位为byte

示例数据

du_dir,host=ubt-server,path=/home/test/dir1 directory_size_bytes=453927206i 1589798100000000000
du_dir,host=ubt-server,path=/home/test/dir2 directory_size_bytes=2034020i 1589798100000000000

注意:如果监控采集的目录较大,du 命令会占用较多的运行资源