0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-05-13 21:22:08 +00:00
netdata_netdata/web/api/formatters/rrdset2json.c
Markos Fountoulakis 6ca6d840dd Database engine ()
* Database engine prototype version 0

* Database engine initial integration with netdata POC

* Scalable database engine with file and memory management.

* Database engine integration with netdata

* Added MIN MAX definitions to fix alpine build of travis CI

* Bugfix for backends and new DB engine, remove useless rrdset_time2slot() calls and erroneous checks

* DB engine disk protocol correction

* Moved DB engine storage file location to /var/cache/netdata/{host}/dbengine

* Fix configure to require openSSL for DB engine

* Fix netdata daemon health not holding read lock when iterating chart dimensions

* Optimized query API for new DB engine and old netdata DB fallback code-path

* netdata database internal query API improvements and cleanup

* Bugfix for DB engine queries returning empty values

* Added netdata internal check for data queries for old and new DB

* Added statistics to DB engine and fixed memory corruption bug

* Added preliminary charts for DB engine statistics

* Changed DB engine ratio statistics to incremental

* Added netdata statistics charts for DB engine internal statistics

* Fix for netdata not compiling successfully when missing dbengine dependencies

* Added DB engine functional test to netdata unittest command parameter

* Implemented DB engine dataset generator based on example.random chart

* Fix build error in CI

* Support older versions of libuv1

* Fixes segmentation fault when using multiple DB engine instances concurrently

* Fix memory corruption bug

* Fixed createdataset advanced option not exiting

* Fix for DB engine not working on FreeBSD

* Support FreeBSD library paths of new dependencies

* Workaround for unsupported O_DIRECT in OS X

* Fix unittest crashing during cleanup

* Disable DB engine FS caching in Apple OS X since O_DIRECT is not available

* Fix segfault when unittest and DB engine dataset generator don't have permissions to create temporary host

* Modified DB engine dataset generator to create multiple files

* Toned down overzealous page cache prefetcher

* Reduce internal memory fragmentation for page-cache data pages

* Added documentation describing the DB engine

* Documentation bugfixes

* Fixed unit tests compilation errors since last rebase

* Added note to back-up the DB engine files in documentation

* Added codacy fix.

* Support old gcc versions for atomic counters in DB engine
2019-05-15 08:28:06 +03:00

111 lines
3.5 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#include "rrdset2json.h"
// generate JSON for the /api/v1/chart API call
void rrdset2json(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memory_used) {
rrdset_rdlock(st);
time_t first_entry_t = rrdset_first_entry_t(st);
time_t last_entry_t = rrdset_last_entry_t(st);
buffer_sprintf(wb,
"\t\t{\n"
"\t\t\t\"id\": \"%s\",\n"
"\t\t\t\"name\": \"%s\",\n"
"\t\t\t\"type\": \"%s\",\n"
"\t\t\t\"family\": \"%s\",\n"
"\t\t\t\"context\": \"%s\",\n"
"\t\t\t\"title\": \"%s (%s)\",\n"
"\t\t\t\"priority\": %ld,\n"
"\t\t\t\"plugin\": \"%s\",\n"
"\t\t\t\"module\": \"%s\",\n"
"\t\t\t\"enabled\": %s,\n"
"\t\t\t\"units\": \"%s\",\n"
"\t\t\t\"data_url\": \"/api/v1/data?chart=%s\",\n"
"\t\t\t\"chart_type\": \"%s\",\n"
"\t\t\t\"duration\": %ld,\n"
"\t\t\t\"first_entry\": %ld,\n"
"\t\t\t\"last_entry\": %ld,\n"
"\t\t\t\"update_every\": %d,\n"
"\t\t\t\"dimensions\": {\n"
, st->id
, st->name
, st->type
, st->family
, st->context
, st->title, st->name
, st->priority
, st->plugin_name?st->plugin_name:""
, st->module_name?st->module_name:""
, rrdset_flag_check(st, RRDSET_FLAG_ENABLED)?"true":"false"
, st->units
, st->name
, rrdset_type_name(st->chart_type)
, last_entry_t - first_entry_t + st->update_every//st->entries * st->update_every
, first_entry_t//rrdset_first_entry_t(st)
, last_entry_t//rrdset_last_entry_t(st)
, st->update_every
);
unsigned long memory = st->memsize;
size_t dimensions = 0;
RRDDIM *rd;
rrddim_foreach_read(rd, st) {
if(rrddim_flag_check(rd, RRDDIM_FLAG_HIDDEN) || rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE)) continue;
memory += rd->memsize;
buffer_sprintf(
wb
, "%s"
"\t\t\t\t\"%s\": { \"name\": \"%s\" }"
, dimensions ? ",\n" : ""
, rd->id
, rd->name
);
dimensions++;
}
if(dimensions_count) *dimensions_count += dimensions;
if(memory_used) *memory_used += memory;
buffer_strcat(wb, "\n\t\t\t},\n\t\t\t\"green\": ");
buffer_rrd_value(wb, st->green);
buffer_strcat(wb, ",\n\t\t\t\"red\": ");
buffer_rrd_value(wb, st->red);
buffer_strcat(wb, ",\n\t\t\t\"alarms\": {\n");
size_t alarms = 0;
RRDCALC *rc;
for(rc = st->alarms; rc ; rc = rc->rrdset_next) {
buffer_sprintf(
wb
, "%s"
"\t\t\t\t\"%s\": {\n"
"\t\t\t\t\t\"id\": %u,\n"
"\t\t\t\t\t\"status\": \"%s\",\n"
"\t\t\t\t\t\"units\": \"%s\",\n"
"\t\t\t\t\t\"update_every\": %d\n"
"\t\t\t\t}"
, (alarms) ? ",\n" : ""
, rc->name
, rc->id
, rrdcalc_status2string(rc->status)
, rc->units
, rc->update_every
);
alarms++;
}
buffer_sprintf(wb,
"\n\t\t\t}\n\t\t}"
);
rrdset_unlock(st);
}