projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-5.0'
[collectd.git]
/
src
/
pinba.c
diff --git
a/src/pinba.c
b/src/pinba.c
index
94e1092
..
26aa539
100644
(file)
--- a/
src/pinba.c
+++ b/
src/pinba.c
@@
-43,11
+43,11
@@
#endif
#ifndef PINBA_DEFAULT_NODE
#endif
#ifndef PINBA_DEFAULT_NODE
-# define PINBA_DEFAULT_NODE "
127.0.0.1" /* FIXME */
+# define PINBA_DEFAULT_NODE "
::0"
#endif
#ifndef PINBA_DEFAULT_SERVICE
#endif
#ifndef PINBA_DEFAULT_SERVICE
-# define PINBA_DEFAULT_SERVICE "
12345" /* FIXME */
+# define PINBA_DEFAULT_SERVICE "
30002"
#endif
#ifndef PINBA_MAX_SOCKETS
#endif
#ifndef PINBA_MAX_SOCKETS
@@
-57,26
+57,14
@@
/*
* Private data structures
*/
/*
* Private data structures
*/
-typedef struct _pinba_statres_ pinba_statres_t;
-struct _pinba_statres_ {
- const char *name;
- double req_per_sec;
- double req_time;
- double ru_utime;
- double ru_stime;
- double doc_size;
- double mem_peak;
-};
-
-struct pinba_socket_s {
+/* {{{ */
+struct pinba_socket_s
+{
struct pollfd fd[PINBA_MAX_SOCKETS];
nfds_t fd_num;
};
typedef struct pinba_socket_s pinba_socket_t;
struct pollfd fd[PINBA_MAX_SOCKETS];
nfds_t fd_num;
};
typedef struct pinba_socket_s pinba_socket_t;
-typedef double pinba_time_t;
-typedef uint32_t pinba_size_t;
-
/* Fixed point counter value. n is the decimal part multiplied by 10^9. */
struct float_counter_s
{
/* Fixed point counter value. n is the decimal part multiplied by 10^9. */
struct float_counter_s
{
@@
-87,7
+75,7
@@
typedef struct float_counter_s float_counter_t;
struct pinba_statnode_s
{
struct pinba_statnode_s
{
- /* collector name */
+ /* collector name
, used as plugin instance
*/
char *name;
/* query data */
char *name;
/* query data */
@@
-105,10
+93,12
@@
struct pinba_statnode_s
gauge_t mem_peak;
};
typedef struct pinba_statnode_s pinba_statnode_t;
gauge_t mem_peak;
};
typedef struct pinba_statnode_s pinba_statnode_t;
+/* }}} */
/*
* Module global variables
*/
/*
* Module global variables
*/
+/* {{{ */
static pinba_statnode_t *stat_nodes = NULL;
static unsigned int stat_nodes_num = 0;
static pthread_mutex_t stat_nodes_lock;
static pinba_statnode_t *stat_nodes = NULL;
static unsigned int stat_nodes_num = 0;
static pthread_mutex_t stat_nodes_lock;
@@
-119,6
+109,7
@@
static char *conf_service = NULL;
static _Bool collector_thread_running = 0;
static _Bool collector_thread_do_shutdown = 0;
static pthread_t collector_thread_id;
static _Bool collector_thread_running = 0;
static _Bool collector_thread_do_shutdown = 0;
static pthread_t collector_thread_id;
+/* }}} */
/*
* Functions
/*
* Functions
@@
-144,12
+135,15
@@
static void float_counter_add (float_counter_t *fc, float val) /* {{{ */
}
} /* }}} void float_counter_add */
}
} /* }}} void float_counter_add */
-static derive_t float_counter_get (const float_counter_t *fc) /* {{{ */
+static derive_t float_counter_get (const float_counter_t *fc, /* {{{ */
+ uint64_t factor)
{
{
- if (fc->n >= 500000000)
- return ((derive_t) (fc->i + 1));
- else
- return ((derive_t) fc->i);
+ derive_t ret;
+
+ ret = (derive_t) (fc->i * factor);
+ ret += (derive_t) (fc->n / (1000000000 / factor));
+
+ return (ret);
} /* }}} derive_t float_counter_get */
static void strset (char **str, const char *new) /* {{{ */
} /* }}} derive_t float_counter_get */
static void strset (char **str, const char *new) /* {{{ */
@@
-195,10
+189,10
@@
static void service_statnode_add(const char *name, /* {{{ */
node->mem_peak = NAN;
/* fill query data */
node->mem_peak = NAN;
/* fill query data */
- strset(&node->name, name);
- strset(&node->host, host);
- strset(&node->server, server);
- strset(&node->script, script);
+ strset
(&node->name, name);
+ strset
(&node->host, host);
+ strset
(&node->server, server);
+ strset
(&node->script, script);
/* increment counter */
stat_nodes_num++;
/* increment counter */
stat_nodes_num++;
@@
-260,11
+254,16
@@
static void service_process_request (Pinba__Request *request) /* {{{ */
for (i = 0; i < stat_nodes_num; i++)
{
for (i = 0; i < stat_nodes_num; i++)
{
- if(stat_nodes[i].host && strcmp(request->hostname, stat_nodes[i].host))
+ if ((stat_nodes[i].host != NULL)
+ && (strcmp (request->hostname, stat_nodes[i].host) != 0))
continue;
continue;
- if(stat_nodes[i].server && strcmp(request->server_name, stat_nodes[i].server))
+
+ if ((stat_nodes[i].server != NULL)
+ && (strcmp (request->server_name, stat_nodes[i].server) != 0))
continue;
continue;
- if(stat_nodes[i].script && strcmp(request->script_name, stat_nodes[i].script))
+
+ if ((stat_nodes[i].script != NULL)
+ && (strcmp (request->script_name, stat_nodes[i].script) != 0))
continue;
service_statnode_process(&stat_nodes[i], request);
continue;
service_statnode_process(&stat_nodes[i], request);
@@
-378,7
+377,7
@@
static pinba_socket_t *pinba_socket_open (const char *node, /* {{{ */
assert (ai_list != NULL);
s = malloc (sizeof (*s));
assert (ai_list != NULL);
s = malloc (sizeof (*s));
- if (s
!
= NULL)
+ if (s
=
= NULL)
{
freeaddrinfo (ai_list);
ERROR ("pinba plugin: malloc failed.");
{
freeaddrinfo (ai_list);
ERROR ("pinba plugin: malloc failed.");
@@
-618,7
+617,7
@@
static int plugin_config (oconfig_item_t *ci) /* {{{ */
if (strcasecmp ("Address", child->key) == 0)
cf_util_get_string (child, &conf_node);
else if (strcasecmp ("Port", child->key) == 0)
if (strcasecmp ("Address", child->key) == 0)
cf_util_get_string (child, &conf_node);
else if (strcasecmp ("Port", child->key) == 0)
- cf_util_get_s
tring
(child, &conf_service);
+ cf_util_get_s
ervice
(child, &conf_service);
else if (strcasecmp ("View", child->key) == 0)
pinba_config_view (child);
else
else if (strcasecmp ("View", child->key) == 0)
pinba_config_view (child);
else
@@
-628,7
+627,7
@@
static int plugin_config (oconfig_item_t *ci) /* {{{ */
pthread_mutex_unlock(&stat_nodes_lock);
return (0);
pthread_mutex_unlock(&stat_nodes_lock);
return (0);
-} /* int pinba_config */
+} /*
}}}
int pinba_config */
static int plugin_init (void) /* {{{ */
{
static int plugin_init (void) /* {{{ */
{
@@
-698,19
+697,23
@@
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, "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);
+ sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type));
plugin_dispatch_values (&vl);
plugin_dispatch_values (&vl);
- value.derive =
float_counter_get (&res->req_time)
;
- sstrncpy (vl.type, "total_
time
", sizeof (vl.type));
+ value.derive =
res->doc_size
;
+ sstrncpy (vl.type, "total_
bytes
", sizeof (vl.type));
plugin_dispatch_values (&vl);
plugin_dispatch_values (&vl);
- value.derive = float_counter_get (&res->ru_utime);
+ value.derive = float_counter_get (&res->ru_utime
, /* factor = */ 100
);
sstrncpy (vl.type, "cpu", sizeof (vl.type));
sstrncpy (vl.type_instance, "user", sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
sstrncpy (vl.type, "cpu", sizeof (vl.type));
sstrncpy (vl.type_instance, "user", sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
- value.derive = float_counter_get (&res->ru_stime);
+ value.derive = float_counter_get (&res->ru_stime
, /* factor = */ 100
);
sstrncpy (vl.type, "cpu", sizeof (vl.type));
sstrncpy (vl.type_instance, "system", sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
sstrncpy (vl.type, "cpu", sizeof (vl.type));
sstrncpy (vl.type_instance, "system", sizeof (vl.type_instance));
plugin_dispatch_values (&vl);