Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of docker-monitor-injector tool algorithm

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article shares the content of an example analysis of the docker-monitor-injector tool algorithm. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Docker-monitor-injector is a tool for correcting docker container monitoring data by Ctrip Open Source. By hijacking open,fopen and other linux library functions, recalculating/proc/meminfo,/proc/stat and other metrics, system tools such as free and top in the container can correctly count container performance indicators. The following will analyze its source code and sort out the monitoring and correction algorithms for each data.

Algorithm (pseudo-code)

/proc/uptime

reaperage: time(NULL) - lstat("/proc/1").st_ctimeidletime: (reaperage - cpuacct.usage)/1000000000

/proc/meminfo

MemTotal: memory.limit_in_bytesmemfree: memlimit - memusageswaptotal: memswlimit > 0 ? memswlimit - memlimit : 0SwapFree: (memswlimit > 0 && memswusage > 0) ? (memswlimit - memlimit) - (memswusage - memusage):0cached: memory.stat.total_cacheBuffers: 0SwapCached: 0Slab: 0

/proc/stat

a.proc_stat_by_sharesuser_sum: cpuacct.stat.usersystem_sum: cpuacct.stat.systemnice_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) Any cpu stat value is calculated as follows: x = x_sum/sysconf(_SC_NPROCESSORS_ONLN), x_sum is any of the above indicators

b.flush_proc_stat_by_cpusets

btime: stat("/proc/1").st_ctimeuser_sum, nice_sum, system_sum, idle_sum, iowait_sum, irq_sum, softirq_sum, steal_sum, guest_sum = sum of all cpu id's owned by the container in/proc/stat.

/proc/cpuinfo

If the container is bound to cpu, only output the cpu info information corresponding to the bound cpu id. Otherwise, output all of them.

/sys/devices/system/cpu/online

//After verification, the algorithm should be defective and not analyzed.

/proc/diskstats

read = blkio.io_serviced:major:minor:Readwrite = blkio.io_serviced:major:minor:Writeread_merged = blkio.io_merged:major:minor:Readwrite_merged=blkio.io_merged:major:minor:Writeread_sectors= blkio.io_service_bytes:major:minor:Read/512write_sectors= blkio.io_service_bytes:major:minor:Write)/512rd_svctm = blkio.io_service_time:major:minor:Read/1000000rd_wait = get_blkio_io_value(blkio.io_wait_time:major:minor:Read)/1000000read_ticks = rd_svctm + rd_waitwr_svctm = blkio.io_service_time:major:minor:Write/1000000wr_wait = blkio.io_wait_time:major:minor:Write/1000000;write_ticks = wr_svctm + wr_waittot_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\n",major, minor, dev_name, read, read_merged, read_ticks,write, write_merged, write_sectors, write_ticks, ios_pgr, tot_ticks, rq_ticks); Thank you for reading! About "docker-monitor-injector tool algorithm example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report