perfstat_volumegroup Interface

The perfstat_volumegroup interface returns a set of structures of type perfstat_logicalvolume_t, which is defined in the libperfstat.h file.

Selected fields from the perfstat_logicalvolume_t structure include:
Item Descriptor
Total_disks Total number of disks in the volume group
Active_disks Total number of active disks in the volume group
Iocnt Number of read and write requests
The following code shows an example of how the perfstat_logicalvolume interface is used:
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
int vg_count, rc,i;
perfstat_id_t first;
perfstat_volumegroup_t *vg;


strcpy(first.name,NULL);

/* to enable the volumegroup statistical collection */
perfstat_config(PERFSTAT_ENABLE|PERFSTAT_LV,NULL);

/* to get the number of volume groups */
vg_count = perfstat_volumegroup (NULL, NULL, sizeof(perfstat_logicalvolume_t), 0);
/* check the subroutine return code for any error */
if (vg_count <=0 ){
   perror("perfstat_volumegroup");
   exit(-1);
}

/* Allocate enough memory to hold all the structures */
vg = (perfstat_volumegroup_t *)calloc(vg_count, sizeof(perfstat_volumegroup_t));
if (vg == NULL){
   perror(".malloc");
   exit(-1);
}

/* Call the API to get the data */
rc = perfstat_volumegroup(&first,vg,sizeof(perfstat_volumegroup_t),vg_count); 
/* check the return code for any error */
if (rc <= 0){
   perror("perfstat_volumegroup ");
   exit(-1);
}
for(i=0;i<vg_count;i++){
    printf("Volume group name=%s\n",vg[i].name);
    printf("Number of physical volumes in the volume group=%lld\n",vg[i].total_disks);
    printf("Number of active physical volumes in the volume group=%lld\n",vg[i].active_disks);
    printf("Number of logical volumes in the volume group=%lld\n",vg[i].total_logical_volumes);
    printf("Number of logical volumes opened in the volume group=%lld\n",vg[i].opened_logical_volumes);
    printf("Number of read and write requests=%lld\n",vg[i].iocnt);
    printf("Number of Kilobytes read=%lld\n",vg[i].kbreads);
    printf("Number of Kilobytes written=%lld\n",vg[i].kbwrites);
}

/* disable logical volume statistical collection */
perfstat_config(PERFSTAT_DISABLE | PERFSTAT_LV , NULL);

return 0;
}
The program displays an output that is similar to the following example output:
Volume group name=rootvg
Number of physical volumes in the volume group=1
Number of active physical volumes in the volume group=1
Number of logical volumes in the volume group=16
Number of logical volumes opened in the volume group=11
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0

The preceding program emulates vmstat behavior and also shows how perfstat_volumegroup is used.