projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Initial support of GPSd in collectd.
[collectd.git]
/
src
/
ceph.c
diff --git
a/src/ceph.c
b/src/ceph.c
index
4f68e5b
..
d928a7b
100644
(file)
--- a/
src/ceph.c
+++ b/
src/ceph.c
@@
-21,6
+21,7
@@
* Dan Ryder <daryder@cisco.com>
**/
* Dan Ryder <daryder@cisco.com>
**/
+#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#include "collectd.h"
#define _BSD_SOURCE
#include "collectd.h"
@@
-114,7
+115,7
@@
struct ceph_daemon
uint32_t *ds_types;
/** Track ds names to match with types */
char **ds_names;
uint32_t *ds_types;
/** Track ds names to match with types */
char **ds_names;
-
+
/**
* Keep track of last data for latency values so we can calculate rate
* since last poll.
/**
* Keep track of last data for latency values so we can calculate rate
* since last poll.
@@
-255,7
+256,7
@@
static int ceph_cb_boolean(void *ctx, int bool_val)
return CEPH_CB_CONTINUE;
}
return CEPH_CB_CONTINUE;
}
-static int
+static int
ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len)
{
yajl_struct *yajl = (yajl_struct*)ctx;
ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len)
{
yajl_struct *yajl = (yajl_struct*)ctx;
@@
-320,7
+321,7
@@
ceph_cb_number(void *ctx, const char *number_val, yajl_len_t number_len)
return CEPH_CB_CONTINUE;
}
return CEPH_CB_CONTINUE;
}
-static int ceph_cb_string(void *ctx, const unsigned char *string_val,
+static int ceph_cb_string(void *ctx, const unsigned char *string_val,
yajl_len_t string_len)
{
return CEPH_CB_CONTINUE;
yajl_len_t string_len)
{
return CEPH_CB_CONTINUE;
@@
-528,7
+529,7
@@
static int parse_keys(const char *key_str, char *ds_name)
int max_str_len = 100;
char tmp_ds_name[max_str_len];
memset(tmp_ds_name, 0, sizeof(tmp_ds_name));
int max_str_len = 100;
char tmp_ds_name[max_str_len];
memset(tmp_ds_name, 0, sizeof(tmp_ds_name));
- if(ds_name == NULL || key_str == NULL || key_str[0] == '\0' ||
+ if(ds_name == NULL || key_str == NULL || key_str[0] == '\0' ||
ds_name[0] != '\0')
{
return -1;
ds_name[0] != '\0')
{
return -1;
@@
-539,7
+540,7
@@
static int parse_keys(const char *key_str, char *ds_name)
memcpy(tmp_ds_name, key_str, max_str_len - 1);
goto compact;
}
memcpy(tmp_ds_name, key_str, max_str_len - 1);
goto compact;
}
-
+
ds_name_len = (rptr - ptr) > max_str_len ? max_str_len : (rptr - ptr);
if((ds_name_len == 0) || strncmp(rptr + 1, "type", 4))
{ /** copy whole key **/
ds_name_len = (rptr - ptr) > max_str_len ? max_str_len : (rptr - ptr);
if((ds_name_len == 0) || strncmp(rptr + 1, "type", 4))
{ /** copy whole key **/
@@
-550,7
+551,7
@@
static int parse_keys(const char *key_str, char *ds_name)
memcpy(tmp_ds_name, key_str, ((rptr - key_str) > (max_str_len - 1) ?
(max_str_len - 1) : (rptr - key_str)));
}
memcpy(tmp_ds_name, key_str, ((rptr - key_str) > (max_str_len - 1) ?
(max_str_len - 1) : (rptr - key_str)));
}
-
+
compact: compact_ds_name(tmp_ds_name, ds_name);
return 0;
}
compact: compact_ds_name(tmp_ds_name, ds_name);
return 0;
}
@@
-565,7
+566,7
@@
static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name,
uint32_t type;
char ds_name[DATA_MAX_NAME_LEN];
memset(ds_name, 0, sizeof(ds_name));
uint32_t type;
char ds_name[DATA_MAX_NAME_LEN];
memset(ds_name, 0, sizeof(ds_name));
-
+
if(convert_special_metrics)
{
/**
if(convert_special_metrics)
{
/**
@@
-611,7
+612,7
@@
static int ceph_daemon_add_ds_entry(struct ceph_daemon *d, const char *name,
sstrncpy(d->ds_names[d->ds_num], ds_name, DATA_MAX_NAME_LEN -1);
d->ds_num = (d->ds_num + 1);
sstrncpy(d->ds_names[d->ds_num], ds_name, DATA_MAX_NAME_LEN -1);
d->ds_num = (d->ds_num + 1);
-
+
return 0;
}
return 0;
}
@@
-656,7
+657,8
@@
static int cc_handle_bool(struct oconfig_item_s *item, int *dest)
static int cc_add_daemon_config(oconfig_item_t *ci)
{
int ret, i;
static int cc_add_daemon_config(oconfig_item_t *ci)
{
int ret, i;
- struct ceph_daemon *array, *nd, cd;
+ struct ceph_daemon *nd, cd;
+ struct ceph_daemon **tmp;
memset(&cd, 0, sizeof(struct ceph_daemon));
if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
memset(&cd, 0, sizeof(struct ceph_daemon));
if((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
@@
-707,22
+709,22
@@
static int cc_add_daemon_config(oconfig_item_t *ci)
"with '/' or './' Can't parse: '%s'\n", cd.name, cd.asok_path);
return -EINVAL;
}
"with '/' or './' Can't parse: '%s'\n", cd.name, cd.asok_path);
return -EINVAL;
}
-
- array = realloc(g_daemons,
- sizeof(struct ceph_daemon *) * (g_num_daemons + 1));
- if(array == NULL)
+
+ tmp = realloc(g_daemons, (g_num_daemons+1) * sizeof(*g_daemons));
+ if(tmp == NULL)
{
/* The positive return value here indicates that this is a
* runtime error, not a configuration error. */
return ENOMEM;
}
{
/* The positive return value here indicates that this is a
* runtime error, not a configuration error. */
return ENOMEM;
}
- g_daemons = (struct ceph_daemon**) array;
- nd = malloc(sizeof(struct ceph_daemon));
+ g_daemons = tmp;
+
+ nd = malloc(sizeof(*nd));
if(!nd)
{
return ENOMEM;
}
if(!nd)
{
return ENOMEM;
}
- memcpy(nd, &cd, sizeof(
struct ceph_daemon
));
+ memcpy(nd, &cd, sizeof(
*nd
));
g_daemons[g_num_daemons++] = nd;
return 0;
}
g_daemons[g_num_daemons++] = nd;
return 0;
}
@@
-806,15
+808,13
@@
node_handler_define_schema(void *arg, const char *val, const char *key)
struct ceph_daemon *d = (struct ceph_daemon *) arg;
int pc_type;
pc_type = atoi(val);
struct ceph_daemon *d = (struct ceph_daemon *) arg;
int pc_type;
pc_type = atoi(val);
- DEBUG("ceph plugin: ceph_daemon_add_ds_entry(d=%s,key=%s,pc_type=%04x)",
- d->name, key, pc_type);
return ceph_daemon_add_ds_entry(d, key, pc_type);
}
/**
* Latency counter does not yet have an entry in last poll data - add it.
*/
return ceph_daemon_add_ds_entry(d, key, pc_type);
}
/**
* Latency counter does not yet have an entry in last poll data - add it.
*/
-static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum,
+static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum,
uint64_t cur_count)
{
d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data));
uint64_t cur_count)
{
d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data));
@@
-967,7
+967,7
@@
static int node_handler_fetch_data(void *arg, const char *val, const char *key)
//don't overflow bounds of array
index = (vtmp->d->ds_num - 1);
}
//don't overflow bounds of array
index = (vtmp->d->ds_num - 1);
}
-
+
/**
* counters should remain in same order we parsed schema... we maintain the
* index variable to keep track of current point in list of counters. first
/**
* counters should remain in same order we parsed schema... we maintain the
* index variable to keep track of current point in list of counters. first
@@
-1006,19
+1006,16
@@
static int node_handler_fetch_data(void *arg, const char *val, const char *key)
{
double sum, result;
sscanf(val, "%lf", &sum);
{
double sum, result;
sscanf(val, "%lf", &sum);
- DEBUG("ceph plugin: avgcount:%" PRIu64,vtmp->avgcount);
- DEBUG("ceph plugin: sum:%lf",sum);
if(vtmp->avgcount == 0)
{
vtmp->avgcount = 1;
}
if(vtmp->avgcount == 0)
{
vtmp->avgcount = 1;
}
-
+
/** User wants latency values as long run avg */
if(long_run_latency_avg)
{
result = (sum / vtmp->avgcount);
/** User wants latency values as long run avg */
if(long_run_latency_avg)
{
result = (sum / vtmp->avgcount);
- DEBUG("ceph plugin: uv->gauge = sumd / avgcounti = :%lf", result);
}
else
{
}
else
{
@@
-1027,8
+1024,6
@@
static int node_handler_fetch_data(void *arg, const char *val, const char *key)
{
return -ENOMEM;
}
{
return -ENOMEM;
}
- DEBUG("ceph plugin: uv->gauge = (sumd_now - sumd_last) / "
- "(avgcounti_now - avgcounti_last) = :%lf", result);
}
uv.gauge = result;
}
uv.gauge = result;
@@
-1039,12
+1034,10
@@
static int node_handler_fetch_data(void *arg, const char *val, const char *key)
case DSET_BYTES:
sscanf(val, "%lf", &tmp_d);
uv.gauge = tmp_d;
case DSET_BYTES:
sscanf(val, "%lf", &tmp_d);
uv.gauge = tmp_d;
- DEBUG("ceph plugin: uv->gauge = %lf",uv.gauge);
break;
case DSET_RATE:
sscanf(val, "%" PRIu64, &tmp_u);
uv.derive = tmp_u;
break;
case DSET_RATE:
sscanf(val, "%" PRIu64, &tmp_u);
uv.derive = tmp_u;
- DEBUG("ceph plugin: uv->derive = %" PRIu64 "",(uint64_t)uv.derive);
break;
case DSET_TYPE_UNFOUND:
default:
break;
case DSET_TYPE_UNFOUND:
default:
@@
-1057,7
+1050,6
@@
static int node_handler_fetch_data(void *arg, const char *val, const char *key)
vtmp->vlist.values = &uv;
vtmp->vlist.values_len = 1;
vtmp->vlist.values = &uv;
vtmp->vlist.values_len = 1;
- DEBUG("ceph plugin: dispatching %s\n", ds_name);
vtmp->index = (vtmp->index + 1);
plugin_dispatch_values(&vtmp->vlist);
vtmp->index = (vtmp->index + 1);
plugin_dispatch_values(&vtmp->vlist);
@@
-1480,8
+1472,6
@@
static int cconn_main_loop(uint32_t request_type)
}
else if(ret == 1)
{
}
else if(ret == 1)
{
- DEBUG("ceph plugin: did cconn_prepare(name=%s,i=%d,st=%d)",
- io->d->name, i, io->state);
polled_io_array[nfds++] = io_array + i;
}
}
polled_io_array[nfds++] = io_array + i;
}
}
@@
-1489,7
+1479,6
@@
static int cconn_main_loop(uint32_t request_type)
{
/* finished */
ret = 0;
{
/* finished */
ret = 0;
- DEBUG("ceph plugin: cconn_main_loop: no more cconn to manage.");
goto done;
}
gettimeofday(&tv, NULL);
goto done;
}
gettimeofday(&tv, NULL);
@@
-1562,7
+1551,6
@@
static int ceph_read(void)
static int ceph_init(void)
{
int ret;
static int ceph_init(void)
{
int ret;
- DEBUG("ceph plugin: ceph_init");
ceph_daemons_print();
ret = cconn_main_loop(ASOK_REQ_VERSION);
ceph_daemons_print();
ret = cconn_main_loop(ASOK_REQ_VERSION);