system.disk Metrics from DataDog Agent

Name

  • system.disk.total
  • KB (unit)
  • The total amount of disk space.
  • system.disk.used
  • KB (unit)
  • The amount of disk space in use.
  • system.disk.free
  • KB (unit)
  • The amount of disk space that is free.
  • system.disk.in_use
  • fraction (unit)
  • The amount of disk space in use as a fraction of the total.
  • system.disk.read_time_pct
  • percent
  • Percent of time spent reading from disk.
  • system.disk.write_time_pct
  • percent
  • Percent of time spent writing to disk.

计算方式

  1. 通过Python的第三方模块psutil(process and system utilities)来实现
import psutil

# parts = [sdiskpart(device='rootfs', mountpoint='/', fstype='rootfs', opts='rw')]
parts = psutil.disk_partitions(all=True)
for part in parts:
    # sdiskusage(total=10725883904, used=713650176, free=10012233728, percent=6.7)
    disk_usage = psutil.disk_usage(part.mountpoint)

    system.disk.total = disk_usage.total / 1024
    system.disk.used = disk_usage.used / 1024
    system.disk.free = disk_usage.free / 1024
    system.disk.in_use = disk_usage.percent / 100.0

system.disk.read_time_pct和system.disk.wirte_time_pct只有当psutil可用时,才存在。

import psutil

# {'dm-83': sdiskio(read_count=262, write_count=46, read_bytes=4603904, write_bytes=2357760, read_time=19, write_time=1101, read_merged_count=0, write_merged_count=0, busy_time=1102)}
disk_dict = psutil.disk_io_counters(True)
for disk_name, disk in disk_dict.items():
    read_time_pct = disk.read_time * 100.0 / 1000.0
    write_time_pct = disk.write_time * 100.0 / 1000.0
    # RATE: 函数,(当前采集值 - 上一个采集值) / 采集时间差
    system.disk.read_time_pct = RATE(read_time_pct)
    system.disk.wirte_time_pct = RATE(write_time_pct)
  1. 如果没有psutil,通过df -T -k命令采集。
# device is
# ["/dev/xvda1", "xfs", 209703916, 53188672, 156515244, "26%", "/"]
used = device[3]
free = device[4]
system.disk.used = used
system.disk.free = free
system.disk.total = device[2]
system.disk.in_use = used / (used + free)
df -T -k

Filesystem         Type     1K-blocks     Used Available Use% Mounted on
/dev/xvda1         xfs      209703916 53188672 156515244  26% /

你可能感兴趣的:(system.disk Metrics from DataDog Agent)