[Patch]additional message queues metrics
"Wu, Liming" <[email protected]>
| Newsgroups | gmane.comp.sysutils.pcp |
|---|---|
| Message-ID | <[email protected]> |
Hi: This patch add some metrics about ipc's message queues . please refer to the attachment for the details. Thanks, -- Liming Wu -- -=-=-=-=-=-=-=-=-=-=-=- pcp mailing list [email protected] https://groups.io/g/pcp/messages -=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#14692): https://groups.io/g/pcp/message/14692 View All Messages In Topic (1): https://groups.io/g/pcp/topic/3119868 Mute This Topic: https://groups.io/mt/3119868?uid=174580 New Topic: https://groups.io/g/pcp/post Change Your Subscription: https://groups.io/g/pcp/editsub?uid=174580 Group Home: https://groups.io/g/pcp Contact Group Owner: [email protected] Terms of Service: https://groups.io/static/tos Unsubscribe: https://groups.io/g/pcp/leave/354243/563757577/xyzzy -=-=-=-=-=-=-=-=-=-=-=-
additional-message-queues-metrics.patch
(application/octet-stream, 10.3 KB)
From 602beafa70abd80853279b560424c0d93b9dc381 Mon Sep 17 00:00:00 2001 From: Liming <[email protected]> Date: Mon, 14 Nov 2016 16:25:22 +0800 Subject: [PATCH] additional message queues metrics --- src/pmdas/linux/clusters.h | 1 + src/pmdas/linux/help | 5 +++ src/pmdas/linux/indom.h | 1 + src/pmdas/linux/ipc.c | 78 +++++++++++++++++++++++++++++++++++++++++++--- src/pmdas/linux/ipc.h | 18 ++++++++--- src/pmdas/linux/pmda.c | 67 +++++++++++++++++++++++++++++++++++++++ src/pmdas/linux/root_linux | 5 +++ 7 files changed, 166 insertions(+), 9 deletions(-) diff --git a/src/pmdas/linux/clusters.h b/src/pmdas/linux/clusters.h index 9b4a3ef..377d313 100644 --- a/src/pmdas/linux/clusters.h +++ b/src/pmdas/linux/clusters.h @@ -85,6 +85,7 @@ enum { CLUSTER_MSG_INFO, /* 62 msgctl(MSG_INFO) system call */ CLUSTER_SOFTIRQS, /* 63 /proc/softirqs percpu counters */ CLUSTER_SHM_STAT, /* 64 shmctl(SHM_STAT) system call */ + CLUSTER_MSG_STAT, /* 65 msgctl(MSG_STAT) system call */ NUM_CLUSTERS /* one more than highest numbered cluster */ }; diff --git a/src/pmdas/linux/help b/src/pmdas/linux/help index c888179..e625e33 100644 --- a/src/pmdas/linux/help +++ b/src/pmdas/linux/help @@ -1499,6 +1499,11 @@ See also the kernel.uname.* metrics @ ipc.msg.used_queues number of message queues that currently exist (from msgctl(..,MSG_INFO,..)) @ ipc.msg.tot_msg total number of messages in all queues (from msgctl(..,MSG_INFO,..)) @ ipc.msg.tot_bytes number of bytes in all messages in all queues (from msgctl(..,MSG_INFO,..)) +@ ipc.msg.key name of these messages slot (from msgctl(..,MSG_STAT,..)) +@ ipc.msg.owner username of owner (from msgctl(..,MSG_STAT,..)) +@ ipc.msg.perms access permissions (from msgctl(..,MSG_STAT,..)) +@ ipc.msg.msgsz used size in bytes (from msgctl(..,MSG_STAT,..)) +@ ipc.msg.messages number of messages currently queued (from msgctl(..,MSG_STAT,..)) @ ipc.shm.max_segsz maximum shared segment size in bytes (from shmctl(..,IPC_INFO,..)) @ ipc.shm.min_segsz minimum shared segment size in bytes (from shmctl(..,IPC_INFO,..)) @ ipc.shm.max_seg maximum number of shared segments in system (from shmctl(..,IPC_INFO,..)) diff --git a/src/pmdas/linux/indom.h b/src/pmdas/linux/indom.h index aa46d27..2497235 100644 --- a/src/pmdas/linux/indom.h +++ b/src/pmdas/linux/indom.h @@ -47,6 +47,7 @@ enum { INTERRUPT_NAMES_INDOM, /* 26 - persistent percpu interrupts IDs */ SOFTIRQS_NAMES_INDOM, /* 27 - persistent percpu softirqs IDs */ IPC_STAT_INDOM, /* 28 - ipc shm_stat shmid */ + IPC_MSG_INDOM, /* 29 - ipc msg_stat msgid */ NUM_INDOMS /* one more than highest numbered cluster */ }; diff --git a/src/pmdas/linux/ipc.c b/src/pmdas/linux/ipc.c index e53c6f2..cd7ba65 100644 --- a/src/pmdas/linux/ipc.c +++ b/src/pmdas/linux/ipc.c @@ -168,13 +168,13 @@ refresh_shm_stat(pmInDom shm_indom) continue; memset(shm_stat, 0, sizeof(shm_stat_t)); - snprintf(shm_stat->shm_key, SHM_KEYLEN, "0x%08x", ipcp->KEY); - shm_stat->shm_key[SHM_KEYLEN-1] = '\0'; + snprintf(shm_stat->shm_key, IPC_KEYLEN, "0x%08x", ipcp->KEY); + shm_stat->shm_key[IPC_KEYLEN-1] = '\0'; if ((pw = getpwuid(ipcp->uid)) != NULL) - strncpy(shm_stat->shm_owner, pw->pw_name, SHM_OWNERLEN); + strncpy(shm_stat->shm_owner, pw->pw_name, IPC_OWNERLEN); else - snprintf(shm_stat->shm_owner, SHM_OWNERLEN, "%d", ipcp->uid); - shm_stat->shm_owner[SHM_OWNERLEN-1] = '\0'; + snprintf(shm_stat->shm_owner, IPC_OWNERLEN, "%d", ipcp->uid); + shm_stat->shm_owner[IPC_OWNERLEN-1] = '\0'; /* convert to octal number */ snprintf(perms, sizeof(perms), "%o", ipcp->mode & 0777); perms[sizeof(perms)-1] = '\0'; @@ -201,3 +201,71 @@ refresh_shm_stat(pmInDom shm_indom) pmdaCacheOp(shm_indom, PMDA_CACHE_SAVE); return 0; } + +int +refresh_msg_que(pmInDom msg_indom) +{ + struct passwd *pw = NULL; + char msgid[IPC_KEYLEN]; + char perms[IPC_KEYLEN]; + int i = 0, maxid = 0; + int sts = 0; + msg_que_t *msg_que = NULL; + struct msqid_ds dummy; + struct msqid_ds msgseg; + + pmdaCacheOp(msg_indom, PMDA_CACHE_INACTIVE); + + maxid = msgctl(0, MSG_STAT, &dummy); + if (maxid < 0) + return -1; + + while (i <= maxid) { + int msgid_o; + struct ipc_perm *ipcp = &msgseg.msg_perm; + + if ((msgid_o = msgctl(i++, MSG_STAT, &msgseg)) < 0) + continue; + + snprintf(msgid, sizeof(msgid), "%d", msgid_o); + msgid[sizeof(msgid)-1] = '\0'; + sts = pmdaCacheLookupName(msg_indom, msgid, NULL, (void **)&msg_que); + if (sts == PMDA_CACHE_ACTIVE) + continue; + + if (sts == PMDA_CACHE_INACTIVE) { + pmdaCacheStore(msg_indom, PMDA_CACHE_ADD, msgid, msg_que); + } + else { + if ((msg_que = (msg_que_t *)malloc(sizeof(msg_que_t))) == NULL) + continue; + memset(msg_que, 0, sizeof(msg_que_t)); + + snprintf(msg_que->msg_key, IPC_KEYLEN, "0x%08x", ipcp->KEY); + msg_que->msg_key[IPC_KEYLEN-1] = '\0'; + if ((pw = getpwuid(ipcp->uid)) != NULL) + strncpy(msg_que->msg_owner, pw->pw_name, IPC_OWNERLEN); + else + snprintf(msg_que->msg_owner, IPC_OWNERLEN, "%d", ipcp->uid); + msg_que->msg_owner[IPC_OWNERLEN-1] = '\0'; + + /* convert to octal number */ + snprintf(perms, sizeof(perms), "%o", ipcp->mode & 0777); + perms[sizeof(perms)-1] = '\0'; + msg_que->msg_perms = atoi(perms); + msg_que->msg_bytes = msgseg.msg_cbytes; + msg_que->messages = msgseg.msg_qnum; + + sts = pmdaCacheStore(msg_indom, PMDA_CACHE_ADD, msgid, (void *)msg_que); + if (sts < 0) { + fprintf(stderr, "Warning: %s: pmdaCacheStore(%s, %s): %s\n", + __FUNCTION__, msgid, msg_que->msg_key, pmErrStr(sts)); + free(msg_que->msg_key); + free(msg_que->msg_owner); + free(msg_que); + } + } + } + pmdaCacheOp(msg_indom, PMDA_CACHE_SAVE); + return 0; +} diff --git a/src/pmdas/linux/ipc.h b/src/pmdas/linux/ipc.h index e5ae8fc..5c04245 100644 --- a/src/pmdas/linux/ipc.h +++ b/src/pmdas/linux/ipc.h @@ -107,12 +107,12 @@ typedef struct { extern int refresh_msg_limits(msg_limits_t *); -#define SHM_KEYLEN 16 -#define SHM_OWNERLEN 128 +#define IPC_KEYLEN 16 +#define IPC_OWNERLEN 128 typedef struct { - char shm_key[SHM_KEYLEN]; /* name of this shm slot */ - char shm_owner[SHM_OWNERLEN]; /* username of owner */ + char shm_key[IPC_KEYLEN]; /* name of this shm slot */ + char shm_owner[IPC_OWNERLEN]; /* username of owner */ unsigned int shm_perms; /* access permissions */ unsigned int shm_bytes; /* segment size in bytes */ unsigned int shm_nattch; /* no. of current attaches */ @@ -120,3 +120,13 @@ typedef struct { } shm_stat_t; extern int refresh_shm_stat(pmInDom shm_indom); + +typedef struct { + char msg_key[IPC_KEYLEN]; /* name of these messages slot */ + char msg_owner[IPC_OWNERLEN]; /* username of owner */ + unsigned int msg_perms; /* access permissions */ + unsigned int msg_bytes; /* used size in bytes */ + unsigned int messages; /* no. of messages */ +} msg_que_t; + +extern int refresh_msg_que(pmInDom msg_indom); diff --git a/src/pmdas/linux/pmda.c b/src/pmdas/linux/pmda.c index 060951f..12d095d 100644 --- a/src/pmdas/linux/pmda.c +++ b/src/pmdas/linux/pmda.c @@ -330,6 +330,7 @@ static pmdaIndom indomtab[] = { { INTERRUPT_NAMES_INDOM, 0, NULL }, { SOFTIRQS_NAMES_INDOM, 0, NULL }, { IPC_STAT_INDOM, 0, NULL }, + { IPC_MSG_INDOM, 0, NULL }, }; @@ -3826,6 +3827,35 @@ static pmdaMetric metrictab[] = { PMDA_PMUNITS(0,0,0,0,0,0) }, }, /* + * message queues stat cluster + */ + +/* ipc.msg.key */ + { NULL, + { PMDA_PMID(CLUSTER_MSG_STAT,0), PM_TYPE_STRING, IPC_MSG_INDOM, PM_SEM_DISCRETE, + PMDA_PMUNITS(0,0,0,0,0,0) }, }, + +/* ipc.msg.owner */ + { NULL, + { PMDA_PMID(CLUSTER_MSG_STAT,1), PM_TYPE_STRING, IPC_MSG_INDOM, PM_SEM_DISCRETE, + PMDA_PMUNITS(0,0,0,0,0,0) }, }, + +/* ipc.msg.perms */ + { NULL, + { PMDA_PMID(CLUSTER_MSG_STAT,2), PM_TYPE_U32, IPC_MSG_INDOM, PM_SEM_INSTANT, + PMDA_PMUNITS(0,0,0,0,0,0) }, }, + +/* ipc.msg.msgsz */ + { NULL, + { PMDA_PMID(CLUSTER_MSG_STAT,3), PM_TYPE_U32, IPC_MSG_INDOM, PM_SEM_DISCRETE, + PMDA_PMUNITS(1,0,0,PM_SPACE_BYTE,0,0) }, }, + +/* ipc.msg.messages */ + { NULL, + { PMDA_PMID(CLUSTER_MSG_STAT,4), PM_TYPE_U32, IPC_MSG_INDOM, PM_SEM_DISCRETE, + PMDA_PMUNITS(0,0,0,0,0,0) }, }, + +/* * number of users cluster */ @@ -4843,6 +4873,9 @@ linux_refresh(pmdaExt *pmda, int *need_refresh, int context) if (need_refresh[CLUSTER_SHM_STAT]) refresh_shm_stat(INDOM(IPC_STAT_INDOM)); + if (need_refresh[CLUSTER_MSG_STAT]) + refresh_msg_que(INDOM(IPC_MSG_INDOM)); + done: if (need_refresh_mtab) pmdaDynamicMetricTable(pmda); @@ -4909,6 +4942,9 @@ linux_instance(pmInDom indom, int inst, char *name, __pmInResult **result, pmdaE case IPC_STAT_INDOM: need_refresh[CLUSTER_SHM_STAT]++; break; + case IPC_MSG_INDOM: + need_refresh[CLUSTER_MSG_STAT]++; + break; /* no default label : pmdaInstance will pick up errors */ } @@ -6224,6 +6260,37 @@ linux_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom) } break; } + + case CLUSTER_MSG_STAT: { + + msg_que_t *msg_que; + + sts = pmdaCacheLookup(INDOM(IPC_MSG_INDOM), inst, NULL, (void **)&msg_que); + if (sts < 0) + return sts; + if (sts != PMDA_CACHE_ACTIVE) + return PM_ERR_INST; + switch (idp->item) { + case 0: /* ipc.msg.key */ + atom->cp = (char *)msg_que->msg_key; + break; + case 1: /* ipc.msg.owner */ + atom->cp = (char *)msg_que->msg_owner; + break; + case 2: /* ipc.msg.perms */ + atom->ul = msg_que->msg_perms; + break; + case 3: /* ipc.msg.msgsz */ + atom->ul = msg_que->msg_bytes; + break; + case 4: /* ipc.shm.messages */ + atom->ul = msg_que->messages; + break; + default: + return PM_ERR_PMID; + } + break; + } /* * Cluster added by Mike Mason <[email protected]> diff --git a/src/pmdas/linux/root_linux b/src/pmdas/linux/root_linux index 1f3b92d..b52778d 100644 --- a/src/pmdas/linux/root_linux +++ b/src/pmdas/linux/root_linux @@ -229,6 +229,11 @@ ipc.msg { used_queues 60:62:0 tot_msg 60:62:1 tot_bytes 60:62:2 + key 60:65:0 + owner 60:65:1 + perms 60:65:2 + msgsz 60:65:3 + messages 60:65:4 } ipc.shm { -- 1.8.3.1