Просмотр исходного кода

STATS: add the service name to the connection name.

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@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Angus Salkeld 15 лет назад
Родитель
Сommit
78ae800f80
3 измененных файлов с 72 добавлено и 7 удалено
  1. 19 7
      exec/coroipcs.c
  2. 47 0
      exec/util.c
  3. 6 0
      exec/util.h

+ 19 - 7
exec/coroipcs.c

@@ -1547,15 +1547,27 @@ static void coroipcs_init_conn_stats (
 {
 {
 	char conn_name[CS_MAX_NAME_LENGTH];
 	char conn_name[CS_MAX_NAME_LENGTH];
 	char proc_name[CS_MAX_NAME_LENGTH];
 	char proc_name[CS_MAX_NAME_LENGTH];
+	char int_str[4];
 
 
 	if (conn->client_pid > 0) {
 	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, 4),
+				conn->client_pid, conn->fd);
+		} else {
+			snprintf (conn_name, sizeof(conn_name),
+				"proc:%s:%d:%d",
+				short_service_name_get(conn->service, int_str, 4),
+				conn->client_pid,
+				conn->fd);
+		}
+	} else {
+		snprintf (conn_name, sizeof(conn_name),
+			"proc:%s:pid:%d",
+			short_service_name_get(conn->service, int_str, 4),
+			conn->fd);
+	}
 	conn->stats_handle = api->stats_create_connection (conn_name, conn->client_pid, 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",
 	api->stats_update_value (conn->stats_handle, "service_id",
 		&conn->service, sizeof(conn->service));
 		&conn->service, sizeof(conn->service));

+ 47 - 0
exec/util.c

@@ -44,6 +44,7 @@
 #include <assert.h>
 #include <assert.h>
 
 
 #include <corosync/corotypes.h>
 #include <corosync/corotypes.h>
+#include <corosync/corodefs.h>
 #include <corosync/list.h>
 #include <corosync/list.h>
 #include <corosync/engine/logsys.h>
 #include <corosync/engine/logsys.h>
 #include <corosync/coroipc_types.h>
 #include <corosync/coroipc_types.h>
@@ -51,6 +52,52 @@
 
 
 LOGSYS_DECLARE_SUBSYS ("MAIN");
 LOGSYS_DECLARE_SUBSYS ("MAIN");
 
 
+struct service_names {
+	const char *c_name;
+	int32_t c_val;
+};
+
+static struct service_names servicenames[] =
+{
+	{ "EVS", EVS_SERVICE },
+	{ "CLM", CLM_SERVICE },
+	{ "AMF", AMF_SERVICE },
+	{ "CKPT", CKPT_SERVICE },
+	{ "EVT", EVT_SERVICE },
+	{ "LCK", LCK_SERVICE },
+	{ "MSG", MSG_SERVICE },
+	{ "CFG", CFG_SERVICE },
+	{ "CPG", CPG_SERVICE },
+	{ "CMAN", CMAN_SERVICE },
+	{ "PCMK", PCMK_SERVICE },
+	{ "CONFDB", CONFDB_SERVICE },
+	{ "QUORUM", QUORUM_SERVICE },
+	{ "PLOAD", PLOAD_SERVICE },
+	{ "TMR", TMR_SERVICE },
+	{ "VOTEQUORUM", VOTEQUORUM_SERVICE },
+	{ "NTF", NTF_SERVICE },
+	{ "AMF", AMF_V2_SERVICE },
+	{ "TST", TST_SV1_SERVICE },
+	{ "TST", TST_SV2_SERVICE },
+	{ "MON", MON_SERVICE },
+	{ "WD", WD_SERVICE },
+	{ NULL, -1 }
+};
+
+const char * short_service_name_get(uint32_t service_id,
+	char *buf, size_t buf_size)
+{
+	uint32_t i;
+
+	for (i = 0; servicenames[i].c_name != NULL; i++) {
+		if (service_id == servicenames[i].c_val) {
+			return (servicenames[i].c_name);
+		}
+	}
+	snprintf(buf, buf_size, "%d", service_id);
+	return buf;
+}
+
 /*
 /*
  * Compare two names.  returns non-zero on match.
  * Compare two names.  returns non-zero on match.
  */
  */

+ 6 - 0
exec/util.h

@@ -97,4 +97,10 @@ void _corosync_out_of_memory_error (void) __attribute__((noreturn));
 extern char *getcs_name_t (cs_name_t *name);
 extern char *getcs_name_t (cs_name_t *name);
 extern void setcs_name_t (cs_name_t *name, char *str);
 extern void setcs_name_t (cs_name_t *name, char *str);
 extern int cs_name_tisEqual (cs_name_t *str1, char *str2);
 extern int cs_name_tisEqual (cs_name_t *str1, char *str2);
+/**
+ * Get the short name of a service from the service_id.
+ */
+const char * short_service_name_get(uint32_t service_id,
+				    char *buf, size_t buf_size);
+
 #endif /* UTIL_H_DEFINED */
 #endif /* UTIL_H_DEFINED */