[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 semaphore arrays . 
   please refer to the attachment for the details.
   Output is as follows
    ipc.sem.key
    		inst [0 or "131072"] value "0x7e94ea42"
 
    ipc.sem.owner
   		 inst [0 or "131072"] value "root"
 
	ipc.sem.perms
    		inst [0 or "131072"] value 644
 
	ipc.sem.nsems
   		 inst [0 or "131072"] value 100

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 (#14848): https://groups.io/g/pcp/message/14848
View All Messages In Topic (1): https://groups.io/g/pcp/topic/3304076
Mute This Topic: https://groups.io/mt/3304076?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-semaphore-arrays-metrics.patch (application/octet-stream, 8.4 KB)
From 9d8102c8393d0bfa962e524ac44362a6bc825aa0 Mon Sep 17 00:00:00 2001
From: Liming <[email protected]>
Date: Wed, 30 Nov 2016 16:57:56 +0800
Subject: [PATCH] additional semaphore arrays metrics

these metrics is read from semctl(..,SEM_STAT,..).
---
 src/pmdas/linux/clusters.h |  1 +
 src/pmdas/linux/help       |  4 +++
 src/pmdas/linux/indom.h    |  1 +
 src/pmdas/linux/ipc.c      | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 src/pmdas/linux/ipc.h      |  9 ++++++
 src/pmdas/linux/pmda.c     | 61 +++++++++++++++++++++++++++++++++++++++-
 src/pmdas/linux/root_linux |  4 +++
 7 files changed, 149 insertions(+), 1 deletion(-)

diff --git a/src/pmdas/linux/clusters.h b/src/pmdas/linux/clusters.h
index 377d313..41fe359 100644
--- a/src/pmdas/linux/clusters.h
+++ b/src/pmdas/linux/clusters.h
@@ -86,6 +86,7 @@ enum {
 	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 */
+	CLUSTER_SEM_STAT,	/* 66 msgctl(SEM_STAT) system call */
 
 	NUM_CLUSTERS		/* one more than highest numbered cluster */
 };
diff --git a/src/pmdas/linux/help b/src/pmdas/linux/help
index e28b82f..7368676 100644
--- a/src/pmdas/linux/help
+++ b/src/pmdas/linux/help
@@ -1488,6 +1488,10 @@ See also the kernel.uname.* metrics
 @ ipc.sem.max_exit adjust on exit maximum value (from semctl(..,IPC_INFO,..))
 @ ipc.sem.used_sem number of semaphore sets currently on the system (from semctl(..,SEM_INFO,..))
 @ ipc.sem.tot_sem number of semaphores in all sets on the system (from semctl(..,SEM_INFO,..))
+@ ipc.sem.key key of these semaphore (from msgctl(..,SEM_STAT,..))
+@ ipc.sem.owner username of owner (from msgctl(..,SEM_STAT,..))
+@ ipc.sem.perms access permissions (from msgctl(..,SEM_STAT,..))
+@ ipc.sem.nsems number of semaphore (from semctl(..,SEM_STAT,..))
 @ ipc.msg.sz_pool size of message pool in kilobytes (from msgctl(..,IPC_INFO,..))
 @ ipc.msg.mapent number of entries in a message map (from msgctl(..,IPC_INFO,..))
 @ ipc.msg.max_msgsz maximum size of a message in bytes (from msgctl(..,IPC_INFO,..))
diff --git a/src/pmdas/linux/indom.h b/src/pmdas/linux/indom.h
index a93dd6d..bb10d40 100644
--- a/src/pmdas/linux/indom.h
+++ b/src/pmdas/linux/indom.h
@@ -48,6 +48,7 @@ enum {
 	SOFTIRQS_NAMES_INDOM,	/* 27 - persistent percpu softirqs IDs */
 	IPC_STAT_INDOM,	        /* 28 - ipc shm_stat shmid */
 	IPC_MSG_INDOM,	        /* 29 - ipc msg_stat msgid */
+	IPC_SEM_INDOM,	        /* 30 - ipc sem_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 0d7e505..a4de36f 100644
--- a/src/pmdas/linux/ipc.c
+++ b/src/pmdas/linux/ipc.c
@@ -280,3 +280,73 @@ refresh_msg_que(pmInDom msg_indom)
     pmdaCacheOp(msg_indom, PMDA_CACHE_SAVE);
     return 0;
 }
+
+int 
+refresh_sem_array(pmInDom sem_indom)
+{
+    struct passwd *pw = NULL;
+    char semid[IPC_KEYLEN]; 
+    char perms[IPC_KEYLEN];
+    int i = 0, maxid = 0;
+    int sts = 0;
+    sem_array_t *sem_arr = NULL;
+    struct seminfo dummy;
+    static union semun arg;
+    struct semid_ds semseg;  
+
+    pmdaCacheOp(sem_indom, PMDA_CACHE_INACTIVE);
+
+    arg.array = (unsigned short *) &dummy;
+    maxid = semctl(0, 0, SEM_INFO, arg);
+    if (maxid < 0)
+	return -1;
+ 
+    while (i <= maxid) {
+	int semid_o;
+        struct ipc_perm *ipcp = &semseg.sem_perm; 
+        arg.buf = (struct semid_ds *)&semseg;
+
+	if ((semid_o = semctl(i++, 0, SEM_STAT, arg)) < 0)
+	    continue;
+
+	snprintf(semid, sizeof(semid), "%d", semid_o);
+	semid[sizeof(semid)-1] = '\0';
+	sts = pmdaCacheLookupName(sem_indom, semid, NULL, (void **)&sem_arr);
+	if (sts == PMDA_CACHE_ACTIVE)
+	    continue;
+
+	if (sts == PMDA_CACHE_INACTIVE) {
+	    pmdaCacheStore(sem_indom, PMDA_CACHE_ADD, semid, sem_arr);
+	}
+	else {
+	    if ((sem_arr = (sem_array_t *)malloc(sizeof(sem_array_t))) == NULL)
+		continue;
+	    memset(sem_arr, 0, sizeof(sem_array_t));
+
+	    snprintf(sem_arr->sem_key, IPC_KEYLEN, "0x%08x", ipcp->KEY); 
+	    sem_arr->sem_key[IPC_KEYLEN-1] = '\0';
+	    if ((pw = getpwuid(ipcp->uid)) != NULL)
+		strncpy(sem_arr->sem_owner, pw->pw_name, IPC_OWNERLEN);
+	    else
+		snprintf(sem_arr->sem_owner, IPC_OWNERLEN, "%d", ipcp->uid);
+	    sem_arr->sem_owner[IPC_OWNERLEN-1] = '\0';
+
+	    /* convert to octal number */
+	    snprintf(perms, sizeof(perms), "%o", ipcp->mode & 0777);
+	    perms[sizeof(perms)-1] = '\0';
+	    sem_arr->sem_perms     = atoi(perms);
+	    sem_arr->nsems      = semseg.sem_nsems;
+
+	    sts = pmdaCacheStore(sem_indom, PMDA_CACHE_ADD, semid, (void *)sem_arr);
+	    if (sts < 0) {
+		fprintf(stderr, "Warning: %s: pmdaCacheStore(%s, %s): %s\n",
+			__FUNCTION__, semid, sem_arr->sem_key, pmErrStr(sts));
+		free(sem_arr->sem_key);
+		free(sem_arr->sem_owner);
+		free(sem_arr);
+	    }	
+	}
+    }
+    pmdaCacheOp(sem_indom, PMDA_CACHE_SAVE);
+    return 0;
+}
diff --git a/src/pmdas/linux/ipc.h b/src/pmdas/linux/ipc.h
index 5c04245..5df4321 100644
--- a/src/pmdas/linux/ipc.h
+++ b/src/pmdas/linux/ipc.h
@@ -130,3 +130,12 @@ typedef struct {
 } msg_que_t;
 
 extern int refresh_msg_que(pmInDom msg_indom);
+
+typedef struct {
+        char                sem_key[IPC_KEYLEN]; /* name of these messages slot */
+        char                sem_owner[IPC_OWNERLEN]; /* username of owner */
+        unsigned int        sem_perms;		/* access permissions */
+        unsigned int        nsems;	        /* no. of semaphore */
+} sem_array_t;
+
+extern int refresh_sem_array(pmInDom sem_indom);
diff --git a/src/pmdas/linux/pmda.c b/src/pmdas/linux/pmda.c
index 4fef790..d8b041d 100644
--- a/src/pmdas/linux/pmda.c
+++ b/src/pmdas/linux/pmda.c
@@ -331,6 +331,7 @@ static pmdaIndom indomtab[] = {
     { SOFTIRQS_NAMES_INDOM, 0, NULL },
     { IPC_STAT_INDOM, 0, NULL },
     { IPC_MSG_INDOM, 0, NULL },
+    { IPC_SEM_INDOM, 0, NULL },
 };
 
 
@@ -3856,6 +3857,30 @@ static pmdaMetric metrictab[] = {
     PMDA_PMUNITS(0,0,0,0,0,0) }, },
 
 /*
+ * semaphore arrays stat cluster
+ */
+
+/* ipc.sem.key */
+  { NULL,
+    { PMDA_PMID(CLUSTER_SEM_STAT,0), PM_TYPE_STRING, IPC_SEM_INDOM, PM_SEM_DISCRETE, 
+    PMDA_PMUNITS(0,0,0,0,0,0) }, },
+
+/* ipc.sem.owner */
+  { NULL,
+    { PMDA_PMID(CLUSTER_SEM_STAT,1), PM_TYPE_STRING, IPC_SEM_INDOM, PM_SEM_DISCRETE, 
+    PMDA_PMUNITS(0,0,0,0,0,0) }, },
+
+/* ipc.sem.perms */
+  { NULL,
+    { PMDA_PMID(CLUSTER_SEM_STAT,2), PM_TYPE_U32, IPC_SEM_INDOM, PM_SEM_INSTANT, 
+    PMDA_PMUNITS(0,0,0,0,0,0) }, },
+
+/* ipc.sem.nsems */
+  { NULL,
+    { PMDA_PMID(CLUSTER_SEM_STAT,3), PM_TYPE_U32, IPC_SEM_INDOM, PM_SEM_INSTANT, 
+    PMDA_PMUNITS(0,0,0,0,0,0) }, },
+
+/*
  * number of users cluster
  */
 
@@ -4876,6 +4901,9 @@ linux_refresh(pmdaExt *pmda, int *need_refresh, int context)
     if (need_refresh[CLUSTER_MSG_STAT])
 	refresh_msg_que(INDOM(IPC_MSG_INDOM));
 
+    if (need_refresh[CLUSTER_SEM_STAT])
+	refresh_sem_array(INDOM(IPC_SEM_INDOM));
+
 done:
     if (need_refresh_mtab)
 	pmdaDynamicMetricTable(pmda);
@@ -4945,6 +4973,9 @@ linux_instance(pmInDom indom, int inst, char *name, __pmInResult **result, pmdaE
     case IPC_MSG_INDOM:
 	need_refresh[CLUSTER_MSG_STAT]++;
 	break;
+    case IPC_SEM_INDOM:
+	need_refresh[CLUSTER_SEM_STAT]++;
+	break;
     /* no default label : pmdaInstance will pick up errors */
     }
 
@@ -6291,7 +6322,35 @@ linux_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
 	}
 	break;
      }
-     
+
+    case CLUSTER_SEM_STAT: {
+	
+        sem_array_t *sem_arr;
+
+	sts = pmdaCacheLookup(INDOM(IPC_SEM_INDOM), inst, NULL, (void **)&sem_arr);
+	if (sts < 0)
+	    return sts;
+	if (sts != PMDA_CACHE_ACTIVE)
+	    return PM_ERR_INST;
+	switch (idp->item) {
+	case 0:	/* ipc.sem.key */
+	    atom->cp = (char *)sem_arr->sem_key;
+	    break;
+	case 1:	/* ipc.sem.owner */
+	    atom->cp = (char *)sem_arr->sem_owner;
+	    break;
+	case 2:	/* ipc.sem.perms */
+	    atom->ul = sem_arr->sem_perms;
+	    break;
+	case 3:	/* ipc.sem.nsems */
+	    atom->ul = sem_arr->nsems;
+	    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 b52778d..ef2c00e 100644
--- a/src/pmdas/linux/root_linux
+++ b/src/pmdas/linux/root_linux
@@ -215,6 +215,10 @@ ipc.sem {
     max_exit		60:21:9
     used_sem		60:61:0
     tot_sem		60:61:1
+    key 		60:66:0
+    owner 		60:66:1
+    perms 		60:66:2
+    nsems 		60:66:3
 }
 
 ipc.msg {
-- 
1.8.3.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.