Esempio n. 1
0
/*
 * 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;
}
Esempio n. 2
0
/*
 * Custom keys pg.table.* (for each field in pg_stat_all_tables)
 *
 * Returns the requested statistic for the specified data table
 *
 * Parameter [0-4]:     <host,port,db,user,passwd>
 *
 * Parameter[table]:    table name to assess (default: all)
 *
 * Returns: u
 */
int    PG_STAT_ALL_TABLES(AGENT_REQUEST *request, AGENT_RESULT *result)
{
    int         ret = SYSINFO_RET_FAIL;                     // Request result code
    const char  *__function_name = "PG_STAT_ALL_TABLES";    // Function name for log file
    
    char        *tablename = 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.table.<field>"
    field = &request->key[9];
    
    // Build query
    tablename = get_rparam(request, PARAM_FIRST);
    if(NULL == tablename || '\0' == *tablename) {   
        zbx_snprintf(query, sizeof(query), PGSQL_GET_TABLE_STAT_SUM, field);
    }
    else {
        zbx_snprintf(query, sizeof(query), PGSQL_GET_TABLE_STAT, field, tablename);
    }
    
    // Set result
    if(0 == strncmp(field, "last_", 5)) {
        if(NULL == tablename || '\0' == *tablename) {
            // Can't do SUMs on text fields!
            zabbix_log(LOG_LEVEL_ERR, "No table specified bro, in %s", __function_name);
            goto out;
        }
    
        ret = pg_get_string(request, result, query);
    }
    else {
        ret = pg_get_int(request, result, query);
    }
    
out:
    zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name);
    return ret;
}
Esempio n. 3
0
/*
 * 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;
}