int VFS_FS_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { char *fsname, *mode; zbx_uint64_t total, free, used; double pfree, pused; if (2 < request->nparam) return SYSINFO_RET_FAIL; fsname = get_rparam(request, 0); mode = get_rparam(request, 1); if (SYSINFO_RET_OK != get_fs_size_stat(fsname, &total, &free, &used, &pfree, &pused)) return SYSINFO_RET_FAIL; if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */ SET_UI64_RESULT(result, total); else if (0 == strcmp(mode, "free")) SET_UI64_RESULT(result, free); else if (0 == strcmp(mode, "used")) SET_UI64_RESULT(result, used); else if (0 == strcmp(mode, "pfree")) SET_DBL_RESULT(result, pfree); else if (0 == strcmp(mode, "pused")) SET_DBL_RESULT(result, pused); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
int WEB_PAGE_PERF(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char hostname[MAX_STRING_LEN]; char path[MAX_STRING_LEN]; char port_str[8]; double start_time; if (num_param(param) > 3) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, hostname, sizeof(hostname))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, path, sizeof(path))) *path = '\0'; if (0 != get_param(param, 3, port_str, sizeof(port_str)) || '\0' == *port_str) zbx_snprintf(port_str, sizeof(port_str), "%d", ZBX_DEFAULT_HTTP_PORT); else if (FAIL == is_uint(port_str)) return SYSINFO_RET_FAIL; start_time = zbx_time(); if (SYSINFO_RET_OK == get_http_page(hostname, path, (unsigned short)atoi(port_str), NULL, 0)) { SET_DBL_RESULT(result, zbx_time() - start_time); } else SET_DBL_RESULT(result, 0.0); return SYSINFO_RET_OK; }
int VFS_FS_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char fsname[MAX_STRING_LEN], mode[8]; zbx_uint64_t total, free, used; double pfree, pused; if (num_param(param) > 2) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, fsname, sizeof(fsname))) return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, mode, sizeof(mode))) *mode = '\0'; if (SYSINFO_RET_OK != get_fs_size_stat(fsname, &total, &free, &used, &pfree, &pused)) return SYSINFO_RET_FAIL; /* default parameter */ if ('\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */ SET_UI64_RESULT(result, total); else if (0 == strcmp(mode, "free")) SET_UI64_RESULT(result, free); else if (0 == strcmp(mode, "used")) SET_UI64_RESULT(result, used); else if (0 == strcmp(mode, "pfree")) SET_DBL_RESULT(result, pfree); else if (0 == strcmp(mode, "pused")) SET_DBL_RESULT(result, pused); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { #if defined(HAVE_GETLOADAVG) double load[3]; #elif defined(HAVE_KSTAT_H) char *key; int value; #endif char tmp[MAX_STRING_LEN]; if (num_param(param) > 2) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, tmp, sizeof(tmp))) return SYSINFO_RET_FAIL; if ('\0' != *tmp && 0 != strcmp(tmp, "all")) /* default parameter */ return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, tmp, sizeof(tmp))) *tmp = '\0'; #if defined(HAVE_GETLOADAVG) if (-1 == getloadavg(load, 3)) return SYSINFO_RET_FAIL; if ('\0' == *tmp || 0 == strcmp(tmp, "avg1")) /* default parameter */ { SET_DBL_RESULT(result, load[0]); } else if ('\0' == *tmp || 0 == strcmp(tmp, "avg5")) { SET_DBL_RESULT(result, load[1]); } else if ('\0' == *tmp || 0 == strcmp(tmp, "avg15")) { SET_DBL_RESULT(result, load[2]); } else return SYSINFO_RET_FAIL; #elif defined(HAVE_KSTAT_H) if ('\0' == *tmp || 0 == strcmp(tmp, "avg1")) /* default parameter */ key = "avenrun_1min"; else if ('\0' == *tmp || 0 == strcmp(tmp, "avg5")) key = "avenrun_5min"; else if ('\0' == *tmp || 0 == strcmp(tmp, "avg15")) key = "avenrun_15min"; else return SYSINFO_RET_FAIL; if (FAIL == get_kstat_system_misc(key, &value)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, (double)value/FSCALE); #else return SYSINFO_RET_FAIL; #endif return SYSINFO_RET_OK; }
int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { /* * FreeBSD 7.0 i386 */ #ifdef XSWDEV_VERSION /* defined in <vm/vm_param.h> */ char *swapdev, *mode; int mib[16], *mib_dev; size_t sz, mib_sz; struct xswdev xsw; zbx_uint64_t total = 0, used = 0; if (2 < request->nparam) return SYSINFO_RET_FAIL; swapdev = get_rparam(request, 0); mode = get_rparam(request, 1); sz = ARRSIZE(mib); if (-1 == sysctlnametomib("vm.swap_info", mib, &sz)) return FAIL; mib_sz = sz + 1; mib_dev = &(mib[sz]); *mib_dev = 0; sz = sizeof(xsw); while (-1 != sysctl(mib, mib_sz, &xsw, &sz, NULL, 0)) { if (NULL == swapdev || '\0' == *swapdev || 0 == strcmp(swapdev, "all") /* default parameter */ || 0 == strcmp(swapdev, devname(xsw.xsw_dev, S_IFCHR))) { total += (zbx_uint64_t)xsw.xsw_nblks; used += (zbx_uint64_t)xsw.xsw_used; } (*mib_dev)++; } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "free")) /* default parameter */ SET_UI64_RESULT(result, (total - used) * getpagesize()); else if (0 == strcmp(mode, "total")) SET_UI64_RESULT(result, total * getpagesize()); else if (0 == strcmp(mode, "used")) SET_UI64_RESULT(result, used * getpagesize()); else if (0 == strcmp(mode, "pfree")) SET_DBL_RESULT(result, total ? ((double)(total - used) * 100.0 / (double)total) : 0.0); else if (0 == strcmp(mode, "pused")) SET_DBL_RESULT(result, total ? ((double)used * 100.0 / (double)total) : 0.0); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; #else return SYSINFO_RET_FAIL; #endif }
int VFS_FS_INODE(AGENT_REQUEST *request, AGENT_RESULT *result) { #ifdef HAVE_SYS_STATVFS_H # define ZBX_STATFS statvfs # define ZBX_FFREE f_favail #else # define ZBX_STATFS statfs # define ZBX_FFREE f_ffree #endif char *fsname, *mode; zbx_uint64_t total; struct ZBX_STATFS s; if (2 < request->nparam) return SYSINFO_RET_FAIL; fsname = get_rparam(request, 0); mode = get_rparam(request, 1); if (NULL == fsname || '\0' == *fsname || 0 != ZBX_STATFS(fsname, &s)) return SYSINFO_RET_FAIL; if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "total")) /* default parameter */ SET_UI64_RESULT(result, s.f_files); else if (0 == strcmp(mode, "free")) SET_UI64_RESULT(result, s.ZBX_FFREE); else if (0 == strcmp(mode, "used")) SET_UI64_RESULT(result, s.f_files - s.f_ffree); else if (0 == strcmp(mode, "pfree")) { total = s.f_files; #ifdef HAVE_SYS_STATVFS_H total -= s.f_ffree - s.f_favail; #endif if (0 != total) SET_DBL_RESULT(result, (double)(100.0 * s.ZBX_FFREE) / total); else return SYSINFO_RET_FAIL; } else if (0 == strcmp(mode, "pused")) { total = s.f_files; #ifdef HAVE_SYS_STATVFS_H total -= s.f_ffree - s.f_favail; #endif if (0 != total) SET_DBL_RESULT(result, 100.0 - (double)(100.0 * s.ZBX_FFREE) / total); else return SYSINFO_RET_FAIL; } else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
static void process_step_data(zbx_uint64_t httpstepid, ZBX_HTTPSTAT *stat) { const char *__function_name = "process_step_data"; DB_RESULT result; DB_ROW row; DB_HTTPSTEPITEM httpstepitem; AGENT_RESULT value; zabbix_log(LOG_LEVEL_DEBUG, "In %s() httpstepid:" ZBX_FS_UI64 " rspcode:%ld time:" ZBX_FS_DBL " speed:" ZBX_FS_DBL, __function_name, httpstepid, stat->rspcode, stat->total_time, stat->speed_download); result = DBselect("select httpstepitemid,httpstepid,itemid,type" " from httpstepitem" " where httpstepid=" ZBX_FS_UI64, httpstepid); while (NULL != (row = DBfetch(result))) { ZBX_STR2UINT64(httpstepitem.httpstepitemid, row[0]); ZBX_STR2UINT64(httpstepitem.httpstepid, row[1]); ZBX_STR2UINT64(httpstepitem.itemid, row[2]); httpstepitem.type = atoi(row[3]); init_result(&value); switch (httpstepitem.type) { case ZBX_HTTPITEM_TYPE_RSPCODE: SET_UI64_RESULT(&value, stat->rspcode); process_value(httpstepitem.itemid, &value); break; case ZBX_HTTPITEM_TYPE_TIME: SET_DBL_RESULT(&value, stat->total_time); process_value(httpstepitem.itemid, &value); break; case ZBX_HTTPITEM_TYPE_SPEED: SET_DBL_RESULT(&value, stat->speed_download); process_value(httpstepitem.itemid, &value); break; default: break; } free_result(&value); } DBfree_result(result); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); }
int SYSTEM_SWAP_SIZE(AGENT_REQUEST *request, AGENT_RESULT *result) { #ifdef HAVE_LIBPERFSTAT perfstat_memory_total_t mem; char *swapdev, *mode; if (2 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; } swapdev = get_rparam(request, 0); mode = get_rparam(request, 1); if (NULL != swapdev && '\0' != *swapdev && 0 != strcmp(swapdev, "all")) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; } if (1 != perfstat_memory_total(NULL, &mem, sizeof(perfstat_memory_total_t), 1)) { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno))); return SYSINFO_RET_FAIL; } if (NULL == mode || '\0' == *mode || 0 == strcmp(mode, "free")) SET_UI64_RESULT(result, mem.pgsp_free << ZBX_PERFSTAT_PAGE_SHIFT); else if (0 == strcmp(mode, "total")) SET_UI64_RESULT(result, mem.pgsp_total << ZBX_PERFSTAT_PAGE_SHIFT); else if (0 == strcmp(mode, "used")) SET_UI64_RESULT(result, (mem.pgsp_total - mem.pgsp_free) << ZBX_PERFSTAT_PAGE_SHIFT); else if (0 == strcmp(mode, "pfree")) SET_DBL_RESULT(result, mem.pgsp_total ? 100.0 * (mem.pgsp_free / (double)mem.pgsp_total) : 0.0); else if (0 == strcmp(mode, "pused")) SET_DBL_RESULT(result, mem.pgsp_total ? 100.0 - 100.0 * (mem.pgsp_free / (double)mem.pgsp_total) : 0.0); else { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; } return SYSINFO_RET_OK; #else SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for Perfstat API.")); return SYSINFO_RET_FAIL; #endif }
int GET_SENSOR(AGENT_REQUEST *request, AGENT_RESULT *result) { char *device, *name, *function; int do_task, cnt = 0; double aggr = 0; if (3 < request->nparam) return SYSINFO_RET_FAIL; device = get_rparam(request, 0); name = get_rparam(request, 1); function = get_rparam(request, 2); if (NULL == device || '\0' == *device) return SYSINFO_RET_FAIL; if (NULL == name || '\0' == *name) return SYSINFO_RET_FAIL; if (NULL == function || '\0' == *function) do_task = DO_ONE; else if (0 == strcmp(function, "avg")) do_task = DO_AVG; else if (0 == strcmp(function, "max")) do_task = DO_MAX; else if (0 == strcmp(function, "min")) do_task = DO_MIN; else return SYSINFO_RET_FAIL; if (DO_ONE != do_task && 0 != isdigit(name[strlen(name)-1])) do_task = DO_ONE; if (DO_ONE != do_task && 0 == isalpha(name[strlen(name)-1])) return SYSINFO_RET_FAIL; get_device_sensors(do_task, device, name, &aggr, &cnt); if (0 == cnt) return SYSINFO_RET_FAIL; if (DO_AVG == do_task) SET_DBL_RESULT(result, aggr / cnt); else SET_DBL_RESULT(result, aggr); return SYSINFO_RET_OK; }
int SYSTEM_CPU_LOAD(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char tmp[32]; int mode; double load[ZBX_AVG_COUNT]; if (num_param(param) > 2) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, tmp, sizeof(tmp))) *tmp = '\0'; if ('\0' != *tmp && 0 != strcmp(tmp, "all")) /* default parameter */ return SYSINFO_RET_FAIL; if (0 != get_param(param, 2, 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 (mode >= getloadavg(load, 3)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, load[mode]); return SYSINFO_RET_OK; }
/* * Function: PG_SETTING * * Provides access to run-time parameters of the server such as those returned * by `SHOW` commands. * * Parameter [0-4]: <host,port,db,user,passwd> * * Parameter [setting]: run-time configuration parameter name * * Returns: determined by parameter vartype */ int PG_SETTING(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_SETTING"; // Function name for log file PGconn *conn = NULL; PGresult *res = NULL; char *setting = NULL; char *value = NULL; char *type = NULL; char query[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); // Build the query setting = get_rparam(request, PARAM_FIRST); if(NULL == setting || '\0' == *setting) { zabbix_log(LOG_LEVEL_ERR, "No setting name specified in %s()", __function_name); goto out; } zbx_snprintf(query, sizeof(query), PGSQL_GET_SETTING, setting); // Connect to PostreSQL if(NULL == (conn = pg_connect(request))) goto out; // Execute the query res = PQexec(conn, query); if(PQresultStatus(res) != PGRES_TUPLES_OK) { zabbix_log(LOG_LEVEL_ERR, "Failed to execute PostgreSQL query in %s() with: %s", __function_name, PQresultErrorMessage(res)); goto out; } if(0 == PQntuples(res)) { zabbix_log(LOG_LEVEL_DEBUG, "No results returned for query \"%s\" in %s()", query, __function_name); goto out; } // Set result value = strdup(PQgetvalue(res, 0, 0)); type = strdup(PQgetvalue(res, 0, 1)); if(0 == strncmp("integer", type, 7)) SET_UI64_RESULT(result, strtoull(value, NULL, 10)); else if(0 == strncmp("real", type, 4)) SET_DBL_RESULT(result, strtold(value, NULL)); else SET_STR_RESULT(result, value); ret = SYSINFO_RET_OK; out: PQclear(res); PQfinish(conn); zabbix_log(LOG_LEVEL_DEBUG, "End of %s(%s)", __function_name, request->key); return ret; }
int USER_PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; char *counter, *error = NULL; double value; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); if (1 != request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid number of parameters.")); goto out; } if (NULL == (counter = get_rparam(request, 0)) || '\0' == *counter) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); goto out; } if (SUCCEED != get_perf_counter_value_by_name(counter, &value, &error)) { SET_MSG_RESULT(result, error != NULL ? error : zbx_strdup(NULL, "Cannot obtain performance information from collector.")); goto out; } SET_DBL_RESULT(result, value); ret = SYSINFO_RET_OK; out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); return ret; }
static int SYSTEM_SWAP_PUSED(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { AGENT_RESULT result_tmp; zbx_uint64_t tot_val = 0; zbx_uint64_t free_val = 0; init_result(&result_tmp); if(SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK || !(result_tmp.type & AR_UINT64)) return SYSINFO_RET_FAIL; tot_val = result_tmp.ui64; /* Check for division by zero */ if(tot_val == 0) { free_result(&result_tmp); return SYSINFO_RET_FAIL; } if(SYSTEM_SWAP_FREE(cmd, param, flags, &result_tmp) != SYSINFO_RET_OK || !(result_tmp.type & AR_UINT64)) return SYSINFO_RET_FAIL; free_val = result_tmp.ui64; free_result(&result_tmp); SET_DBL_RESULT(result, 100.0 - (100.0 * (double)free_val) / (double)tot_val); return SYSINFO_RET_OK; }
int PERF_COUNTER(AGENT_REQUEST *request, AGENT_RESULT *result) { char counterpath[PDH_MAX_COUNTER_PATH], *tmp, *error = NULL; int interval, ret = SYSINFO_RET_FAIL; double value; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __func__); if (2 < request->nparam) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); goto out; } tmp = get_rparam(request, 0); if (NULL == tmp || '\0' == *tmp) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); goto out; } strscpy(counterpath, tmp); if (NULL == (tmp = get_rparam(request, 1)) || '\0' == *tmp) { interval = 1; } else if (FAIL == is_uint31(tmp, &interval)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); goto out; } if (1 > interval || MAX_COLLECTOR_PERIOD < interval) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Interval out of range.")); goto out; } if (FAIL == check_counter_path(counterpath)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid performance counter path.")); goto out; } if (SUCCEED != get_perf_counter_value_by_path(counterpath, interval, &value, &error)) { SET_MSG_RESULT(result, error != NULL ? error : zbx_strdup(NULL, "Cannot obtain performance information from collector.")); goto out; } ret = SYSINFO_RET_OK; SET_DBL_RESULT(result, value); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __func__, zbx_result_string(ret)); return ret; }
static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result) { AGENT_RESULT result_tmp; zbx_uint64_t tot_val = 0; zbx_uint64_t free_val = 0; init_result(&result_tmp); if (SYSINFO_RET_OK != SYSTEM_SWAP_TOTAL(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64)) return SYSINFO_RET_FAIL; tot_val = result_tmp.ui64; /* Check for division by zero */ if (0 == tot_val) { free_result(&result_tmp); return SYSINFO_RET_FAIL; } if (SYSINFO_RET_OK != SYSTEM_SWAP_FREE(cmd, param, flags, &result_tmp) || !(result_tmp.type & AR_UINT64)) return SYSINFO_RET_FAIL; free_val = result_tmp.ui64; free_result(&result_tmp); SET_DBL_RESULT(result, (100.0 * (double)free_val) / (double)tot_val); return SYSINFO_RET_OK; }
int SYSTEM_CPU_UTIL(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { char tmp[32]; int cpu_num; if (!CPU_COLLECTOR_STARTED(collector)) { SET_MSG_RESULT(result, strdup("Collector is not started!")); return SYSINFO_RET_OK; } if (num_param(param) > 3) return SYSINFO_RET_FAIL; if (0 != get_param(param, 1, tmp, sizeof(tmp))) *tmp = '\0'; if ('\0' == *tmp || 0 == strcmp(tmp, "all")) /* default parameter */ cpu_num = 0; else { cpu_num = atoi(tmp) + 1; if (cpu_num < 1 || cpu_num > collector->cpus.count) return SYSINFO_RET_FAIL; } if (0 != get_param(param, 2, tmp, sizeof(tmp))) *tmp = '\0'; /* only 'system' parameter supported */ if ('\0' != *tmp && 0 != strcmp(tmp, "system")) /* default parameter */ return SYSINFO_RET_FAIL; if (0 != get_param(param, 3, tmp, sizeof(tmp))) *tmp = '\0'; if ('\0' == *tmp || 0 == strcmp(tmp, "avg1")) /* default parameter */ SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util1); else if (0 == strcmp(tmp, "avg5")) SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util5); else if (0 == strcmp(tmp, "avg15")) SET_DBL_RESULT(result, collector->cpus.cpu[cpu_num].util15); else return SYSINFO_RET_FAIL; return SYSINFO_RET_OK; }
static double *get_result_dbl_value(AGENT_RESULT *result) { double value; assert(result); if (0 != ISSET_DBL(result)) { /* nothing to do */ } else if (0 != ISSET_UI64(result)) { SET_DBL_RESULT(result, result->ui64); } else if (0 != ISSET_STR(result)) { zbx_rtrim(result->str, " \""); zbx_ltrim(result->str, " \"+"); if (SUCCEED != is_double(result->str)) return NULL; value = atof(result->str); SET_DBL_RESULT(result, value); } else if (0 != ISSET_TEXT(result)) { zbx_rtrim(result->text, " \""); zbx_ltrim(result->text, " \"+"); if (SUCCEED != is_double(result->text)) return NULL; value = atof(result->text); SET_DBL_RESULT(result, value); } /* skip AR_MESSAGE - it is information field */ if (0 != ISSET_DBL(result)) return &result->dbl; return NULL; }
int USER_PERF_COUNTER(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) { const char *__function_name = "USER_PERF_COUNTER"; PERF_COUNTER_DATA *perfs = NULL; int ret = SYSINFO_RET_FAIL; double value; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); if (!PERF_COLLECTOR_STARTED(collector)) { zabbix_log(LOG_LEVEL_DEBUG, "Collector is not started!"); return ret; } for (perfs = collector->perfs.pPerfCounterList; NULL != perfs; perfs = perfs->next) { if (NULL != perfs->name && 0 == strcmp(perfs->name, param)) { if (PERF_COUNTER_ACTIVE == perfs->status) { SET_DBL_RESULT(result, compute_average_value(__function_name, perfs, USE_DEFAULT_INTERVAL)); ret = SYSINFO_RET_OK; } break; } } if (SYSINFO_RET_OK != ret && NULL != perfs) { if (ERROR_SUCCESS == calculate_counter_value(__function_name, perfs->counterpath, &value)) { perfs->status = PERF_COUNTER_INITIALIZED; SET_DBL_RESULT(result, value); ret = SYSINFO_RET_OK; } } zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/****************************************************************************** * * * Function: zbx_module_docker_up * * * * Purpose: check if container is running * * * * Return value: 1 - is running, 0 - is not running * * * ******************************************************************************/ int zbx_module_docker_up(AGENT_REQUEST *request, AGENT_RESULT *result) { zabbix_log(LOG_LEVEL_DEBUG, "In zbx_module_docker_up()"); char *container, *metric; int ret = SYSINFO_RET_FAIL; if (1 != request->nparam) { zabbix_log(LOG_LEVEL_ERR, "Invalid number of parameters: %d", request->nparam); SET_MSG_RESULT(result, strdup("Invalid number of parameters.")); return SYSINFO_RET_FAIL; } if (stat_dir == NULL) { zabbix_log(LOG_LEVEL_DEBUG, "docker.up check is not available at the moment - no stat directory."); SET_MSG_RESULT(result, zbx_strdup(NULL, "docker.up check is not available at the moment - no stat directory.")); return SYSINFO_RET_OK; } container = get_rparam(request, 0); char *stat_file = "/cpuacct.stat"; char *cgroup = "cpuacct/"; size_t filename_size = strlen(base_dir) + strlen(cgroup) + strlen(container) + strlen(stat_dir) + strlen(stat_file) + 2; char *filename = malloc(filename_size); zbx_strlcpy(filename, base_dir, filename_size); zbx_strlcat(filename, cgroup, filename_size); zbx_strlcat(filename, stat_dir, filename_size); zbx_strlcat(filename, container, filename_size); zbx_strlcat(filename, stat_file, filename_size); zabbix_log(LOG_LEVEL_DEBUG, "Metric source file: %s", filename); FILE *file; if (NULL == (file = fopen(filename, "r"))) { zabbix_log(LOG_LEVEL_DEBUG, "Can't open docker container metric file: '%s', container doesn't run", filename); SET_DBL_RESULT(result, 0); return SYSINFO_RET_OK; } zbx_fclose(file); zabbix_log(LOG_LEVEL_DEBUG, "Can open docker container metric file: '%s', container is running", filename); SET_DBL_RESULT(result, 1); return SYSINFO_RET_OK; }
static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result) { double pused; if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, &pused, NULL, NULL)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, pused); return SYSINFO_RET_OK; }
static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result) { zbx_uint64_t total; if (0 == (total = sysconf(_SC_PHYS_PAGES))) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, sysconf(_SC_AVPHYS_PAGES) / (double)total * 100); return SYSINFO_RET_OK; }
static int VFS_FS_PUSED(const char *fs, AGENT_RESULT *result) { double value = 0; if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &value)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, value); return SYSINFO_RET_OK; }
static int VM_MEMORY_PUSED(AGENT_RESULT *result) { ZBX_SYSCTL(uvm); if (0 == uvm.npages) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, (uvm.npages - uvm.free) / (double)uvm.npages * 100); return SYSINFO_RET_OK; }
static int VFS_FS_INODE_PFREE(const char *fs, AGENT_RESULT *result) { double value = 0; if (SYSINFO_RET_OK != get_fs_inodes_stat(fs, NULL, NULL, NULL, &value, NULL)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, value); return SYSINFO_RET_OK; }
static int VM_MEMORY_PFREE(AGENT_RESULT *result) { double value = 0; if (SYSINFO_RET_OK != get_vm_stat(NULL, NULL, NULL, &value, NULL, NULL)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, value); return SYSINFO_RET_OK; }
static int SYSTEM_SWAP_PFREE(AGENT_RESULT *result) { double value; if (SYSINFO_RET_OK != get_swap_size(NULL, NULL, NULL, &value, NULL)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, value); return SYSINFO_RET_OK; }
static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result) { ZBX_PERFSTAT_MEMORY_TOTAL(); if (0 == m.real_total) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, m.real_free / (double)m.real_total * 100); return SYSINFO_RET_OK; }
static int VFS_FS_PFREE(const char *fs, AGENT_RESULT *result) { double pfree; if (SYSINFO_RET_OK != get_fs_size_stat(fs, NULL, NULL, NULL, NULL, &pfree)) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, pfree); return SYSINFO_RET_OK; }
static int VM_MEMORY_PAVAILABLE(AGENT_RESULT *result) { ZBX_PSTAT_GETSTATIC(); ZBX_PSTAT_GETDYNAMIC(); if (0 == pst.physical_memory) return SYSINFO_RET_FAIL; SET_DBL_RESULT(result, pdy.psd_free / (double)pst.physical_memory * 100); return SYSINFO_RET_OK; }
static int get_sensor(const char *name, unsigned flags, AGENT_RESULT *result) { DIR *dir; struct dirent *entries; struct stat buf; char filename[MAX_STRING_LEN]; char line[MAX_STRING_LEN]; double d1,d2,d3; FILE *f; assert(result); init_result(result); dir=opendir("/proc/sys/dev/sensors"); if(NULL == dir) { return SYSINFO_RET_FAIL; } while((entries=readdir(dir))!=NULL) { strscpy(filename,"/proc/sys/dev/sensors/"); zbx_strlcat(filename,entries->d_name,MAX_STRING_LEN); zbx_strlcat(filename,name,MAX_STRING_LEN); if(stat(filename,&buf)==0) { if( NULL == (f = fopen(filename,"r") )) { continue; } fgets(line,MAX_STRING_LEN,f); zbx_fclose(f); if(sscanf(line,"%lf\t%lf\t%lf\n",&d1, &d2, &d3) == 3) { closedir(dir); SET_DBL_RESULT(result, d3); return SYSINFO_RET_OK; } else { closedir(dir); return SYSINFO_RET_FAIL; } } } closedir(dir); return SYSINFO_RET_FAIL; }