[Openais] [PATCH 3/3] STATS: add the service name to the connection name.

Angus Salkeld asalkeld at redhat.com
Mon Mar 28 02:26:31 PDT 2011


This helps to quickly identify what service the application
is connected to.

The object will now look like:
runtime.connections.corosync-objctl:CONFDB:19654:13.service_id=11
runtime.connections.corosync-objctl:CONFDB:19654:13.client_pid=19654
etc...

This also makes it clearer to receivers of the dbus/snmp events
what is going on.

Signed-off-by: Angus Salkeld <asalkeld at redhat.com>
---
 exec/coroipcs.c |  106 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/exec/coroipcs.c b/exec/coroipcs.c
index b64c5a9..bfb638b 100644
--- a/exec/coroipcs.c
+++ b/exec/coroipcs.c
@@ -70,6 +70,7 @@
 #include <sys/shm.h>
 
 #include <corosync/corotypes.h>
+#include <corosync/corodefs.h>
 #include <corosync/list.h>
 
 #include <corosync/coroipc_types.h>
@@ -1541,20 +1542,111 @@ static char * pid_to_name (pid_t pid, char *out_name, size_t name_len)
 	return out_name;
 }
 
+static const char * short_service_name_get(uint32_t service_id, char *buf)
+{
+	const char * name;
+	switch (service_id) {
+	case EVS_SERVICE:
+		name = "EVS";
+		break;
+	case CLM_SERVICE:
+		name = "CLM";
+		break;
+	case AMF_SERVICE:
+		name = "AMF";
+		break;
+	case CKPT_SERVICE:
+		name = "CKPT";
+		break;
+	case EVT_SERVICE:
+		name = "EVT";
+		break;
+	case LCK_SERVICE:
+		name = "LCK";
+		break;
+	case MSG_SERVICE:
+		name = "MSG";
+		break;
+	case CFG_SERVICE:
+		name = "CFG";
+		break;
+	case CPG_SERVICE:
+		name = "CPG";
+		break;
+	case CMAN_SERVICE:
+		name = "CMAN";
+		break;
+	case PCMK_SERVICE:
+		name = "PCMK";
+		break;
+	case CONFDB_SERVICE:
+		name = "CONFDB";
+		break;
+	case QUORUM_SERVICE:
+		name = "QUORUM";
+		break;
+	case PLOAD_SERVICE:
+		name = "PLOAD";
+		break;
+	case TMR_SERVICE:
+		name = "TMR";
+		break;
+	case VOTEQUORUM_SERVICE:
+		name = "VOTEQUORUM";
+		break;
+	case NTF_SERVICE:
+		name = "NTF";
+		break;
+	case AMF_V2_SERVICE:
+		name = "AMF";
+		break;
+	case TST_SV1_SERVICE:
+		name = "TST";
+		break;
+	case TST_SV2_SERVICE:
+		name = "TST";
+		break;
+	case MON_SERVICE:
+		name = "MON";
+		break;
+	case WD_SERVICE:
+		name = "WD";
+		break;
+	default:
+		sprintf(buf, "%d", service_id);
+		name = buf;
+		break;
+	}
+	return name;
+}
+
+
 static void coroipcs_init_conn_stats (
 	struct conn_info *conn)
 {
 	char conn_name[CS_MAX_NAME_LENGTH];
 	char proc_name[CS_MAX_NAME_LENGTH];
+	char int_str[4];
 
 	if (conn->client_pid > 0) {
-		if (pid_to_name (conn->client_pid, proc_name, sizeof(proc_name)))
-			snprintf (conn_name, sizeof(conn_name), "%s:%d:%d", proc_name, conn->client_pid, conn->fd);
-		else
-			snprintf (conn_name, sizeof(conn_name), "%d:%d", conn->client_pid, conn->fd);
-	} else
-		snprintf (conn_name, sizeof(conn_name), "%d", conn->fd);
-
+		if (pid_to_name (conn->client_pid, proc_name, sizeof(proc_name))) {
+			snprintf (conn_name, sizeof(conn_name),
+				"%s:%s:%d:%d", proc_name,
+				short_service_name_get(conn->service, int_str),
+				conn->client_pid, conn->fd);
+		} else {
+			snprintf (conn_name, sizeof(conn_name),
+				"proc:%s:%d:%d",
+				short_service_name_get(conn->service, int_str),
+				conn->client_pid,
+				conn->fd);
+		}
+	} else {
+		snprintf (conn_name, sizeof(conn_name),
+			"proc:%s:pid:%d",
+			short_service_name_get(conn->service, int_str),
+			conn->fd);
+	}
 	conn->stats_handle = api->stats_create_connection (conn_name, conn->client_pid, conn->fd);
 	api->stats_update_value (conn->stats_handle, "service_id",
 		&conn->service, sizeof(conn->service));
-- 
1.7.4



More information about the Openais mailing list