===cpu_util
读取"/cgroup/cpuacct/docker/"+contain_id+"/cpuacct.usage_percpu"中绑定核的cpu使用时间片(累计值,cpu_use_time),
cat /cgroup/cpuset/docker/b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb/cpuset.cpus
6-9
cat /cgroup/cpuacct/docker/b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb/cpuacct.usage_percpu
0 0 0 0 0 0 66238344197440 70824963617248 74983569233356 78846644169639 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
读取"/proc/stat"中对应核的cpu总时间片(累计值,cpu_total_time)
cat /proc/stat
cpu 748602637 100253 642640755 59115027509 617404 62194 46746998 0 0
......
cpu6 5917531 581 3271039 937040243 7577 0 60604 0 0
cpu7 5117588 239 2687069 938306300 5839 0 60538 0 0
cpu8 5565280 2357 3584801 936739202 5650 0 60437 0 0
cpu9 5295556 3968 3496022 936905600 7601 0 59572 0 0
......
间隔采样,使用率=cpu_use_time差值/cpu_total_time差值
===memory.usage
读取"/cgroup/memory/docker/"+contain_id+"/memory.stat"中 active_anon和 inactive_anon
cat /cgroup/memory/docker/b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb/memory.stat
cache 2484948992
rss 3240157184
mapped_file 14901248
pgpgin 2825935330
pgpgout 2832891427
swap 18874368
inactive_anon 550154240
active_anon 2690007040
......
cat /cgroup/memory/docker/b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb/memory.limit_in_bytes
8589934592
使用率= (active_anon+ inactive_anon)/分配的memory
===netio
读取"/proc/"+pid+"/net/dev"中对应网卡的In/Out的bytes/packets 累计值
cat /proc/11973/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 369299212872 329498342 0 0 0 0 0 0 369299212872 329498342 0 0 0 0 0 0
ns9a07c03c-2f: 262981028026 567054466 0 0 0 0 0 0 600088509350 658578900 0 0 0 0 0 0
间隔采样,速率=差值/采样间隔
===diskio
ls -l /dev/mapper/docker-contain_id查看对应挂载磁盘
ls -l /dev/mapper/docker-b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb
lrwxrwxrwx 1 root root 7 2月 22 16:57 /dev/mapper/docker-b57b1f091f0b517499a74d5b36f23e7f001cac2ebc0639e85c291b41da04edcb -> ../dm-1
读取‘/sys/block/‘+device+‘/stat‘中disk读写bytes/次数 累计值,io时间
cat /sys/block/dm-1/stat
2409 0 36434 5984 38847495 0 310779960 83760448 0 6256117 83778634
间隔采样,速率=差值/采样间隔,disk.util=io时间/采样间隔
===tcp.connections
统计"/proc/"+pid+"/net/tcp" 和 "/proc/"+pid+"/net/tcp6"中 连接建立状态的 连接个数,间隔抽样采集
===load
间隔(5s)统计"/cgroup/cpuacct/docker/" + contain_id + "/tasks" 中状态为running/disk-sleep/waiting的线程个数,
计算公式:load = pre_load * math.exp(-间隔时间/300) + cur_load * (1 - math.exp(-间隔时间/300))