void disk_collect(char * tags) { int i, ret, tot; char read_sectors[16] = ""; char write_sectors[16] = ""; perfstat_disk_total_t data2; gettimeofday(&tv, NULL); ret = perfstat_disk_total(NULL, &data2, sizeof(perfstat_disk_total_t), 1); if (ret > 0) { sprintf(read_sectors, "%8llu", data2.rblks); sprintf(read_sectors, "%8llu", data2.wblks); sendCollectedData(tv.tv_sec, "iostat.part.read_sectors", read_sectors, tags); sendCollectedData(tv.tv_sec, "iostat.part.write_sectors", read_sectors, tags); } else { printf("perfstat_disk_total returns %d", ret); } }
static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = sysconf(_SC_PAGESIZE), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; perfstat_cpu_total_t cpustats; #ifdef _AIX61 perfstat_cpu_total_wpar_t cpustats_wpar; #endif perfstat_partition_total_t lparstats; perfstat_disk_total_t diskinfo; perfstat_netinterface_total_t netinfo; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HX(perfstat_cpu_total(NULL, &cpustats, sizeof(cpustats), 1) == -1, cpustats); #ifdef _AIX61 HX(perfstat_cpu_total_wpar(NULL, &cpustats_wpar, sizeof(cpustats_wpar), 1) == -1, cpustats_wpar); #endif HX(perfstat_partition_total(NULL, &lparstats, sizeof(lparstats), 1) == -1, lparstats); HX(perfstat_disk_total(NULL, &diskinfo, sizeof(diskinfo), 1) == -1, diskinfo); HX(perfstat_netinterface_total(NULL, &netinfo, sizeof(netinfo), 1) == -1, netinfo); for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) { HX((e = clock_gettime(cl[ii], &ts)) == -1, ts); if (e != -1) cnt += (int)ts.tv_nsec; } HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, min(sizeof(results), len - i)); i += min(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); if (gotdata(buf, len) == 0) { errno = save_errno; return 0; /* satisfied */ } errno = EIO; return -1; }
static void update_vmstat(ZBX_VMSTAT_DATA *vmstat) { #if defined(HAVE_LIBPERFSTAT) int now; zbx_uint64_t dlcpu_us, dlcpu_sy, dlcpu_id, dlcpu_wa, lcputime; perfstat_memory_total_t memstats; perfstat_cpu_total_t cpustats; perfstat_disk_total_t diskstats; #ifdef _AIXVERSION_530 zbx_uint64_t dpcpu_us, dpcpu_sy, dpcpu_id, dpcpu_wa, pcputime, dtimebase; zbx_uint64_t delta_purr, entitled_purr, unused_purr, r1, r2; perfstat_partition_total_t lparstats; #ifdef HAVE_AIXOSLEVEL_530006 zbx_uint64_t didle_donated_purr, dbusy_donated_purr, didle_stolen_purr, dbusy_stolen_purr; #endif /* HAVE_AIXOSLEVEL_530006 */ #endif /* _AIXVERSION_530 */ now = (int)time(NULL); /* retrieve the metrics * Upon successful completion, the number of structures filled is returned. * If unsuccessful, a value of -1 is returned and the errno global variable is set */ #ifdef _AIXVERSION_530 if (-1 == perfstat_partition_total(NULL, &lparstats, sizeof(lparstats), 1)) { zabbix_log(LOG_LEVEL_DEBUG, "perfstat_partition_total: %s", zbx_strerror(errno)); return; } #endif if (-1 == perfstat_cpu_total(NULL, &cpustats, sizeof(cpustats), 1)) { zabbix_log(LOG_LEVEL_DEBUG, "perfstat_cpu_total: %s", zbx_strerror(errno)); return; } if (-1 == perfstat_memory_total(NULL, &memstats, sizeof(memstats), 1)) { zabbix_log(LOG_LEVEL_DEBUG, "perfstat_memory_total: %s", zbx_strerror(errno)); return; } if (-1 == perfstat_disk_total(NULL, &diskstats, sizeof(diskstats), 1)) { zabbix_log(LOG_LEVEL_DEBUG, "perfstat_disk_total: %s", zbx_strerror(errno)); return; } if (last_clock && now > last_clock) { /* --- kthr --- */ vmstat->kthr_r = (double)(cpustats.runque - last_runque) / (double)(now - last_clock); vmstat->kthr_b = (double)(cpustats.swpque - last_swpque) / (double)(now - last_clock); /* --- page --- */ vmstat->fi = (double)(memstats.pgins - last_pgins) / (double)(now - last_clock); vmstat->fo = (double)(memstats.pgouts - last_pgouts) / (double)(now - last_clock); vmstat->pi = (double)(memstats.pgspins - last_pgspins) / (double)(now - last_clock); vmstat->po = (double)(memstats.pgspouts - last_pgspouts) / (double)(now - last_clock); vmstat->fr = (double)(memstats.cycles - last_cycles) / (double)(now - last_clock); vmstat->sr = (double)(memstats.scans - last_scans) / (double)(now - last_clock); /* -- faults -- */ vmstat->in = (double)(cpustats.devintrs - last_devintrs) / (double)(now - last_clock); vmstat->sy = (double)(cpustats.syscall - last_syscall) / (double)(now - last_clock); vmstat->cs = (double)(cpustats.pswitch - last_pswitch) / (double)(now - last_clock); #ifdef _AIXVERSION_530 /* --- cpu ---- */ dpcpu_us = lparstats.puser - last_puser; dpcpu_sy = lparstats.psys - last_psys; dpcpu_id = lparstats.pidle - last_pidle; dpcpu_wa = lparstats.pwait - last_pwait; delta_purr = pcputime = dpcpu_us + dpcpu_sy + dpcpu_id + dpcpu_wa; #endif /* _AIXVERSION_530 */ dlcpu_us = cpustats.user - last_user; dlcpu_sy = cpustats.sys - last_sys; dlcpu_id = cpustats.idle - last_idle; dlcpu_wa = cpustats.wait - last_wait; lcputime = dlcpu_us + dlcpu_sy + dlcpu_id + dlcpu_wa; #ifdef _AIXVERSION_530 /* Distribute the donated and stolen purr to the existing purr buckets in case if donation is enabled. */ #ifdef HAVE_AIXOSLEVEL_530006 if (lparstats.type.b.donate_enabled) { didle_donated_purr = lparstats.idle_donated_purr - last_idle_donated_purr; dbusy_donated_purr = lparstats.busy_donated_purr - last_busy_donated_purr; didle_stolen_purr = lparstats.idle_stolen_purr - last_idle_stolen_purr; dbusy_stolen_purr = lparstats.busy_stolen_purr - last_busy_stolen_purr; if (0 != dlcpu_id + dlcpu_wa) { r1 = dlcpu_id / (dlcpu_id + dlcpu_wa); r2 = dlcpu_wa / (dlcpu_id + dlcpu_wa); } else r1 = r2 = 0; dpcpu_us += didle_donated_purr * r1 + didle_stolen_purr * r1; dpcpu_wa += didle_donated_purr * r2 + didle_stolen_purr * r2; dpcpu_sy += dbusy_donated_purr + dbusy_stolen_purr; delta_purr += didle_donated_purr + dbusy_donated_purr + didle_stolen_purr + dbusy_stolen_purr; pcputime = delta_purr; } #endif /* HAVE_AIXOSLEVEL_530006 */ dtimebase = lparstats.timebase_last - last_timebase_last; vmstat->ent = (double)lparstats.entitled_proc_capacity / 100.0; if (lparstats.type.b.shared_enabled) { entitled_purr = dtimebase * vmstat->ent; if (entitled_purr < delta_purr) { /* when above entitlement, use consumption in percentages */ entitled_purr = delta_purr; } unused_purr = entitled_purr - delta_purr; /* distribute unused purr in wait and idle proportionally to logical wait and idle */ if (0 != dlcpu_wa + dlcpu_id) { dpcpu_wa += unused_purr * ((double)dlcpu_wa / (double)(dlcpu_wa + dlcpu_id)); dpcpu_id += unused_purr * ((double)dlcpu_id / (double)(dlcpu_wa + dlcpu_id)); } pcputime = entitled_purr; } /* Physical Processor Utilization */ vmstat->cpu_us = (double)dpcpu_us * 100.0 / (double)pcputime; vmstat->cpu_sy = (double)dpcpu_sy * 100.0 / (double)pcputime; vmstat->cpu_id = (double)dpcpu_id * 100.0 / (double)pcputime; vmstat->cpu_wa = (double)dpcpu_wa * 100.0 / (double)pcputime; if (lparstats.type.b.shared_enabled) { /* Physical Processor Consumed */ vmstat->cpu_pc = (double)delta_purr / (double)dtimebase; /* Percentage of Entitlement Consumed */ vmstat->cpu_ec = (double)(vmstat->cpu_pc / vmstat->ent) * 100.0; /* Logical Processor Utilization */ vmstat->cpu_lbusy = (double)(dlcpu_us + dlcpu_sy) * 100.0 / (double)lcputime; if (lparstats.type.b.pool_util_authority) { /* Available Pool Processor (app) */ vmstat->cpu_app = (double)(lparstats.pool_idle_time - last_pool_idle_time) / (XINTFRAC * (double)dtimebase); } } #else /* not _AIXVERSION_530 */ /* Physical Processor Utilization */ vmstat->cpu_us = (double)dlcpu_us * 100.0 / (double)lcputime; vmstat->cpu_sy = (double)dlcpu_sy * 100.0 / (double)lcputime; vmstat->cpu_id = (double)dlcpu_id * 100.0 / (double)lcputime; vmstat->cpu_wa = (double)dlcpu_wa * 100.0 / (double)lcputime; #endif /* _AIXVERSION_530 */ /* --- disk --- */ vmstat->disk_bps = 512 * ((diskstats.wblks - last_wblks) + (diskstats.rblks - last_rblks)) / (now - last_clock); vmstat->disk_tps = (double)(diskstats.xfers - last_xfers) / (double)(now - last_clock); /* -- memory -- */ #ifdef HAVE_AIXOSLEVEL_520004 vmstat->mem_avm = (zbx_uint64_t)memstats.virt_active; /* Active virtual pages. Virtual pages are considered active if they have been accessed */ #endif vmstat->mem_fre = (zbx_uint64_t)memstats.real_free; /* free real memory (in 4KB pages) */ } else { #ifdef _AIXVERSION_530 vmstat->shared_enabled = (unsigned char)lparstats.type.b.shared_enabled; vmstat->pool_util_authority = (unsigned char)lparstats.type.b.pool_util_authority; #endif #ifdef HAVE_AIXOSLEVEL_520004 vmstat->aix52stats = 1; #endif } /* saving last values */ last_clock = now; /* --- kthr -- */ last_runque = (zbx_uint64_t)cpustats.runque; last_swpque = (zbx_uint64_t)cpustats.swpque; /* --- page --- */ last_pgins = (zbx_uint64_t)memstats.pgins; last_pgouts = (zbx_uint64_t)memstats.pgouts; last_pgspins = (zbx_uint64_t)memstats.pgspins; last_pgspouts = (zbx_uint64_t)memstats.pgspouts; last_cycles = (zbx_uint64_t)memstats.cycles; last_scans = (zbx_uint64_t)memstats.scans; /* -- faults -- */ last_devintrs = (zbx_uint64_t)cpustats.devintrs; last_syscall = (zbx_uint64_t)cpustats.syscall; last_pswitch = (zbx_uint64_t)cpustats.pswitch; /* --- cpu ---- */ #ifdef _AIXVERSION_530 last_puser = (zbx_uint64_t)lparstats.puser; last_psys = (zbx_uint64_t)lparstats.psys; last_pidle = (zbx_uint64_t)lparstats.pidle; last_pwait = (zbx_uint64_t)lparstats.pwait; last_timebase_last = (zbx_uint64_t)lparstats.timebase_last; last_pool_idle_time = (zbx_uint64_t)lparstats.pool_idle_time; #ifdef HAVE_AIXOSLEVEL_530006 last_idle_donated_purr = (zbx_uint64_t)lparstats.idle_donated_purr; last_busy_donated_purr = (zbx_uint64_t)lparstats.busy_donated_purr; last_idle_stolen_purr = (zbx_uint64_t)lparstats.idle_stolen_purr; last_busy_stolen_purr = (zbx_uint64_t)lparstats.busy_stolen_purr; #endif /* HAVE_AIXOSLEVEL_530006 */ #endif /* _AIXVERSION_530 */ last_user = (zbx_uint64_t)cpustats.user; last_sys = (zbx_uint64_t)cpustats.sys; last_idle = (zbx_uint64_t)cpustats.idle; last_wait = (zbx_uint64_t)cpustats.wait; last_xfers = (zbx_uint64_t)diskstats.xfers; last_wblks = (zbx_uint64_t)diskstats.wblks; last_rblks = (zbx_uint64_t)diskstats.rblks; #endif /* HAVE_LIBPERFSTAT */ }