/* * Custom keys pg.* (for each field in pg_stat_bgwriter) * * Returns the requested global statistic for the PostgreSQL server * * Parameters: * 0: connection string * 1: connection database * * Returns: u */ int PG_STAT_BGWRITER(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_STAT_BGWRITER"; // Function name for log file char *field; char query[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); // Get stat field from requested key name "pb.table.<field>" field = &request->key[3]; // Build query zbx_snprintf(query, sizeof(query), PGSQL_GET_BGWRITER_STAT, field); // Get field value if(0 == strncmp(field, "checkpoint_", 11)) ret = pg_get_dbl(request, result, query, NULL); else if(0 == strncmp(field, "stats_reset", 11)) ret = pg_get_string(request, result, query, NULL); else ret = pg_get_int(request, result, query, NULL); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/* * Custom key pg.checkpoint_time_perc * * Returns the percentage of time spent writing or syncing checkpoints since * statistics were reset. * * Parameters: * 0: connection string * 1: connection database * 2: action: all (default) | write | sync * * Returns: d */ int PG_BG_TIME_PERC(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_BG_TIME_PERC"; // Function name for log file char query[MAX_STRING_LEN]; char *action = NULL, *field = NULL; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); // parse action parameter action = get_rparam(request, PARAM_FIRST); if (strisnull(action) || 0 == strcmp(action, "all")) field = "(checkpoint_write_time + checkpoint_sync_time)"; else if (0 == strcmp(action, "write")) field = "checkpoint_write_time"; else if (0 == strcmp(action, "sync")) field = "checkpoint_sync_time"; else { SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Invalid action parameter: %s", action)); return ret; } // build query zbx_snprintf(query, sizeof(query), PGSQL_BG_TIME_PERC, field); // get result ret = pg_get_dbl(request, result, query, NULL); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/* * Custom key pg.queries.longest * * Returns the duration in seconds of the longest running current query * * Parameters: * 0: connection string * 1: connection database * 2: filter by database oid name * 3: filter by user OID or name * 4: filter by hostname or IP address of the connected host * 5: return only waiting backends * * Returns: d * * Support: Requires PostgreSQL v9.2 or above * * TODO: allow filtering in pg.queries.longest similar to pg.backends.count */ int PG_QUERIES_LONGEST(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_QUERIES_LONGEST"; // Function name for log file char query[MAX_QUERY_LEN]; char clause[MAX_CLAUSE_LEN]; PGparams params = NULL; // freed later in pg_exec zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); // build the filter clause memset(clause, 0, sizeof(clause)); if (0 == build_activity_clause(request, clause, ¶ms, 1)) goto out; // build the full sql query memset(query, 0, MAX_QUERY_LEN); if (pg_version(request) < 90200) zbx_snprintf(query, MAX_QUERY_LEN, PGSQL_GET_LONGEST_QUERY, clause); else zbx_snprintf(query, MAX_QUERY_LEN, PGSQL_GET_LONGEST_QUERY_92, clause); ret = pg_get_dbl(request, result, query, params); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/* * Custom key pg.checkpoint_avg_interval * * Returns the average interval in seconds between all checkpoints that have * run since statistics were reset. * * Parameters: * 0: connection string * 1: connection database * * Returns: d */ int PG_BG_AVG_INTERVAL(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_BG_AVG_INTERVAL"; // Function name for log file zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); ret = pg_get_dbl(request, result, PGSQL_BG_AVG_INTERVAL, NULL); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/* * Custom keys pg.* (for each field in pg_stat_database) * * Returns the requested statistic for the specified database * * Parameter [0-4]: <host,port,db,user,passwd> * * Returns: u */ int PG_STAT_DATABASE(AGENT_REQUEST *request, AGENT_RESULT *result) { int ret = SYSINFO_RET_FAIL; // Request result code const char *__function_name = "PG_STAT_DATABASE"; // Function name for log file char *datname = NULL; char *field; char query[MAX_STRING_LEN]; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); // Get stat field from requested key name "pb.db.<field>" field = &request->key[6]; // Build query datname = get_rparam(request, PARAM_DB); if(NULL == datname || '\0' == *datname) zbx_snprintf(query, sizeof(query), PGSQL_GET_DB_STAT_SUM, field); else zbx_snprintf(query, sizeof(query), PGSQL_GET_DB_STAT, field, datname); // Get results based on type if (0 == strncmp(field, "stats_reset", 11)) { if(NULL == datname || '\0' == *datname) { // Can't do SUMs on text fields! zabbix_log(LOG_LEVEL_ERR, "No database specified bro, in %s", __function_name); goto out; } ret = pg_get_string(request, result, query); } else if(0 == strncmp(field, "blk_", 4)) ret = pg_get_dbl(request, result, query); else ret = pg_get_int(request, result, query); out: zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }