projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
write_tsdb: enable TCP keepalive on network socket
[collectd.git]
/
src
/
pinba.c
diff --git
a/src/pinba.c
b/src/pinba.c
index
d13d047
..
b9eed68
100644
(file)
--- a/
src/pinba.c
+++ b/
src/pinba.c
@@
-24,11
+24,11
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "common.h"
#include "plugin.h"
#include "configfile.h"
-#include <pthread.h>
#include <netdb.h>
#include <poll.h>
#include <netdb.h>
#include <poll.h>
@@
-171,7
+171,7
@@
static void service_statnode_add(const char *name, /* {{{ */
const char *script)
{
pinba_statnode_t *node;
const char *script)
{
pinba_statnode_t *node;
-
+
node = realloc (stat_nodes,
sizeof (*stat_nodes) * (stat_nodes_num + 1));
if (node == NULL)
node = realloc (stat_nodes,
sizeof (*stat_nodes) * (stat_nodes_num + 1));
if (node == NULL)
@@
-183,7
+183,7
@@
static void service_statnode_add(const char *name, /* {{{ */
node = stat_nodes + stat_nodes_num;
memset (node, 0, sizeof (*node));
node = stat_nodes + stat_nodes_num;
memset (node, 0, sizeof (*node));
-
+
/* reset strings */
node->name = NULL;
node->host = NULL;
/* reset strings */
node->name = NULL;
node->host = NULL;
@@
-191,13
+191,13
@@
static void service_statnode_add(const char *name, /* {{{ */
node->script = NULL;
node->mem_peak = NAN;
node->script = NULL;
node->mem_peak = NAN;
-
+
/* fill query data */
strset (&node->name, name);
strset (&node->host, host);
strset (&node->server, server);
strset (&node->script, script);
/* fill query data */
strset (&node->name, name);
strset (&node->host, host);
strset (&node->server, server);
strset (&node->script, script);
-
+
/* increment counter */
stat_nodes_num++;
} /* }}} void service_statnode_add */
/* increment counter */
stat_nodes_num++;
} /* }}} void service_statnode_add */
@@
-209,14
+209,14
@@
static unsigned int service_statnode_collect (pinba_statnode_t *res, /* {{{ */
unsigned int index)
{
pinba_statnode_t *node;
unsigned int index)
{
pinba_statnode_t *node;
-
+
if (stat_nodes_num == 0)
return 0;
if (stat_nodes_num == 0)
return 0;
-
+
/* begin collecting */
if (index == 0)
pthread_mutex_lock (&stat_nodes_lock);
/* begin collecting */
if (index == 0)
pthread_mutex_lock (&stat_nodes_lock);
-
+
/* end collecting */
if (index >= stat_nodes_num)
{
/* end collecting */
if (index >= stat_nodes_num)
{
@@
-229,7
+229,7
@@
static unsigned int service_statnode_collect (pinba_statnode_t *res, /* {{{ */
/* reset node */
node->mem_peak = NAN;
/* reset node */
node->mem_peak = NAN;
-
+
return (index + 1);
} /* }}} unsigned int service_statnode_collect */
return (index + 1);
} /* }}} unsigned int service_statnode_collect */
@@
-252,11
+252,9
@@
static void service_statnode_process (pinba_statnode_t *node, /* {{{ */
static void service_process_request (Pinba__Request *request) /* {{{ */
{
static void service_process_request (Pinba__Request *request) /* {{{ */
{
- unsigned int i;
-
pthread_mutex_lock (&stat_nodes_lock);
pthread_mutex_lock (&stat_nodes_lock);
-
- for (i = 0; i < stat_nodes_num; i++)
+
+ for (
unsigned int
i = 0; i < stat_nodes_num; i++)
{
if ((stat_nodes[i].host != NULL)
&& (strcmp (request->hostname, stat_nodes[i].host) != 0))
{
if ((stat_nodes[i].host != NULL)
&& (strcmp (request->hostname, stat_nodes[i].host) != 0))
@@
-272,7
+270,7
@@
static void service_process_request (Pinba__Request *request) /* {{{ */
service_statnode_process(&stat_nodes[i], request);
}
service_statnode_process(&stat_nodes[i], request);
}
-
+
pthread_mutex_unlock(&stat_nodes_lock);
} /* }}} void service_process_request */
pthread_mutex_unlock(&stat_nodes_lock);
} /* }}} void service_process_request */
@@
-352,25
+350,20
@@
static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
{
pinba_socket_t *s;
struct addrinfo *ai_list;
{
pinba_socket_t *s;
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
- struct addrinfo ai_hints;
int status;
int status;
- memset (&ai_hints, 0, sizeof (ai_hints));
- ai_hints.ai_flags = AI_PASSIVE;
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_addr = NULL;
- ai_hints.ai_canonname = NULL;
- ai_hints.ai_next = NULL;
-
if (node == NULL)
node = PINBA_DEFAULT_NODE;
if (service == NULL)
service = PINBA_DEFAULT_SERVICE;
if (node == NULL)
node = PINBA_DEFAULT_NODE;
if (service == NULL)
service = PINBA_DEFAULT_SERVICE;
- ai_list = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_PASSIVE,
+ .ai_socktype = SOCK_DGRAM
+ };
+
status = getaddrinfo (node, service,
&ai_hints, &ai_list);
if (status != 0)
status = getaddrinfo (node, service,
&ai_hints, &ai_list);
if (status != 0)
@@
-381,22
+374,21
@@
static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
}
assert (ai_list != NULL);
}
assert (ai_list != NULL);
- s =
malloc (
sizeof (*s));
+ s =
calloc (1,
sizeof (*s));
if (s == NULL)
{
freeaddrinfo (ai_list);
if (s == NULL)
{
freeaddrinfo (ai_list);
- ERROR ("pinba plugin:
m
alloc failed.");
+ ERROR ("pinba plugin:
c
alloc failed.");
return (NULL);
}
return (NULL);
}
- memset (s, 0, sizeof (*s));
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (
struct addrinfo *
ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
status = pb_add_socket (s, ai_ptr);
if (status != 0)
break;
} /* for (ai_list) */
{
status = pb_add_socket (s, ai_ptr);
if (status != 0)
break;
} /* for (ai_list) */
-
+
freeaddrinfo (ai_list);
if (s->fd_num < 1)
freeaddrinfo (ai_list);
if (s->fd_num < 1)
@@
-411,35
+403,33
@@
static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
static void pinba_socket_free (pinba_socket_t *socket) /* {{{ */
{
static void pinba_socket_free (pinba_socket_t *socket) /* {{{ */
{
- nfds_t i;
-
if (!socket)
return;
if (!socket)
return;
-
- for (i = 0; i < socket->fd_num; i++)
+
+ for (
nfds_t
i = 0; i < socket->fd_num; i++)
{
if (socket->fd[i].fd < 0)
continue;
close (socket->fd[i].fd);
socket->fd[i].fd = -1;
}
{
if (socket->fd[i].fd < 0)
continue;
close (socket->fd[i].fd);
socket->fd[i].fd = -1;
}
-
+
sfree(socket);
} /* }}} void pinba_socket_free */
static int pinba_process_stats_packet (const uint8_t *buffer, /* {{{ */
size_t buffer_size)
{
sfree(socket);
} /* }}} void pinba_socket_free */
static int pinba_process_stats_packet (const uint8_t *buffer, /* {{{ */
size_t buffer_size)
{
- Pinba__Request *request;
-
+ Pinba__Request *request;
+
request = pinba__request__unpack (NULL, buffer_size, buffer);
request = pinba__request__unpack (NULL, buffer_size, buffer);
-
+
if (!request)
return (-1);
service_process_request(request);
pinba__request__free_unpacked (request, NULL);
if (!request)
return (-1);
service_process_request(request);
pinba__request__free_unpacked (request, NULL);
-
+
return (0);
} /* }}} int pinba_process_stats_packet */
return (0);
} /* }}} int pinba_process_stats_packet */
@@
-507,7
+497,6
@@
static int receive_loop (void) /* {{{ */
while (!collector_thread_do_shutdown)
{
int status;
while (!collector_thread_do_shutdown)
{
int status;
- nfds_t i;
if (s->fd_num < 1)
break;
if (s->fd_num < 1)
break;
@@
-530,7
+519,7
@@
static int receive_loop (void) /* {{{ */
return (-1);
}
return (-1);
}
- for (i = 0; i < s->fd_num; i++)
+ for (
nfds_t
i = 0; i < s->fd_num; i++)
{
if (s->fd[i].revents & (POLLERR | POLLHUP | POLLNVAL))
{
{
if (s->fd[i].revents & (POLLERR | POLLHUP | POLLNVAL))
{
@@
-570,13
+559,12
@@
static int pinba_config_view (const oconfig_item_t *ci) /* {{{ */
char *server = NULL;
char *script = NULL;
int status;
char *server = NULL;
char *script = NULL;
int status;
- int i;
status = cf_util_get_string (ci, &name);
if (status != 0)
return (status);
status = cf_util_get_string (ci, &name);
if (status != 0)
return (status);
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
oconfig_item_t *child = ci->children + i;
@@
-609,13
+597,11
@@
static int pinba_config_view (const oconfig_item_t *ci) /* {{{ */
static int plugin_config (oconfig_item_t *ci) /* {{{ */
{
static int plugin_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
/* The lock should not be necessary in the config callback, but let's be
* sure.. */
pthread_mutex_lock (&stat_nodes_lock);
/* The lock should not be necessary in the config callback, but let's be
* sure.. */
pthread_mutex_lock (&stat_nodes_lock);
- for (i = 0; i < ci->children_num; i++)
+ for (i
nt i
= 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
oconfig_item_t *child = ci->children + i;
@@
-630,7
+616,7
@@
static int plugin_config (oconfig_item_t *ci) /* {{{ */
}
pthread_mutex_unlock(&stat_nodes_lock);
}
pthread_mutex_unlock(&stat_nodes_lock);
-
+
return (0);
} /* }}} int pinba_config */
return (0);
} /* }}} int pinba_config */
@@
-694,7
+680,7
@@
static int plugin_submit (const pinba_statnode_t *res) /* {{{ */
{
value_t value;
value_list_t vl = VALUE_LIST_INIT;
{
value_t value;
value_list_t vl = VALUE_LIST_INIT;
-
+
vl.values = &value;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
vl.values = &value;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
@@
-702,15
+688,15
@@
static int plugin_submit (const pinba_statnode_t *res) /* {{{ */
sstrncpy (vl.plugin_instance, res->name, sizeof (vl.plugin_instance));
value.derive = res->req_count;
sstrncpy (vl.plugin_instance, res->name, sizeof (vl.plugin_instance));
value.derive = res->req_count;
- sstrncpy (vl.type, "total_requests", sizeof (vl.type));
+ sstrncpy (vl.type, "total_requests", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->req_time, /* factor = */ 1000);
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->req_time, /* factor = */ 1000);
- sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type));
+ sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = res->doc_size;
plugin_dispatch_values (&vl);
value.derive = res->doc_size;
- sstrncpy (vl.type, "total_bytes", sizeof (vl.type));
+ sstrncpy (vl.type, "total_bytes", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->ru_utime, /* factor = */ 100);
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->ru_utime, /* factor = */ 100);
@@
-735,12
+721,12
@@
static int plugin_read (void) /* {{{ */
{
unsigned int i=0;
pinba_statnode_t data;
{
unsigned int i=0;
pinba_statnode_t data;
-
+
while ((i = service_statnode_collect (&data, i)) != 0)
{
plugin_submit (&data);
}
while ((i = service_statnode_collect (&data, i)) != 0)
{
plugin_submit (&data);
}
-
+
return 0;
} /* }}} int plugin_read */
return 0;
} /* }}} int plugin_read */