* Dan Ryder <daryder@cisco.com>
**/
+#define _DEFAULT_SOURCE
#define _BSD_SOURCE
#include "collectd.h"
#include <stdlib.h>
#include <string.h>
#include <strings.h>
-#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/un.h>
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.
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;
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;
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;
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 **/
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;
}
uint32_t type;
char ds_name[DATA_MAX_NAME_LEN];
memset(ds_name, 0, sizeof(ds_name));
-
+
if(convert_special_metrics)
{
/**
sstrncpy(d->ds_names[d->ds_num], ds_name, DATA_MAX_NAME_LEN -1);
d->ds_num = (d->ds_num + 1);
-
+
return 0;
}
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))
"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;
}
- g_daemons = (struct ceph_daemon**) array;
- nd = malloc(sizeof(struct ceph_daemon));
+ g_daemons = tmp;
+
+ nd = malloc(sizeof(*nd));
if(!nd)
{
return ENOMEM;
}
- memcpy(nd, &cd, sizeof(struct ceph_daemon));
+ memcpy(nd, &cd, sizeof(*nd));
g_daemons[g_num_daemons++] = nd;
return 0;
}
/**
* 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));
//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
{
vtmp->avgcount = 1;
}
-
+
/** User wants latency values as long run avg */
if(long_run_latency_avg)
{
{
ERROR("ceph plugin: cconn_connect: connect(%d) failed: error %d",
fd, err);
+ close(fd);
return err;
}
err = -errno;
ERROR("ceph plugin: cconn_connect: fcntl(%d, O_NONBLOCK) error %d",
fd, err);
+ close(fd);
return err;
}
io->asok = fd;