summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b2d31bc)
raw | patch | inline | side by side (parent: b2d31bc)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 10 Sep 2016 23:23:14 +0000 (19:23 -0400) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 10 Sep 2016 23:23:14 +0000 (19:23 -0400) |
For that purpose, let the metric store provide a reference to the timeseries
information object (to be populated on read). The JSON formatter compiles a
list of unique data_names and outputs that alongside the other metric
metadata.
information object (to be populated on read). The JSON formatter compiles a
list of unique data_names and outputs that alongside the other metric
metadata.
diff --git a/src/core/memstore.c b/src/core/memstore.c
index 87f9512745446d0f079ca6792fb12ce40168b1ca..9ae836921a5e6daaa99e42f57518917ebfc0f8dc 100644 (file)
--- a/src/core/memstore.c
+++ b/src/core/memstore.c
@@ -784,6 +784,7 @@ sdb_memstore_metric(sdb_memstore_t *store, const char *hostname, const char *nam
metric.stores = &(const sdb_metric_store_t){
metric_store->type,
metric_store->id,
+ NULL,
metric_store->last_update,
};
metric.stores_num = 1;
diff --git a/src/core/store_json.c b/src/core/store_json.c
index 56baa46d476d33f9f83974046ecbb982d375a2fa..256fdeac0496f9a55f97fa53bf3ee10f7c375ada 100644 (file)
--- a/src/core/store_json.c
+++ b/src/core/store_json.c
#include "sysdb.h"
#include "core/store.h"
#include "utils/error.h"
+#include "utils/strings.h"
#include <assert.h>
* 0: false
* 1: true */
int timeseries;
+ char **data_names;
+ size_t data_names_len;
/* generic meta-data */
sdb_time_t last_update;
sdb_strbuf_append(f->buf, "\"timeseries\": true, ");
else
sdb_strbuf_append(f->buf, "\"timeseries\": false, ");
+
+ if (obj->data_names_len > 0) {
+ sdb_strbuf_append(f->buf, "\"data_names\": [");
+ for (i = 0; i < obj->data_names_len; i++) {
+ char dn[2 * strlen(obj->data_names[i]) + 3];
+ escape_string(obj->data_names[i], dn);
+ sdb_strbuf_append(f->buf, "%s", dn);
+ if (i < obj->data_names_len - 1)
+ sdb_strbuf_append(f->buf, ", ");
+ }
+ sdb_strbuf_append(f->buf, "], ");
+ }
}
/* TODO: make time and interval formats configurable */
host->name,
/* value */ NULL,
- /* timeseries */ -1,
+ /* timeseries */ -1, NULL, 0,
host->last_update,
host->interval,
service->name,
/* value */ NULL,
- /* timeseries */ -1,
+ /* timeseries */ -1, NULL, 0,
service->last_update,
service->interval,
emit_metric(sdb_store_metric_t *metric, sdb_object_t *user_data)
{
sdb_store_json_formatter_t *f = F(user_data);
+ int status;
+ size_t i;
if ((! metric) || (! user_data))
return -1;
metric->name,
/* value */ NULL,
- /* timeseries */ metric->stores_num > 0,
+ /* timeseries */ metric->stores_num > 0, NULL, 0,
metric->last_update,
metric->interval,
(const char * const *)metric->backends,
};
- return json_emit(f, &o);
+ for (i = 0; i < metric->stores_num; i++) {
+ const sdb_metric_store_t *s = metric->stores + i;
+ size_t j;
+
+ if (! s->info)
+ continue;
+
+ if (! o.data_names) {
+ stringv_copy(&o.data_names, &o.data_names_len,
+ (const char * const *)s->info->data_names,
+ s->info->data_names_len);
+ continue;
+ }
+
+ for (j = 0; j < s->info->data_names_len; j++)
+ stringv_append_if_missing(&o.data_names, &o.data_names_len,
+ s->info->data_names[j]);
+ }
+
+ status = json_emit(f, &o);
+ stringv_free(&o.data_names, &o.data_names_len);
+ return status;
}
} /* emit_metric */
attr->key,
/* value */ &attr->value,
- /* timeseries */ -1,
+ /* timeseries */ -1, NULL, 0,
attr->last_update,
attr->interval,
index 3f20429b9f3e37eccdf40c2938c111ad163203b1..f0fc0c7d779cf4504eb67f316c6846c8f7e99303 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
#include "core/object.h"
#include "core/data.h"
#include "core/time.h"
+#include "core/timeseries.h"
#include "parser/ast.h"
#include "utils/strbuf.h"
typedef struct {
const char *type;
const char *id;
+ const sdb_timeseries_info_t *info;
sdb_time_t last_update;
} sdb_metric_store_t;
index 54df202fbecaa32aad705b32fe5b52440aa85dac..73d0dc6228e8aff05c5c7b41195412a1cfc63ffa 100644 (file)
char metric_id[(ud->ts_base ? strlen(ud->ts_base) : 0)
+ strlen(hostname) + sizeof(name) + 7];
- sdb_metric_store_t store = { ud->ts_type, metric_id, last_update };
+ sdb_metric_store_t store = { ud->ts_type, metric_id, NULL, last_update };
sdb_data_t data = { SDB_TYPE_STRING, { .string = NULL } };
index fa48728120b611efa075081a1571696b88499fde..0724ce1dd49b9dc9b18f0e7dbb2693c381d5c403 100644 (file)
sdb_metric_store_t store;
} metrics[] = {
{ "some.host.name", "foo/bar/qux",
- { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd", NULL, 0 } },
{ "some.host.name", "foo/bar/baz",
- { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd", NULL, 0 } },
{ "some.host.name", "foo2/bar/qux",
- { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd", NULL, 0 } },
{ "some.host.name", "foo2/bar/baz",
- { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd", NULL, 0 } },
{ "other.host.name", "foo/bar/qux",
- { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd", NULL, 0 } },
{ "other.host.name", "foo/bar/baz",
- { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd", NULL, 0 } },
{ "other.host.name", "foo2/bar/qux",
- { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd", NULL, 0 } },
{ "other.host.name", "foo2/bar/baz",
- { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd", 0 } },
+ { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd", NULL, 0 } },
};
static struct {
index d6a44e09f13ab01e095ecae6a64db3246e74e083..3fef343b61ef9efdb5a5adfa1ae6d6532ac5c5eb 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
START_TEST(test_store_metric)
{
- sdb_metric_store_t store1 = { "dummy-type1", "dummy-id1", 0 };
- sdb_metric_store_t store2 = { "dummy-type2", "dummy-id2", 0 };
+ sdb_metric_store_t store1 = { "dummy-type1", "dummy-id1", NULL, 0 };
+ sdb_metric_store_t store2 = { "dummy-type2", "dummy-id2", NULL, 0 };
struct {
const char *host;