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>
This commit is contained in:
Angus Salkeld 2011-03-29 09:41:04 +11:00
parent 4991ccd3d8
commit 076e8b74f7
3 changed files with 72 additions and 7 deletions

View File

@ -1546,15 +1546,27 @@ static void coroipcs_init_conn_stats (
{
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, 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);
api->stats_update_value (conn->stats_handle, "service_id",
&conn->service, sizeof(conn->service));

View File

@ -44,6 +44,7 @@
#include <assert.h>
#include <corosync/corotypes.h>
#include <corosync/corodefs.h>
#include <corosync/list.h>
#include <corosync/engine/logsys.h>
#include <corosync/coroipc_types.h>
@ -51,6 +52,52 @@
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.
*/

View File

@ -97,4 +97,10 @@ void _corosync_out_of_memory_error (void) __attribute__((noreturn));
extern char *getcs_name_t (cs_name_t *name);
extern void setcs_name_t (cs_name_t *name, char *str);
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 */