监控采集

system.disk Metrics from DataDog

2018-08-29  本文已影响45人  xufeibuaa

Name

  • KB (unit)
  • The total amount of disk space.
  • KB (unit)
  • The amount of disk space in use.
  • KB (unit)
  • The amount of disk space that is free.
  • fraction (unit)
  • The amount of disk space in use as a fraction of the total.
  • percent
  • Percent of time spent reading from disk.
  • 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% /
上一篇下一篇

猜你喜欢

热点阅读