X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fipc.c;h=b4038472efb76e4ff48df62e95b91307a8ff2dfc;hb=e0e307657d6b751d6beb5afb92c9359a6df7f5e8;hp=c10cdb1d687b6c1e2b2787c3e4f5c8469d216ecc;hpb=a0ba86d57e39b5146d9fc06311b91af2af065e65;p=collectd.git diff --git a/src/ipc.c b/src/ipc.c index c10cdb1d..b4038472 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -32,6 +32,9 @@ #include "configfile.h" #if KERNEL_LINUX + /* _GNU_SOURCE is needed for struct shm_info.used_ids on musl libc */ +# define _GNU_SOURCE + /* X/OPEN tells us to use for semctl() */ /* X/OPEN tells us to use for msgctl() */ /* X/OPEN tells us to use for shmctl() */ @@ -89,7 +92,10 @@ static long pagesize_g; #endif __attribute__ ((nonnull(1))) -static void ipc_submit_g (const char *type, gauge_t value) /* {{{ */ +static void ipc_submit_g (const char *plugin_instance, + const char *type, + const char *type_instance, + gauge_t value) /* {{{ */ { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; @@ -100,12 +106,88 @@ static void ipc_submit_g (const char *type, gauge_t value) /* {{{ */ vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipc", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); sstrncpy (vl.type, type, sizeof (vl.type)); + if (type_instance != NULL) + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); plugin_dispatch_values (&vl); } /* }}} */ -#if KERNEL_AIX +#if KERNEL_LINUX +static int ipc_read_sem (void) /* {{{ */ +{ + struct seminfo seminfo; + union semun arg; + int status; + + arg.array = (void *) &seminfo; + + status = semctl (/* id = */ 0, /* num = */ 0, SEM_INFO, arg); + if (status == -1) + { + char errbuf[1024]; + ERROR("ipc plugin: semctl(2) failed: %s. " + "Maybe the kernel is not configured for semaphores?", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + ipc_submit_g("sem", "count", "arrays", seminfo.semusz); + ipc_submit_g("sem", "count", "total", seminfo.semaem); + + return (0); +} /* }}} int ipc_read_sem */ + +static int ipc_read_shm (void) /* {{{ */ +{ + struct shm_info shm_info; + int status; + + status = shmctl (/* id = */ 0, SHM_INFO, (void *) &shm_info); + if (status == -1) + { + char errbuf[1024]; + ERROR("ipc plugin: shmctl(2) failed: %s. " + "Maybe the kernel is not configured for shared memory?", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + ipc_submit_g("shm", "segments", NULL, shm_info.used_ids); + ipc_submit_g("shm", "bytes", "total", shm_info.shm_tot * pagesize_g); + ipc_submit_g("shm", "bytes", "rss", shm_info.shm_rss * pagesize_g); + ipc_submit_g("shm", "bytes", "swapped", shm_info.shm_swp * pagesize_g); + return (0); +} +/* }}} int ipc_read_shm */ + +static int ipc_read_msg (void) /* {{{ */ +{ + struct msginfo msginfo; + + if ( msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo) < 0 ) + { + ERROR("Kernel is not configured for message queues"); + return (-1); + } + ipc_submit_g("msg", "count", "queues", msginfo.msgmni); + ipc_submit_g("msg", "count", "headers", msginfo.msgmap); + ipc_submit_g("msg", "count", "space", msginfo.msgtql); + + return (0); +} +/* }}} int ipc_read_msg */ + +static int ipc_init (void) /* {{{ */ +{ + pagesize_g = sysconf(_SC_PAGESIZE); + return (0); +} +/* }}} */ +/* #endif KERNEL_LINUX */ + +#elif KERNEL_AIX static caddr_t ipc_get_info (cid_t cid, int cmd, int version, int stsize, int *nmemb) /* {{{ */ { int size = 0; @@ -148,27 +230,9 @@ static caddr_t ipc_get_info (cid_t cid, int cmd, int version, int stsize, int *n return buff; } /* }}} */ -#endif /* KERNEL_AIX */ static int ipc_read_sem (void) /* {{{ */ { -#if KERNEL_LINUX - struct seminfo seminfo; - union semun arg; - - arg.array = (ushort *) (void *) &seminfo; - - if ( semctl(0, 0, SEM_INFO, arg) < 0 ) - { - ERROR("Kernel is not configured for semaphores"); - return (-1); - } - - ipc_submit_g("sem_used_arrays", seminfo.semusz); - ipc_submit_g("sem_used", seminfo.semaem); - -/* #endif KERNEL_LINUX */ -#elif KERNEL_AIX ipcinfo_sem_t *ipcinfo_sem; unsigned short sem_nsems=0; unsigned short sems=0; @@ -185,31 +249,14 @@ static int ipc_read_sem (void) /* {{{ */ } free(ipcinfo_sem); - ipc_submit_g("sem_used_arrays", sem_nsems); - ipc_submit_g("sem_used", sems); -#endif /* KERNEL_AIX */ + ipc_submit_g("sem", "count", "arrays", sem_nsems); + ipc_submit_g("sem", "count", "total", sems); return (0); -} -/* }}} */ +} /* }}} int ipc_read_sem */ static int ipc_read_shm (void) /* {{{ */ { -#if KERNEL_LINUX - struct shm_info shm_info; - pagesize_g = sysconf(_SC_PAGESIZE); - - if ( shmctl(0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info) < 0 ) - { - ERROR("Kernel is not configured for shared memory"); - return (-1); - } - ipc_submit_g("shm_segments", shm_info.used_ids); - ipc_submit_g("shm_bytes_total", shm_info.shm_tot * pagesize_g); - ipc_submit_g("shm_bytes_rss", shm_info.shm_rss * pagesize_g); - ipc_submit_g("shm_bytes_swapped", shm_info.shm_swp * pagesize_g); -/* #endif KERNEL_LINUX */ -#elif KERNEL_AIX ipcinfo_shm_t *ipcinfo_shm; ipcinfo_shm_t *pshm; unsigned int shm_segments=0; @@ -227,29 +274,15 @@ static int ipc_read_shm (void) /* {{{ */ } free(ipcinfo_shm); - ipc_submit_g("shm_segments", shm_segments); - ipc_submit_g("shm_bytes_total", shm_bytes); + ipc_submit_g("shm", "segments", NULL, shm_segments); + ipc_submit_g("shm", "bytes", "total", shm_bytes); -#endif /* KERNEL_AIX */ return (0); } -/* }}} */ +/* }}} int ipc_read_shm */ static int ipc_read_msg (void) /* {{{ */ { -#if KERNEL_LINUX - struct msginfo msginfo; - - if ( msgctl(0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo) < 0 ) - { - ERROR("Kernel is not configured for message queues"); - return (-1); - } - ipc_submit_g("msg_alloc_queues", msginfo.msgmni); - ipc_submit_g("msg_used_headers", msginfo.msgmap); - ipc_submit_g("msg_used_space", msginfo.msgtql); -/* #endif KERNEL_LINUX */ -#elif KERNEL_AIX ipcinfo_msg_t *ipcinfo_msg; uint32_t msg_used_space=0; uint32_t msg_alloc_queues=0; @@ -265,16 +298,17 @@ static int ipc_read_msg (void) /* {{{ */ msg_alloc_queues++; msg_used_space += ipcinfo_msg[i].msg_cbytes; msg_qnum += ipcinfo_msg[i].msg_qnum; - } + free(ipcinfo_msg); - ipc_submit_g("msg_alloc_queues", msg_alloc_queues); - ipc_submit_g("msg_used_headers", msg_qnum); - ipc_submit_g("msg_used_space", msg_used_space); -#endif /* KERNEL_AIX */ + ipc_submit_g("msg", "count", "queues", msg_alloc_queues); + ipc_submit_g("msg", "count", "headers", msg_qnum); + ipc_submit_g("msg", "count", "space", msg_used_space); + return (0); } /* }}} */ +#endif /* KERNEL_AIX */ static int ipc_read (void) /* {{{ */ { @@ -287,15 +321,6 @@ static int ipc_read (void) /* {{{ */ } /* }}} */ -#ifdef KERNEL_LINUX -static int ipc_init (void) /* {{{ */ -{ - pagesize_g = sysconf(_SC_PAGESIZE); - return (0); -} -/* }}} */ -#endif /* KERNEL_LINUX */ - void module_register (void) /* {{{ */ { #ifdef KERNEL_LINUX