Get the App
SLTechnology News&Howtos  ›  Servers  › 

Example Analysis of docker-monitor-injector tool algorithm

Shulou Source: shulou.com Published: 2022-05-31 20:01:30 10月03日 Update

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!

Tags: Algorithms tools containers analysis indicators examples content data more articles any monitoring output good practical sum information functions will be right performance Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Docker Redmi Shulou Information