Global interfaces

Global interfaces report metrics related to a set of components on a system (such as processors, disks, or memory).

The following are the global interfaces:
Item Descriptor
perfstat_cpu_total Retrieves global processor usage metrics
perfstat_memory_total Retrieves global memory usage metrics
perfstat_disk_total Retrieves global disk usage metrics
Note: This API does not return any data when started from an application running inside WPAR.
perfstat_netinterface_total Retrieves global network interfaces metrics
Note: This API does not return any data when started from an application running inside WPAR.
perfstat_partition_config Retrieves Operating System and partition related information
perfstat_partition_total Retrieves global partition metrics
perfstat_tape_total Retrieves global tape usage metrics
Note: This API does not return any data when started from an application running inside WPAR.
The common signature used by all of the global interfaces is as follows:
int perfstat_subsystem_total(perfstat_id_t *name,
                             perfstat_subsystem_total_t *userbuff,
                             int sizeof_struct,
                             int desired_number);
The usage of the parameters for all of the interfaces is as follows:
Item Descriptor
perfstat_id_t *name Reserved for future use, must be NULL
perfstat_subsystem_total_t *userbuff A pointer to a memory area with enough space for the returned structure
int sizeof_struct Should be set to sizeof(perfstat_subsystem_t)
int desired_number Reserved for future use, must be set to 0 or 1
The return value is -1 in case of errors. Otherwise, the number of structures copied is returned. This is always 1.

The following sections provide examples of the type of data returned and code using each of the interfaces.

The following code shows an example of how perfstat_netinterface_total is used:
#include <stdio.h>
#include <libperfstat.h>

int main(int argc, char* argv[]) {
    perfstat_netinterface_total_t ninfo;
    int rc;
    rc = perfstat_netinterface_total(NULL, &ninfo, sizeof(perfstat_netinterface_total_t), 1);
    if (rc != 1)
    {
    perror("perfstat_netinterface_total");
    exit(-1);
    }
    perfstat_netinterface_total(NULL, &ninfo, sizeof(perfstat_netinterface_total_t), 1);

    printf("Network interfaces statistics\n");
    printf("-----------------------------\n");
    printf("number of interfaces : %d\n",   ninfo.number);
    printf("\ninput statistics:\n");
    printf("number of packets    : %llu\n", ninfo.ipackets);
    printf("number of errors     : %llu\n", ninfo.ierrors);
    printf("number of bytes      : %llu\n", ninfo.ibytes);
    printf("\noutput statistics:\n");
    printf("number of packets    : %llu\n", ninfo.opackets);
    printf("number of bytes      : %llu\n", ninfo.obytes);
    printf("number of errors     : %llu\n", ninfo.oerrors);
}
The program produces output similar to the following:
Network interfaces statistics
-----------------------------
number of interfaces : 2

input statistics:
number of packets    : 306688
number of errors     : 0
number of bytes      : 24852688

output statistics:
number of packets    : 63005
number of bytes      : 11518591
number of errors     : 0
The preceding program emulates ifstat's behavior and also shows how perfstat_netinterface_total is used.