</URL>
</Plugin>
-Another CouchDB example:
-The following example will collect the status values from each database:
-
- <URL "http://localhost:5984/_all_dbs">
- Instance "dbs"
- <Key "*/doc_count">
- Type "gauge"
- </Key>
- <Key "*/doc_del_count">
- Type "counter"
- </Key>
- <Key "*/disk_size">
- Type "bytes"
- </Key>
- </URL>
-
In the B<Plugin> block, there may be one or more B<URL> blocks, each defining
a URL to be fetched via HTTP (using libcurl) and one or more B<Key> blocks.
The B<Key> string argument must be in a path format, which is used to collect a
unsigned int len)
{
cj_t *db = (cj_t *)ctx;
- c_avl_tree_t *tree;
- char *ptr;
-
- if (db->depth != 1) /* e.g. _all_dbs */
- return (CJ_CB_CONTINUE);
+ char str[len + 1];
- cj_cb_map_key (ctx, val, len); /* same logic */
+ /* Create a null-terminated version of the string. */
+ memcpy (str, val, len);
+ str[len] = 0;
- 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)
{