From: Wilfried Goesgens Date: Tue, 10 Oct 2017 14:43:08 +0000 (+0200) Subject: implement review sugestions. X-Git-Tag: collectd-5.12.0~4^2^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1db1ab4869261ec4d4f3d9df9f97c4687fd55379;p=thirdparty%2Fcollectd.git implement review sugestions. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index b7e31d956..30fd92652 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -2269,18 +2269,18 @@ Jolokia JSON reply retrieved via B (L) Password "passvoid" Post - - MBean "java.lang:name=PS Scavenge,type=GarbageCollector" - BeanNameSpace "java_lang" - - Attribute "CollectionTime" - type "gauge" - - - Attribute "CollectionCount" - type "gauge" - - + + MBean "java.lang:name=PS Scavenge,type=GarbageCollector" + BeanNameSpace "java_lang" + + Attribute "CollectionTime" + type "gauge" + + + Attribute "CollectionCount" + type "gauge" + + The plugin is intended to be written in a simple manner. Thus it doesn't @@ -2348,24 +2348,34 @@ I plugin. Please see there for a detailed description. =item BBeanNameE> One B block configures the translation of the gauges of one bean -to their respective collectd names. +to their respective collectd names, where BeanName sets the main name. -=back +=item B I -The following options are valid within B blocks: +The name of the Bean on the server + +=item B I + +The name space the Bean resides under =over 4 +=item B I + +A bean can contain several Attributes with gauges. Each one can be matched by a +AttributeName section or be ignored. + +=item B I + +How should this attribute be called under the BeanName in the collectd hierarchy? + =item B I Sets the type used to dispatch the values to the daemon. Detailed information about types and their configuration can be found in L. This option is mandatory. -=item B I - -Type-instance to use. Defaults to the current map key or current string array element value. - +=back =back =head2 Plugin C diff --git a/src/curl_jolokia.c b/src/curl_jolokia.c index 9bac36a93..ac93bb80b 100644 --- a/src/curl_jolokia.c +++ b/src/curl_jolokia.c @@ -37,14 +37,9 @@ #include #include -#if HAVE_YAJL_YAJL_VERSION_H -#include -#endif #define CJO_DEFAULT_HOST "localhost" -typedef size_t yajl_len_t; - struct cjo_attribute_s /* {{{ */ { char *attribute_name; @@ -71,9 +66,9 @@ typedef enum { eNone = 0, eValue, eMBean } cjo_expect_token; /* {{{ */ struct cjo_attribute_values_s { const char *json_value; - yajl_len_t json_value_len; + size_t json_value_len; const char *json_name; - yajl_len_t json_name_len; + size_t json_name_len; }; typedef struct cjo_attribute_values_s cjo_attribute_values_t; /* }}} */ @@ -104,7 +99,7 @@ struct cjo_s /* {{{ */ int attribute_pool_used; const char *json_key; - yajl_len_t json_key_len; + size_t json_key_len; cjo_expect_token expect; @@ -158,25 +153,24 @@ static void cjo_append_buffer(cjo_membuffer_t *buf, const char *append, static void cjo_release_buffercontent(cjo_membuffer_t *buf) { sfree(buf->buffer); - buf->buffer = NULL; buf->size = 0; buf->used = 0; } -static void cjo_remember_value(cjo_membuffer_t *ShouldBeInHere, - cjo_membuffer_t *BufferHereIfNot, +static void cjo_remember_value(cjo_membuffer_t *should_be_in_here, + cjo_membuffer_t *buffer_here_if_not, const char *ptr, size_t len, const char **SetThisOne, - yajl_len_t *SetThisLen) { - if (!((ptr > ShouldBeInHere->buffer) && - (ptr < ShouldBeInHere->buffer + ShouldBeInHere->used))) { - char *tptr = BufferHereIfNot->buffer + BufferHereIfNot->used; - cjo_append_buffer(BufferHereIfNot, ptr, len); + size_t *SetThisLen) { + if (!((ptr > should_be_in_here->buffer) && + (ptr < should_be_in_here->buffer + should_be_in_here->used))) { + char *tptr = buffer_here_if_not->buffer + buffer_here_if_not->used; + cjo_append_buffer(buffer_here_if_not, ptr, len); ptr = tptr; } *SetThisOne = ptr; - *SetThisLen = (yajl_len_t) len; + *SetThisLen = len; } /* @@ -212,7 +206,7 @@ static int cjo_get_type(cjo_attribute_t *attribute) { const data_set_t *ds = plugin_get_ds(attribute->type); if (ds == NULL) { - static char type[DATA_MAX_NAME_LEN] = "!!!invalid!!!"; + static char type[DATA_MAX_NAME_LEN] = "/--invalid--/"; if (strcmp(type, attribute->type) != 0) { ERROR("curl_jolokia plugin: Unable to look up DS type \"%s\".", @@ -261,7 +255,7 @@ static void cjo_submit(cjo_t *db) /* {{{ */ /* Create a null-terminated version of the string. */ int ds_type = cjo_get_type(curr_attribute); - if (ds_type == -1) { + if (ds_type < 0) { char attribute[db->curr_attribute->json_name_len + 1]; memcpy(attribute, db->curr_attribute->json_name, @@ -273,8 +267,7 @@ static void cjo_submit(cjo_t *db) /* {{{ */ continue; } - value_t ret_value; - memset(&ret_value, 0, sizeof(ret_value)); + value_t ret_value = {0}; char buffer[db->max_value_len + 1]; memcpy(buffer, db->curr_attribute->json_value, @@ -333,7 +326,7 @@ static void cjo_submit(cjo_t *db) /* {{{ */ #define CJO_CB_ABORT 0 #define CJO_CB_CONTINUE 1 -static int cjo_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) { +static int cjo_cb_string(void *ctx, const unsigned char *val, size_t len) { cjo_t *db = (cjo_t *)ctx; switch (db->expect) { @@ -365,7 +358,7 @@ static int cjo_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) { return CJO_CB_CONTINUE; } /* int cjo_cb_string */ -static int cjo_cb_number(void *ctx, const char *number, yajl_len_t number_len) { +static int cjo_cb_number(void *ctx, const char *number, size_t number_len) { cjo_t *db = (cjo_t *)ctx; switch (db->expect) { @@ -389,7 +382,7 @@ static int cjo_cb_number(void *ctx, const char *number, yajl_len_t number_len) { } /* int cjo_cb_number */ static int cjo_cb_map_key(void *ctx, unsigned char const *in_name, - yajl_len_t in_name_len) { + size_t in_name_len) { cjo_t *db = (cjo_t *)ctx; if ((in_name_len == 5) && !strncmp((const char *)in_name, "value", 5)) {