From: Florian Forster Date: Sun, 21 Aug 2011 14:43:22 +0000 (+0200) Subject: Merge branch 'collectd-4.10' into collectd-5.0 X-Git-Tag: collectd-5.0.1~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ba2ee9aec4c0454eed8f29b4c6ce96c6fc372346;p=collectd.git Merge branch 'collectd-4.10' into collectd-5.0 Conflicts: src/curl_json.c src/libvirt.c Change-Id: I0852495b416435fa3cfd36068d967e0cd5ff689f --- ba2ee9aec4c0454eed8f29b4c6ce96c6fc372346 diff --cc src/curl_json.c index 5549f0ab,55527282..988ed58d --- a/src/curl_json.c +++ b/src/curl_json.c @@@ -97,13 -110,25 +110,26 @@@ static size_t cj_curl_callback (void *b if (db == NULL) return (0); -- status = yajl_parse(db->yajl, (unsigned char *)buf, len); - if ((status != yajl_status_ok) - && (status != yajl_status_insufficient_data)) ++ status = yajl_parse(db->yajl, (unsigned char *) buf, len); + if (status == yajl_status_ok) + { + #if HAVE_YAJL_V2 + status = yajl_complete_parse(db->yajl); + #else + status = yajl_parse_complete(db->yajl); + #endif + return (len); + } + #if !HAVE_YAJL_V2 + else if (status == yajl_status_insufficient_data) + return (len); + #endif + + if (status != yajl_status_ok) { unsigned char *msg = - yajl_get_error(db->yajl, 1, (unsigned char *)buf, len); + yajl_get_error(db->yajl, /* verbose = */ 1, + /* jsonText = */ (unsigned char *) buf, (unsigned int) len); ERROR ("curl_json plugin: yajl_parse failed: %s", msg); yajl_free_error(db->yajl, msg); return (0); /* abort write callback */ @@@ -187,29 -230,37 +213,29 @@@ static int cj_cb_map_key (void *ctx, co } static int cj_cb_string (void *ctx, const unsigned char *val, - unsigned int len) + yajl_len_t len) { cj_t *db = (cj_t *)ctx; - c_avl_tree_t *tree; - char *ptr; + char str[len + 1]; - if (db->depth != 1) /* e.g. _all_dbs */ - return (CJ_CB_CONTINUE); + /* Create a null-terminated version of the string. */ + memcpy (str, val, len); + str[len] = 0; - cj_cb_map_key (ctx, val, len); /* same logic */ - - tree = db->state[db->depth].tree; + /* No configuration for this string -> simply return. */ + if (db->state[db->depth].key == NULL) + return (CJ_CB_CONTINUE); - if ((tree != NULL) && (ptr = rindex (db->url, '/'))) + if (!CJ_IS_KEY (db->state[db->depth].key)) { - char url[PATH_MAX]; - CURL *curl; - - /* url =~ s,[^/]+$,$name, */ - len = (ptr - db->url) + 1; - ptr = url; - sstrncpy (ptr, db->url, sizeof (url)); - sstrncpy (ptr + len, db->state[db->depth].name, sizeof (url) - len); - - curl = curl_easy_duphandle (db->curl); - curl_easy_setopt (curl, CURLOPT_URL, url); - cj_curl_perform (db, curl); - curl_easy_cleanup (curl); + NOTICE ("curl_json plugin: Found string \"%s\", but the configuration " + "expects a map here.", str); + return (CJ_CB_CONTINUE); } - return (CJ_CB_CONTINUE); -} + + /* Handle the string as if it was a number. */ + return (cj_cb_number (ctx, (const char *) val, len)); +} /* int cj_cb_string */ static int cj_cb_start (void *ctx) { diff --cc src/disk.c index 697d850f,6187459f..fde0dcde --- a/src/disk.c +++ b/src/disk.c @@@ -426,18 -426,17 +426,17 @@@ static int disk_read (void int numfields; int fieldshift = 0; - int major = 0; int minor = 0; - counter_t read_sectors = 0; - counter_t write_sectors = 0; + derive_t read_sectors = 0; + derive_t write_sectors = 0; - counter_t read_ops = 0; - counter_t read_merged = 0; - counter_t read_time = 0; - counter_t write_ops = 0; - counter_t write_merged = 0; - counter_t write_time = 0; + derive_t read_ops = 0; + derive_t read_merged = 0; + derive_t read_time = 0; + derive_t write_ops = 0; + derive_t write_merged = 0; + derive_t write_time = 0; int is_disk = 0; diskstats_t *ds, *pre_ds; diff --cc src/libvirt.c index c74b937e,1f628792..774067cd --- a/src/libvirt.c +++ b/src/libvirt.c @@@ -132,113 -133,6 +132,109 @@@ static int refresh_lists (void) if (err) ERROR ("%s: %s", (s), err->message); \ } while(0) +static void +init_value_list (value_list_t *vl, virDomainPtr dom) +{ + int i, n; + const char *name; + char uuid[VIR_UUID_STRING_BUFLEN]; - char *host_ptr; - size_t host_len; + + vl->interval = interval_g; + + sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin)); + + vl->host[0] = '\0'; - host_ptr = vl->host; - host_len = sizeof (vl->host); + + /* Construct the hostname field according to HostnameFormat. */ + for (i = 0; i < HF_MAX_FIELDS; ++i) { + if (hostname_format[i] == hf_none) + continue; + + n = DATA_MAX_NAME_LEN - strlen (vl->host) - 2; + + if (i > 0 && n >= 1) { + strncat (vl->host, ":", 1); + n--; + } + + switch (hostname_format[i]) { + case hf_none: break; + case hf_hostname: + strncat (vl->host, hostname_g, n); + break; + case hf_name: + name = virDomainGetName (dom); + if (name) + strncat (vl->host, name, n); + break; + case hf_uuid: + if (virDomainGetUUIDString (dom, uuid) == 0) + strncat (vl->host, uuid, n); + break; + } + } + + vl->host[sizeof (vl->host) - 1] = '\0'; +} /* void init_value_list */ + +static void +cpu_submit (unsigned long long cpu_time, + virDomainPtr dom, const char *type) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + init_value_list (&vl, dom); + + values[0].derive = cpu_time; + + vl.values = values; + vl.values_len = 1; + + sstrncpy (vl.type, type, sizeof (vl.type)); + + plugin_dispatch_values (&vl); +} + +static void +vcpu_submit (derive_t cpu_time, + virDomainPtr dom, int vcpu_nr, const char *type) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + init_value_list (&vl, dom); + + values[0].derive = cpu_time; + vl.values = values; + vl.values_len = 1; + + sstrncpy (vl.type, type, sizeof (vl.type)); + ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%d", vcpu_nr); + + plugin_dispatch_values (&vl); +} + +static void +submit_derive2 (const char *type, derive_t v0, derive_t v1, + virDomainPtr dom, const char *devname) +{ + value_t values[2]; + value_list_t vl = VALUE_LIST_INIT; + + init_value_list (&vl, dom); + + values[0].derive = v0; + values[1].derive = v1; + vl.values = values; + vl.values_len = 2; + + sstrncpy (vl.type, type, sizeof (vl.type)); + sstrncpy (vl.type_instance, devname, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} /* void submit_derive2 */ + static int lv_init (void) { diff --cc src/mysql.c index cae6760b,69df7c70..6b636787 --- a/src/mysql.c +++ b/src/mysql.c @@@ -555,18 -707,17 +555,17 @@@ static int mysql_read (user_data_t *ud MYSQL_RES *res; MYSQL_ROW row; char *query; - int field_num; - unsigned long long qcache_hits = 0ULL; - unsigned long long qcache_inserts = 0ULL; - unsigned long long qcache_not_cached = 0ULL; - unsigned long long qcache_lowmem_prunes = 0ULL; - int qcache_queries_in_cache = -1; + derive_t qcache_hits = 0; + derive_t qcache_inserts = 0; + derive_t qcache_not_cached = 0; + derive_t qcache_lowmem_prunes = 0; + gauge_t qcache_queries_in_cache = NAN; - int threads_running = -1; - int threads_connected = -1; - int threads_cached = -1; - unsigned long long threads_created = 0ULL; + gauge_t threads_running = NAN; + gauge_t threads_connected = NAN; + gauge_t threads_cached = NAN; + derive_t threads_created = 0; unsigned long long traffic_incoming = 0ULL; unsigned long long traffic_outgoing = 0ULL; diff --cc src/notify_email.c index da6894a3,6b4678a7..cd216ca2 --- a/src/notify_email.c +++ b/src/notify_email.c @@@ -228,9 -228,7 +228,8 @@@ static int notify_email_config (const c static int notify_email_notification (const notification_t *n, user_data_t __attribute__((unused)) *user_data) { - smtp_recipient_t recipient; + time_t tt; struct tm timestamp_tm; char timestamp_str[64]; diff --cc src/processes.c index 72442f09,bab7080f..0c24cb70 --- a/src/processes.c +++ b/src/processes.c @@@ -871,11 -871,10 +871,10 @@@ int ps_read_process (int pid, procstat_ int i; - int ppid; int name_len; - long long unsigned cpu_user_counter; - long long unsigned cpu_system_counter; + derive_t cpu_user_counter; + derive_t cpu_system_counter; long long unsigned vmem_size; long long unsigned vmem_rss; long long unsigned stack_size;