您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關docker-monitor-injector工具算法的示例分析的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
工具介紹 docker-monitor-injector是攜程開源的一個修正docker容器內監控數據的工具,通過劫持open,fopen等linux庫函數,重算/proc/meminfo,/proc/stat等度量指標,使得容器內free,top等系統工具能正確統計容器性能指標。下面將對其進行源碼分析,并整理出各個數據的監控修正算法。
算法(偽碼)
/proc/uptime
reaperage: time(NULL) - lstat("/proc/1").st_ctime idletime: (reaperage - cpuacct.usage)/1000000000
/proc/meminfo
MemTotal: memory.limit_in_bytes memfree: memlimit - memusage swaptotal: memswlimit > 0 ? memswlimit - memlimit : 0 SwapFree: (memswlimit > 0 && memswusage > 0) ? (memswlimit - memlimit) - (memswusage - memusage):0 cached: memory.stat.total_cache Buffers: 0 SwapCached: 0 Slab: 0
/proc/stat
a.proc_stat_by_shares user_sum: cpuacct.stat.user system_sum: cpuacct.stat.system nice_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) idle_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) iowait_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) irq_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) softirq_sum:(_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) steal_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) guest_sum: (_self*cpu.shares/1024)/sysconf(_SC_NPROCESSORS_ONLN) 任一cpu stat值算法如下: x = x_sum/sysconf(_SC_NPROCESSORS_ONLN),x_sum為上述任一指標
b.flush_proc_stat_by_cpusets
btime: stat("/proc/1").st_ctime user_sum, nice_sum, system_sum, idle_sum, iowait_sum, irq_sum, softirq_sum, steal_sum, guest_sum = 容器所擁有cpu id在/proc/stat中對應值之和。
/proc/cpuinfo
若容器綁定cpu,只輸出綁定cpu id對應cpu info信息 否則,全部輸出
/sys/devices/system/cpu/online
//經過驗證,該算法應該是有缺陷的,不作分析。
/proc/diskstats
read = blkio.io_serviced:major:minor:Read write = blkio.io_serviced:major:minor:Write read_merged = blkio.io_merged:major:minor:Read write_merged=blkio.io_merged:major:minor:Write read_sectors= blkio.io_service_bytes:major:minor:Read/512 write_sectors= blkio.io_service_bytes:major:minor:Write)/512 rd_svctm = blkio.io_service_time:major:minor:Read/1000000 rd_wait = get_blkio_io_value(blkio.io_wait_time:major:minor:Read)/1000000 read_ticks = rd_svctm + rd_wait wr_svctm = blkio.io_service_time:major:minor:Write/1000000 wr_wait = blkio.io_wait_time:major:minor:Write/1000000; write_ticks = wr_svctm + wr_wait tot_ticks = blkio.io_service_time:major:minor:Total/1000000 ... if (read || write || read_merged || write_merged || read_sectors || write_sectors || read_ticks || write_ticks) { snprintf(lbuf, 256, "%u %u %s %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", major, minor, dev_name, read, read_merged, read_sectors, read_ticks, write, write_merged, write_sectors, write_ticks, ios_pgr, tot_ticks, rq_ticks);
感謝各位的閱讀!關于“docker-monitor-injector工具算法的示例分析”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。