/****************************************************************************** * * * Function: collector_thread * * * * Purpose: Collect system information * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ ZBX_THREAD_ENTRY(collector_thread, args) { assert(args); zabbix_log(LOG_LEVEL_WARNING, "agent #%d started [collector]", ((zbx_thread_args_t *)args)->thread_num); zbx_free(args); if (SUCCEED != init_cpu_collector(&(collector->cpus))) free_cpu_collector(&(collector->cpus)); while (ZBX_IS_RUNNING()) { zbx_setproctitle("collector [processing data]"); #ifdef _WINDOWS collect_perfstat(); #else if (0 != CPU_COLLECTOR_STARTED(collector)) collect_cpustat(&(collector->cpus)); if (0 != DISKDEVICE_COLLECTOR_STARTED(collector)) collect_stats_diskdevices(); #endif #ifdef _AIX if (1 == collector->vmstat.enabled) collect_vmstat_data(&collector->vmstat); #endif zbx_setproctitle("collector [sleeping for 1 seconds]"); zbx_sleep(1); } if (CPU_COLLECTOR_STARTED(collector)) free_cpu_collector(&(collector->cpus)); #ifdef _WINDOWS free_perf_collector(); /* cpu_collector must be freed before perf_collector is freed */ #endif zabbix_log(LOG_LEVEL_INFORMATION, "zabbix_agentd collector stopped"); ZBX_DO_EXIT(); zbx_thread_exit(0); }
static int vfs_dev_rw(const char *param, AGENT_RESULT *result, int rw) { ZBX_SINGLE_DISKDEVICE_DATA *device; char devname[32], tmp[16]; int type, mode, nparam; zbx_uint64_t dstats[ZBX_DSTAT_MAX]; char *pd; /* pointer to device name without '/dev/' prefix, e.g. 'da0'*/ if (3 < (nparam = num_param(param))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, devname, sizeof(devname))) return SYSINFO_RET_FAIL; pd = devname; if ('\0' != *pd) { if (0 == strcmp(pd, "all")) *pd = '\0'; else { /* skip prefix ZBX_DEV_PFX, if present */ if (0 == strncmp(pd, ZBX_DEV_PFX, sizeof(ZBX_DEV_PFX) - 1)) pd += sizeof(ZBX_DEV_PFX) - 1; } } if (0 != get_param(param, 2, tmp, sizeof(tmp))) *tmp = '\0'; if ('\0' == *tmp || 0 == strcmp(tmp, "bps")) /* default parameter */ type = ZBX_DSTAT_TYPE_BPS; else if (0 == strcmp(tmp, "ops")) type = ZBX_DSTAT_TYPE_OPS; else if (0 == strcmp(tmp, "bytes")) type = ZBX_DSTAT_TYPE_BYTE; else if (0 == strcmp(tmp, "operations")) type = ZBX_DSTAT_TYPE_OPER; else return SYSINFO_RET_FAIL; if (type == ZBX_DSTAT_TYPE_BYTE || type == ZBX_DSTAT_TYPE_OPER) { if (nparam > 2) return SYSINFO_RET_FAIL; if (FAIL == get_diskstat(pd, dstats)) return SYSINFO_RET_FAIL; if (ZBX_DSTAT_TYPE_BYTE == type) SET_UI64_RESULT(result, dstats[(ZBX_DEV_READ == rw ? ZBX_DSTAT_R_BYTE : ZBX_DSTAT_W_BYTE)]); else /* ZBX_DSTAT_TYPE_OPER */ SET_UI64_RESULT(result, dstats[(ZBX_DEV_READ == rw ? ZBX_DSTAT_R_OPER : ZBX_DSTAT_W_OPER)]); return SYSINFO_RET_OK; } if (0 != get_param(param, 3, tmp, sizeof(tmp))) *tmp = '\0'; if ('\0' == *tmp || 0 == strcmp(tmp, "avg1")) /* default parameter */ mode = ZBX_AVG1; else if (0 == strcmp(tmp, "avg5")) mode = ZBX_AVG5; else if (0 == strcmp(tmp, "avg15")) mode = ZBX_AVG15; else return SYSINFO_RET_FAIL; if (0 == DISKDEVICE_COLLECTOR_STARTED(collector)) { SET_MSG_RESULT(result, strdup("Collector is not started!")); return SYSINFO_RET_FAIL; } if (NULL == (device = collector_diskdevice_get(pd))) { if (FAIL == get_diskstat(pd, dstats)) /* validate device name */ return SYSINFO_RET_FAIL; if (NULL == (device = collector_diskdevice_add(pd))) return SYSINFO_RET_FAIL; } if (ZBX_DSTAT_TYPE_BPS == type) /* default parameter */ SET_DBL_RESULT(result, (ZBX_DEV_READ == rw ? device->r_bps[mode] : device->w_bps[mode])); else if (ZBX_DSTAT_TYPE_OPS == type) SET_DBL_RESULT(result, (ZBX_DEV_READ == rw ? device->r_ops[mode] : device->w_ops[mode])); return SYSINFO_RET_OK; }