[AIX 성능 도구 8] perfstat API (3) 디스크·경로·어댑터·FC·논리 볼륨
https://archive.horanglab.com/posts/aix-perf-perfstat-3
핵심 정리
perfstat_disk: 디스크마다 이름·설명·VG 이름(ODM), 크기·빈 공간(MB), 전송량(KB) 등.iostat -d와 같은 정보를 프로그램에서 얻습니다.perfstat_diskpath: MPIO 경로마다(hdisk0_Path0) 전송량과 연결된 어댑터 이름.perfstat_diskadapter: 어댑터마다 연결된 디스크의 전체 크기·빈 공간, 전송량.- (6.1)
perfstat_fcstat: 파이버 채널 어댑터 통계,perfstat_hfistat_window: HFI 창별 패킷 통계. perfstat_logicalvolume: LV마다 PP 크기, I/O 요청 수, 읽고 쓴 KB. 먼저perfstat_config(PERFSTAT_ENABLE | PERFSTAT_LV, NULL)로 LV 통계 수집을 켜야 합니다.
| 항목 | 내용 |
|---|---|
| 버전 | AIX 5.3, AIX 6.1 (6.1에서 perfstat_fcstat, perfstat_hfistat_window가 더해짐) |
| 원문 | Performance Tools Guide and Reference — 5.3판 6장(158166쪽), 6.1판 124138쪽 |
| 파일 | /usr/include/libperfstat.h, /usr/samples/libperfstat |
| 관련 명령어 | iostat, lvmstat, fcstat, lspath |
perfstat_disk 인터페이스
perfstat_disk 인터페이스는 libperfstat.h 파일에 정의된 perfstat_disk_t 구조체 묶음을 돌려줍니다.
perfstat_disk_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
name |
디스크 이름(ODM에서) |
description |
디스크 설명(ODM에서) |
vgname |
볼륨 그룹 이름(ODM에서) |
size |
디스크 크기(MB) |
free |
빈 공간(MB) |
xfers |
디스크와 주고받은 전송(KB) |
이 밖에도 디스크 관련 지표(디스크에서 읽고 쓴 블록 수, 어댑터 이름 등)를 돌려줍니다. 전체 목록은 Files Reference의 libperfstat.h 헤더 파일에서 perfstat_disk_t 부분을 봅니다.
다음 프로그램은 diskstat의 동작을 흉내 내며 perfstat_disk 인터페이스를 쓰는 방법을 보여 줍니다.
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
int i, ret, tot;
perfstat_disk_t *statp;
perfstat_id_t first;
/* check how many perfstat_disk_t structures are available */
tot = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0);
/* check for error */
if (tot < 0)
{
perror("perfstat_disk");
exit(-1);
}
if (tot == 0)
{
printf("No disks found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
statp = calloc(tot, sizeof(perfstat_disk_t));
/* set name to first interface */
strcpy(first.name, FIRST_DISK);
/* ask to get all the structures available in one call */
/* return code is number of structures returned */
ret = perfstat_disk(&first, statp,
sizeof(perfstat_disk_t), tot);
/* check for error */
if (ret <= 0)
{
perror("perfstat_disk");
exit(-1);
}
/* print statistics for each of the disks */
for (i = 0; i < ret; i++) {
printf("\nStatistics for disk : %s\n", statp[i].name);
printf("-------------------\n");
printf("description : %s\n", statp[i].description);
printf("volume group name : %s\n", statp[i].vgname);
printf("adapter name : %s\n", statp[i].adapter);
printf("size : %llu MB\n", statp[i].size);
printf("free space : %llu MB\n", statp[i].free);
printf("number of blocks read : %llu blocks of %llu bytes\n", statp[i].rblks, statp[i].bsize);
printf("number of blocks written : %llu blocks of %llu bytes\n", statp[i].wblks, statp[i].bsize);
}
}
이 프로그램은 다음과 같은 출력을 냅니다.
Statistics for disk : hdisk1
-------------------
description : 16 Bit SCSI Disk Drive
volume group name : rootvg
adapter name : scsi0
size : 4296 MB
free space : 2912 MB
number of blocks read : 403946 blocks of 512 bytes
number of blocks written : 768176 blocks of 512 bytes
Statistics for disk : hdisk0
-------------------
description : 16 Bit SCSI Disk Drive
volume group name : None
adapter name : scsi0
size : 0 MB
free space : 0 MB
number of blocks read : 0 blocks of 512 bytes
number of blocks written : 0 blocks of 512 bytes
Statistics for disk : cd0
-------------------
description : SCSI Multimedia CD-ROM Drive
volume group name : not available
adapter name : scsi0
size : 0 MB
free space : 0 MB
number of blocks read : 3128 blocks of 2048 bytes
number of blocks written : 0 blocks of 2048 bytes
영어 원문
perfstat_disk Interface
The perfstat_disk interface returns a set of structures of type perfstat_disk_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_disk_t structure include:
- name — Disk name (from ODM)
- description — Disk description (from ODM)
- vgname — Volume group name (from ODM)
- size — Disk size (in MB)
- free — Free space (in MB)
- xfers — Transfers to/from disk (in KB)
Several other disk-related metrics (such as number of blocks read from and written to disk, and adapter names) are also returned. For a complete list, see the perfstat_disk_t section in the libperfstat.h header file in Files Reference.
The following program emulates diskstat behavior and also shows an example of how the perfstat_disk interface is used:
(47줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The preceding program produces the following output:
(27줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
perfstat_diskpath 인터페이스
perfstat_diskpath 인터페이스는 libperfstat.h 파일에 정의된 perfstat_diskpath_t 구조체 묶음을 돌려줍니다.
perfstat_diskpath_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
name |
경로 이름(<disk_name>_Path<path_id>) |
xfers |
이 경로를 거친 전체 전송(KB) |
adapter |
경로에 연결된 어댑터 이름 |
이 밖에도 디스크 경로 관련 지표(경로를 거쳐 읽고 쓴 블록 수 등)를 돌려줍니다. 전체 목록은 libperfstat.h 헤더 파일의 perfstat_diskpath_t 부분을 봅니다.
다음 코드는 perfstat_diskpath 인터페이스를 쓰는 예입니다.
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(int argc, char* argv[]) {
int ret, tot, i;
perfstat_diskpath_t *statp;
perfstat_id_t first;
char *substring;
perfstat_disk_t dstat;
/* check how many perfstat_diskpath_t structures are available */
tot = perfstat_diskpath(NULL, NULL, sizeof(perfstat_diskpath_t), 0);
/* check for error */
if (tot < 0)
{
perror("perfstat_diskpath");
exit(-1);
}
if (tot == 0)
{
printf("No Paths found in the system\n");
exit(-1);
}
/* allocate enough memory for all the structures */
statp = calloc(tot, sizeof(perfstat_diskpath_t));
if(statp==NULL){
printf("No sufficient memory\n");
exit(-1);
}
/* set name to first interface */
strcpy(first.name, FIRST_DISKPATH);
/* ask to get all the structures available in one call */
/* return code is number of structures returned */
ret = perfstat_diskpath(&first, statp, sizeof(perfstat_diskpath_t), tot);
/* check for error */
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
/* print statistics for each of the disk paths */
for (i = 0; i < ret; i++) {
printf("\nStatistics for disk path : %s\n", statp[i].name);
printf("----------------------\n");
printf("number of blocks read : %llu\n", statp[i].rblks);
printf("number of blocks written : %llu\n", statp[i].wblks);
printf("adapter name : %s\n", statp[i].adapter);
}
/* retrieve paths for last disk if any */
if (ret > 0) {
/* extract the disk name from the last disk path name */
substring = strstr(statp[ret-1].name, "_Path");
if (substring == NULL) {
return (-1);
}
substring[0] = ’\0’;
/* set name to the disk name */
strcpy(first.name, substring);
/* retrieve info about disk */
ret = perfstat_disk(&first, &dstat, sizeof(perfstat_disk_t),1);
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
printf("\nPaths for disk path : %s (%d)\n", dstat.name, dstat.paths_count);
printf("----------------------\n");
/* retrieve all paths for this disk */
ret = perfstat_diskpath(&first, statp, sizeof(perfstat_diskpath_t), dstat.paths_count);
if (ret <= 0)
{
perror("perfstat_diskpath");
exit(-1);
}
/* print statistics for each of the paths */
for (i = 0; i < ret; i++) {
printf("\nStatistics for disk path : %s\n", statp[i].name);
printf("----------------------\n");
printf("number of blocks read : %llu\n", statp[i].rblks);
printf("number of blocks written : %llu\n", statp[i].wblks);
printf("adapter name : %s\n", statp[i].adapter);
}
}
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0
Paths for disk path : hdisk0 (1)
----------------------
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0
영어 원문
perfstat_diskpath Interface
The perfstat_diskpath interface returns a set of structures of type perfstat_diskpath_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_diskpath_t structure include:
- name — Path name (
<disk_name>_Path<path_id>) - xfers — Total transfers through this path (in KB)
- adapter — Name of the adapter linked to the path
Several other disk path-related metrics (such as the number of blocks read from and written through the path) are also returned. For a complete list, see the perfstat_diskpath_t section in the libperfstat.h header file.
The following code shows an example of how the perfstat_diskpath interface is used:
(83줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0
Paths for disk path : hdisk0 (1)
----------------------
Statistics for disk path : hdisk0_Path0
----------------------
number of blocks read : 335354
number of blocks written : 291416
adapter name : vscsi0
perfstat_diskadapter 인터페이스
perfstat_diskadapter 인터페이스는 libperfstat.h 파일에 정의된 perfstat_diskadapter_t 구조체 묶음을 돌려줍니다.
perfstat_diskadapter_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
name |
어댑터 이름(ODM에서) |
description |
어댑터 설명(ODM에서) |
size |
이 어댑터에 연결된 디스크의 전체 크기(MB) |
free |
이 어댑터에 연결된 디스크의 전체 빈 공간(MB) |
xfers |
이 어댑터와 주고받은 전체 전송(KB) |
이 밖에도 디스크 어댑터 관련 지표(어댑터에서 읽고 쓴 블록 수 등)를 돌려줍니다. 전체 목록은 libperfstat.h 헤더 파일의 perfstat_diskadapter_t 부분을 봅니다.
다음 프로그램은 diskadapterstat의 동작을 흉내 내며 perfstat_diskadapter 인터페이스를 쓰는 방법을 보여 줍니다.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <libperfstat.h>
#include <errno.h>
#include <wpars/wparcfg.h>
/* Non zero WPAR ID indicates WPAR */
#define IS_WPAR(X) ((X))
/* To Check whether malloc is successful or not */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
/* Default values for interval and count */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Function prototypes */
static int do_initialization(void);
static void do_cleanup(void);
static void collect_disk_metrics(void);
static void print_disk_header(void);
static void showusage(char *);
/* variables and data structures declaration */
static perfstat_diskadapter_t *statp, *statq;
static int num_adapt;
static int interval = INTERVAL_DEFAULT;
static int count = COUNT_DEFAULT;
static int rc;
/* support for remote node statistics collection in a cluster environment */
static perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
cid_t cid; /* store the WPAR cid */
/*
* NAME: do_initialization
* This function initializes the data structues.
* It also collects initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exit with code 1.
*/
static int do_initialization(void)
{
if (collect_remote_node_stats){
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
/* Get the total number of disk adapters available in the current system */
num_adapt = perfstat_diskadapter_node(&nodeid, NULL, sizeof(perfstat_diskadapter_t), 0);
}
else{
/* Get the total number of disk adapters available in the current system */
num_adapt = perfstat_diskadapter(NULL, NULL, sizeof(perfstat_diskadapter_t), 0);
}
if (num_adapt == 0) {
printf("There are no disk adapters.\n");
exit(0);
}
if (num_adapt < 0) {
perror("perfstat_diskadapter: ");
exit(1);
}
/* Allocate sufficient memory for perfstat structures */
statp = (perfstat_diskadapter_t *)malloc(sizeof(perfstat_diskadapter_t) * num_adapt);
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_diskadapter_t *)malloc(sizeof(perfstat_diskadapter_t) * num_adapt);
CHECK_FOR_MALLOC_NULL(statq);
/* Make the structures as 0 */
memset(statq, 0, (sizeof(perfstat_diskadapter_t) * num_adapt));
memset(statp, 0, (sizeof(perfstat_diskadapter_t) * num_adapt));
return (0);
}
/*
*NAME: Showusage
* This function displays the usage
*/
void showusage (char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds> ] [-c <number of iterations> ] [-n <node name in the cluster> ]\n", cmd);
exit(1);
}
/*
* NAME: do_cleanup
* This function frees the memory allocated for the perfstat structures.
*
*/
static void do_cleanup(void)
{
if (statp) {
free(statp);
}
if (statq) {
free(statq);
}
}
/*
* NAME: collect_diskadapter_metrics
* This function collects the raw values in to
* the specified structures and derive the metrics from the
* raw values
*
*/
void collect_diskadapter_metrics(void)
{
perfstat_id_t first;
unsigned long long delta_read, delta_write,delta_xfers, delta_xrate;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
strcpy(nodeid.name, FIRST_DISKADAPTER);
rc = perfstat_diskadapter_node(&nodeid ,statq, sizeof(perfstat_diskadapter_t),num_adapt);
}
else {
strcpy(first.name, FIRST_DISKADAPTER);
rc = perfstat_diskadapter(&first ,statq, sizeof(perfstat_diskadapter_t),num_adapt);
}
if (rc < num_adapt){
perror("perfstat_diskadapter: ");
exit(1);
}
/* Name - name of the diskadapter
* Disks- number of disks connected
* Size - total size of all the disks
* Free - free space on disk
* ARS - average read per second
* AWS - average write per second
*/
printf("\n%-8s %7s %8s %8s %8s %8s\n", " Name ", " Disks ", " Size ", " Free ", " ARS ", " AWS ");
printf("%-8s %7s %8s %8s %8s %8s\n", "======", "======", "======", "======", "=====", "=====");
while (count > 0) {
sleep(interval);
if(collect_remote_node_stats) {
rc = perfstat_diskadapter_node(&nodeid, statp, sizeof(perfstat_diskadapter_t), num_adapt);
}
else {
rc = perfstat_diskadapter(&first ,statp, sizeof(perfstat_diskadapter_t),num_adapt);
}
if (rc < num_adapt ) {
perror("perfstat_diskadapter:");
exit(-1);
}
/* print statistics for each of the diskadapter */
for (int i = 0; i < rc; i++) {
delta_write = statp[i].wblks - statq[i].wblks;
delta_read = statp[i].rblks - statq[i].rblks;
delta_xfers = statp[i].xfers - statq[i].xfers;
delta_xrate = statp[i].xrate - statq[i].xrate;
printf("%-8s %7d %8llu %8llu %8llu %8llu\n", statp[i].name, statp[i].number,
statp[i].size, statp[i].free, (u_longlong_t)(delta_read / (statp[i].xrate - statq[i].xrate)),
(u_longlong_t)(delta_write / (delta_xfers - delta_xrate)));
}
/* copy to the old data structures */
memcpy(statq, statp, sizeof(perfstat_diskadapter_t) * num_adapt);
count--;
printf("\n");
}
/* Free all the memory allocated for all the data structures */
do_cleanup();
}
/*
*NAME: main
*
*/
int main(int argc, char* argv[])
{
int i;
cid = corral_getcid();
/* Check Whether running Inside WPAR or on Global*/
if(IS_WPAR(cid)) {
printf("The metrics requested for WPAR cannot be retrieved.\n");
exit(1);
}
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:")) != EOF)
{
switch(i)
{
case ’i’: /* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’: /* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
/* call the functions to collect the metrics and display them */
collect_diskadapter_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
return (0);
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Name Disks Size Free ARS AWS
====== ====== ====== ====== ===== =====
vscsi0 1 25568 19616 1 9
영어 원문
perfstat_diskadapter Interface
The perfstat_diskadapter interface returns a set of structures of type perfstat_diskadapter_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_diskadapter_t structure include:
- name — Adapter name (from ODM)
- description — Adapter description (from ODM)
- size — Total disk size connected to this adapter (in MB)
- free — Total free space on disks connected to this adapter (in MB)
- xfers — Total transfers to/from this adapter (in KB)
Several other disk adapter-related metrics (such as the number of blocks read from and written to the adapter) are also returned. For a complete list, see the perfstat_diskadapter_t section in the libperfstat.h header file.
The following program emulates the diskadapterstat behavior and also shows an example of how the
perfstat_diskadapter interface is used
(219줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
Name Disks Size Free ARS AWS
====== ====== ====== ====== ===== =====
vscsi0 1 25568 19616 1 9
(6.1) perfstat_fcstat 인터페이스
perfstat_fcstat 인터페이스는 libperfstat.h 파일에 정의된 perfstat_fcstat_t 구조체 묶음을 돌려줍니다.
다음 프로그램은 perfstat_fcstat 인터페이스를 쓰는 예입니다.
/* The sample program displays the metrics *
* related to every Individual *
* Fiber Channel adapter in the LPAR */
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
/* define default interval and count values */
#define INTERVAL_DEFAULT 1
#define COUNT_DEFAULT 1
/* Check value returned by malloc for NULL */
#define CHECK_FOR_MALLOC_NULL(X) { if ((X) == NULL) {\
perror ("malloc");\
exit(2);\
}\
}
int count = COUNT_DEFAULT, interval = INTERVAL_DEFAULT, tot=0;
int returncode=0;
/* store the data structures */
static perfstat_fcstat_t *statp=NULL ,*statq=NULL;
/* support for remote node statistics collection in a cluster environment */
perfstat_id_node_t nodeid;
static char nodename[MAXHOSTNAMELEN] = "";
static int collect_remote_node_stats = 0;
unsigned long long wwpn_id=0;
int fc_flag=0, wwpn_flag=0;
char fcadapter_name[MAXHOSTNAMELEN];
/*
* NAME: showusage
* to display the usage
*
*/
void showusage(char *cmd)
{
fprintf (stderr, "usage: %s [-i <interval in seconds> ] [-c <number of iterations> ] [-n <node name in the cluster> ] [-a FC adapter name] [-w worldwide port name]] \n", cmd);
exit(1);
}
/*
* NAME: do_initialization
* This function initializes the data structures.
* It also collects the initial set of values.
*
* RETURNS:
* On successful completion:
* - returns 0.
* In case of error
* - exits with code 1.
*/
int do_initialization(void)
{
/* check how many perfstat_fcstat_t structures are available */
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
tot = perfstat_fcstat_node(&nodeid, NULL, sizeof(perfstat_fcstat_t), 0)
;
}
else if(fc_flag == 1 && wwpn_flag == 1)
{
tot = perfstat_fcstat_wwpn(NULL, NULL, sizeof(perfstat_fcstat_t), 0);
if(tot >= 1)
{
tot = 1;
}
else
{
printf("There is no FC adapter \n");
exit(-1);
}
}
else
{
tot = perfstat_fcstat(NULL, NULL, sizeof(perfstat_fcstat_t), 0);
}
if (tot <= 0) {
printf("There is no FC adapter\n");
exit(0);
}
/* allocate enough memory for all the structures */
statp = (perfstat_fcstat_t *)malloc(tot * sizeof(perfstat_fcstat_t));
CHECK_FOR_MALLOC_NULL(statp);
statq = (perfstat_fcstat_t *)malloc(tot * sizeof(perfstat_fcstat_t));
CHECK_FOR_MALLOC_NULL(statq);
return(0);
}
/*
*Name: display_metrics
* collect the metrics and display them
*
*/
void display_metrics()
{
perfstat_id_t first;
perfstat_wwpn_id_t wwpn;
int ret=0, i=0;
if(collect_remote_node_stats) {
strncpy(nodeid.u.nodename, nodename, MAXHOSTNAMELEN);
nodeid.spec = NODENAME;
strcpy(nodeid.name , FIRST_NETINTERFACE);
ret = perfstat_fcstat_node(&nodeid, statq, sizeof(perfstat_fcstat_t), tot);
} else if((fc_flag == 1) && (wwpn_flag == 1)) {
strcpy(wwpn.name , fcadapter_name);
wwpn.initiator_wwpn_name = wwpn_id;
ret = perfstat_fcstat_wwpn( &wwpn, statq, sizeof(perfstat_fcstat_t), tot);
}
else
{
strcpy(first.name , FIRST_NETINTERFACE);
ret = perfstat_fcstat( &first, statq, sizeof(perfstat_fcstat_t), tot);
}
if (ret < 0)
{
free(statp);
free(statq);
perror("perfstat_fcstat: ");
exit(1);
}
while (count)
{
sleep (interval);
if(collect_remote_node_stats) {
ret = perfstat_fcstat_node(&nodeid, statp, sizeof(perfstat_fcstat_t), tot);
}
if((fc_flag == 1) && (wwpn_flag == 1))
{
strcpy(wwpn.name , fcadapter_name);
wwpn.initiator_wwpn_name = wwpn_id;
ret = perfstat_fcstat_wwpn(&wwpn, statp, sizeof(perfstat_fcstat_t), tot);
}
else
{
ret = perfstat_fcstat(&first, statp, sizeof(perfstat_fcstat_t), tot);
}
/* print statistics for the Fiber channel */
for (i = 0; i < ret; i++) {
printf(" FC Adapter name: %s \n", statp[i].name);
printf(" ======================== Traffic Statistics ============================\n");
printf(" Number of Input Requests: %lld \n",
statp[i].InputRequests - statq[i].InputRequests);
printf(" Number of Output Requests: %lld \n",
statp[i].OutputRequests - statq[i].OutputRequests);
printf(" Number of Input Bytes : %lld \n",
statp[i].InputBytes - statq[i].InputBytes);
printf(" Number of Output Bytes : %lld \n",
statp[i].OutputBytes - statq[i].OutputBytes);
printf(" ======================== Transfer Statistics ============================\n");
printf(" Adapter’s Effective Maximum Transfer Value : %lld \n",
statp[i].EffMaxTransfer - statq[i].EffMaxTransfer);
printf(" ======================== Driver Statistics ============================\n");
printf(" Count of DMA failures: %lld \n",
statp[i].NoDMAResourceCnt - statq[i].NoDMAResourceCnt);
printf(" No command resource available :%lld \n",
statp[i].NoCmdResourceCnt - statq[i].NoCmdResourceCnt);
printf(" Link Indicator : %d \n", statp[i].AttentionType);
printf(" ======================== CHBA Statistics ============================\n");
printf(" Seconds since last reset of the statistics on the adapter: %lld \n",
statp[i].SecondsSinceLastReset - statq[i].SecondsSinceLastReset);
printf(" Number of frames transmitted: %lld \n",
statp[i].TxFrames - statq[i].TxFrames);
printf(" Fiber Channel Kbytes transmitted : %lld \n",
statp[i].TxWords - statq[i].TxWords);
printf(" Number of Frames Received.: %lld \n",
statp[i].RxFrames - statq[i].RxFrames);
printf(" Fiber Channel Kbytes Received : %lld \n",
statp[i].RxWords - statq[i].RxWords);
printf(" Loop Initialization Protocol(LIP) Count: %lld \n",
statp[i].LIPCount - statq[i].LIPCount);
printf(" NOS(Not_Operational) Count : %lld \n",
statp[i].NOSCount - statq[i].NOSCount);
printf(" Number of frames received with the CRC Error : %lld \n",
statp[i].ErrorFrames - statq[i].ErrorFrames);
printf(" Number of lost frames : %lld \n",
statp[i].DumpedFrames - statq[i].DumpedFrames);
printf(" Count of Link failures: %lld \n",
statp[i].LinkFailureCount - statq[i].LinkFailureCount);
printf(" Count of loss of sync : %lld \n",
statp[i].LossofSyncCount - statq[i].LossofSyncCount);
printf(" Count of loss of Signal:%lld \n",
statp[i].LossofSignal - statq[i].LossofSignal);
printf(" Number of times a primitive sequence was in error :%lld \n",
statp[i].PrimitiveSeqProtocolErrCount - statq[i].PrimitiveSeqProtocolErrCount);
printf(" Count of Invalid Transmission words received : %lld \n",
statp[i].InvalidTxWordCount - statq[i].InvalidTxWordCount);
printf(" Count of CRC Errors in a Received Frame :%lld \n",
statp[i].InvalidCRCCount - statq[i].InvalidCRCCount);
printf(" SCSI Id of the adapter : %lld \n",
statp[i].PortFcId);
printf(" Speed of Adapter in GBIT : %lld \n",
statp[i].PortSpeed);
printf(" Connection Type: %s \n",
statp[i].PortType);
printf(" worldwide port name : %lld \n",
statp[i].PortWWN);
printf(" Supported Port Speed in GBIT: %lld \n",
statp[i].PortSupportedSpeed);
printf(" ================================== End ===============================\n");
}
memcpy(statq, statp, (tot * sizeof(perfstat_fcstat_t)));
count--;
}
}
/*
*Name: main
*
*/
int main(int argc, char *argv[])
{
int i=0, rc=0;
/* get the interval and count values */
/* Process the arguments */
while ((i = getopt(argc, argv, "i:c:n:a:w")) != EOF)
{
switch(i)
{
case ’i’: /* Interval */
interval = atoi(optarg);
if( interval <= 0 )
interval = INTERVAL_DEFAULT;
break;
case ’c’: /* Number of interations */
count = atoi(optarg);
if( count <= 0 )
count = COUNT_DEFAULT;
break;
case ’n’: /* Node name in a cluster environment */
strncpy(nodename, optarg, MAXHOSTNAMELEN);
nodename[MAXHOSTNAMELEN-1] = ’\0’;
collect_remote_node_stats = 1;
break;
case ’a’: /* Fiber Channel Adapter Name */
strncpy(fcadapter_name, optarg, MAXHOSTNAMELEN);
fcadapter_name[MAXHOSTNAMELEN-1] = ’\0’;
fc_flag = 1;
break;
case ’w’: /* Worldwide port name(WWPN) */
wwpn_id = (unsigned long long) (atoll(optarg));
wwpn_flag = 1;
break;
default:
/* Invalid arguments. Print the usage and terminate */
showusage(argv[0]);
}
}
if((fc_flag == 1))
{
if(fcadapter_name == NULL )
{
fprintf(stderr, "FC adapter Name should not be NULL");
exit(-1);
}
}
if(wwpn_flag == 1)
{
if(wwpn_id < 0 )
{
fprintf(stderr, "WWPN id should not be negavite ");
exit(-1);
}
}
if(collect_remote_node_stats)
{ /* perfstat_config needs to be called to enable cluster statistics collection */
rc = perfstat_config(PERFSTAT_ENABLE|PERFSTAT_CLUSTER_STATS, NULL);
if (rc == -1)
{
perror("cluster statistics collection is not available");
exit(-1);
}
}
do_initialization();
display_metrics();
if(collect_remote_node_stats)
{ /* Now disable cluster statistics by calling perfstat_config */
perfstat_config(PERFSTAT_DISABLE|PERFSTAT_CLUSTER_STATS, NULL);
}
free(statp);
free(statq);
return 0;
}
영어 원문
perfstat_fcstat Interface
The perfstat_fcstat interface returns a set of structures of type perfstat_fcstat_t, which is defined in the libperfstat.h file.
The following program is an example of how the perfstat_fcstat interface is used:
(277줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
(6.1) perfstat_hfistat_window 인터페이스
perfstat_hfistat_window 인터페이스는 libperfstat.h 파일에 정의된 perfstat_hfistat_window_t 구조체 묶음을 돌려줍니다.
perfstat_hfistat_window_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
pkts_sent |
보낸 패킷 수(56비트 카운터) |
pkts_dropped_sending |
보내지 못하고 버린 패킷 수(40비트 카운터) |
pkts_received |
받은 패킷 수(56비트 카운터) |
영어 원문
perfstat_hfistat_window Interface
The perfstat_hfistat_window interface returns a set of structures of type perfstat_hfistat_window_t, which is defined in the libperfstat.h file.
Selected fields from the perfstat_hfistat_window_t structure include:
pkts_sent— The number of packets sent (56 bit counter).pkts_dropped_sending— The number of packets that were dropped from sending (40 bit counter).pkts_received— The number of the packets that were received (56 bit counter).
perfstat_logicalvolume 인터페이스
perfstat_logicalvolume 인터페이스는 libperfstat.h 파일에 정의된 perfstat_logicalvolume_t 구조체 묶음을 돌려줍니다.
perfstat_logicalvolume_t 구조체의 주요 필드는 다음과 같습니다.
| 필드 | 설명 |
|---|---|
ppsize |
물리 파티션 크기(MB) |
iocnt |
읽기·쓰기 요청 수 |
kbreads |
읽은 KB 수 |
kbwrites |
쓴 KB 수 |
이 밖에도 논리 볼륨 관련 지표(이름, 유형, 활성 여부 등)를 돌려줍니다. 전체 목록은 Files Reference의 libperfstat.h 헤더 파일에서 perfstat_logicalvolume_t 부분을 봅니다.
참고: 논리 볼륨 통계 수집을 켜려면 perfstat_config(PERFSTAT_ENABLE | PERFSTAT_LV, NULL)을 불러야 합니다.
다음 코드는 perfstat_logicalvolume 인터페이스를 쓰는 예입니다.
#include <stdio.h>
#include <stdlib.h>
#include <libperfstat.h>
int main(){
int lv_count,i, rc;
perfstat_id_t first;
perfstat_logicalvolume_t *lv;
strcpy(first.name,NULL);
/* enable the logical volume statistical collection */
perfstat_config(PERFSTAT_ENABLE | PERFSTAT_LV,NULL);
/* get the number of logical volumes */
lv_count = perfstat_logicalvolume (NULL, NULL, sizeof(perfstat_logicalvolume_t), 0);
/* check the subroutine return code for any error */
if (lv_count == -1){
perror("perfstat_logicalvolume");
exit(-1);
}
/* Allocate enough memory to hold all the structures */
lv = (perfstat_logicalvolume_t *)calloc(lv_count, sizeof(perfstat_logicalvolume_t));
if (lv == NULL){
perror(".malloc");
exit(-1);
}
/* Call the API to get the data */
rc = perfstat_logicalvolume(&first,(perfstat_logicalvolume_t*)lv,
sizeof(perfstat_logicalvolume_t),lv_count);
/* check the return code for any error */
if (rc == -1){
perror("perfstat_logical volume ");
exit(-1);
}
for(i=0;i<lv_count;i++){
printf("\n");
printf("Logical volume name=%s\n",lv[i].name);
printf("Volume group name=%s\n",lv[i].vgname);
printf("Physical partition size in MB=%lld\n",lv[i].ppsize);
printf("total number of logical paritions configured for this logical volume=%lld\n",lv[i].logical_partitions);
printf("number of physical mirrors for each logical partition=%lu\n",lv[i].mirrors);
printf("Number of read and write requests=%lu\n",lv[i].iocnt);
printf("Number of Kilobytes read=%lld\n",lv[i].kbreads);
printf("Number of Kilobytes written=%lld\n",lv[i].kbwrites);
}
/* disable logical volume statistical collection */
perfstat_config(PERFSTAT_DISABLE | PERFSTAT_LV , NULL);
}
이 프로그램은 다음과 비슷한 출력을 냅니다.
Logical volume name=hd5
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd6
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=16
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd8
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd4
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=2
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd2
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=31
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd9var
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd10opt
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd3
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=4
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd1
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=74
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=hd11admin
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=4
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=lg_dumplv
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=32
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=livedump
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=8
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=fslv00
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=3
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
Logical volume name=fslv01
Volume group name=rootvg
Physical partition size in MB=32
total number of logical paritions configured for this logical volume=1
number of physical mirrors for each logical partition=1
Number of read and write requests=0
Number of Kilobytes read=0
Number of Kilobytes written=0
영어 원문
perfstat_logicalvolume Interface
The perfstat_logicalvolume 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:
- Ppsize — Physical partition size (in MB)
- Iocnt — Number of read and write requests
- Kbreads — Number of kilobytes read
- Kbwrites — Number of kilobytes written
Several other paging-space-related metrics (such as name, type, and active) are also returned. For a complete list of other paging-space-related metrics, see the perfstat_logicalvolume_t section in the libperfstat.h header file in Files Reference.
Note: The perfstat_config (PERFSTAT_ENABLE | PERFSTAT_LV, NULL) must be used to enable the logical volume statistical collection.
The following code shows an example of how the perfstat_logicalvolume interface is used:
(45줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The program displays an output that is similar to the following example output:
(112줄짜리 예는 위 한글 본문에 그대로 실었습니다.)
The preceding program emulates vmstat behavior and also shows how perfstat_logicalvolume is used.