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 */
}
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)
{
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;
if (err) ERROR ("%s: %s", (s), err->message); \
} while(0)
- char *host_ptr;
- size_t host_len;
+static void
+init_value_list (value_list_t *vl, virDomainPtr dom)
+{
+ int i, n;
+ const char *name;
+ char uuid[VIR_UUID_STRING_BUFLEN];
- host_ptr = vl->host;
- host_len = sizeof (vl->host);
+
+ vl->interval = interval_g;
+
+ sstrncpy (vl->plugin, "libvirt", sizeof (vl->plugin));
+
+ vl->host[0] = '\0';
+
+ /* 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)
{
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;
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];
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;