void rrdr_json_wrapper_begin(RRDR *r, BUFFER *wb, uint32_t format, uint32_t options, int string_value)
{
+ //info("JSONWRAPPER(): %s: BEGIN", r->st->id);
char kq[2] = "", // key quote
sq[2] = ""; // string quote
);
if(string_value) buffer_strcat(wb, sq);
+ //info("JSONWRAPPER(): %s: END", r->st->id);
}
void rrdr_json_wrapper_end(RRDR *r, BUFFER *wb, uint32_t format, uint32_t options, int string_value)
static void rrdr2json(RRDR *r, BUFFER *wb, uint32_t options, int datatable)
{
+ //info("RRD2JSON(): %s: BEGIN", r->st->id);
int row_annotations = 0, dates = JSON_DATES_JS, dates_with_new = 0;
char kq[2] = "", // key quote
sq[2] = "", // string quote
// if all dimensions are hidden, print a null
if(!i) {
- buffer_strcat(wb, pre_value);
- if(options & RRDR_OPTION_NULL2ZERO)
- buffer_strcat(wb, "0");
- else
- buffer_strcat(wb, "null");
- buffer_strcat(wb, post_value);
+ buffer_strcat(wb, finish);
+ return;
}
long start = 0, end = rrdr_rows(r), step = 1;
if(dates == JSON_DATES_JS) {
// generate the local date time
- struct tm *tm = localtime(&now);
- if(!tm) { error("localtime() failed."); continue; }
+ struct tm tmbuf, *tm = localtime_r(&now, &tmbuf);
+ if(!tm) { error("localtime_r() failed."); continue; }
if(likely(i != start)) buffer_strcat(wb, ",\n");
buffer_strcat(wb, pre_date);
}
buffer_strcat(wb, finish);
+ //info("RRD2JSON(): %s: END", r->st->id);
}
static void rrdr2csv(RRDR *r, BUFFER *wb, uint32_t options, const char *startline, const char *separator, const char *endline)
{
+ //info("RRD2CSV(): %s: BEGIN", r->st->id);
long c, i;
RRDDIM *d;
}
else {
// generate the local date time
- struct tm *tm = localtime(&now);
+ struct tm tmbuf, *tm = localtime_r(&now, &tmbuf);
if(!tm) { error("localtime() failed."); continue; }
buffer_date(wb, tm->tm_year + 1900, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}
buffer_strcat(wb, endline);
}
+ //info("RRD2CSV(): %s: END", r->st->id);
}
static void rrdr2ssv(RRDR *r, BUFFER *wb, uint32_t options, const char *prefix, const char *separator, const char *suffix)
{
+ //info("RRD2SSV(): %s: BEGIN", r->st->id);
long c, i;
RRDDIM *d;
buffer_rrd_value(wb, sum);
}
buffer_strcat(wb, suffix);
+ //info("RRD2SSV(): %s: END", r->st->id);
}
inline static calculated_number *rrdr_line_values(RRDR *r)
return NULL;
}
- RRDR *r = malloc(sizeof(RRDR));
+ RRDR *r = calloc(1, sizeof(RRDR));
if(unlikely(!r)) goto cleanup;
r->st = st;
- r->has_st_lock = 0;
rrdr_lock_rrdset(r);
if(unlikely(!r->od)) goto cleanup;
r->c = -1;
- r->rows = 0;
r->group = 1;
r->update_every = 1;
- r->min = 0.0;
- r->max = 0.0;
-
- r->before = 0;
- r->after = 0;
-
return r;
cleanup:
// the duration of the chart
time_t duration = before - after;
- if(duration <= 0) return NULL;
-
- // how many points does the chart has?
long available_points = duration / st->update_every;
+ if(duration <= 0 || available_points <= 0)
+ return rrdr_create(st, 1);
+
// check the wanted points
if(points < 0) points = -points;
if(points > available_points) points = available_points;
long start_at_slot = rrdset_time2slot(st, before_new),
stop_at_slot = rrdset_time2slot(st, after_new);
+#ifdef NETDATA_INTERNAL_CHECKS
if(after_new < first_entry_t) {
error("after_new %u is too small, minimum %u", after_new, first_entry_t);
}
}
if(start_at_slot < 0 || start_at_slot >= st->entries) {
error("start_at_slot is invalid %ld, expected %ld to %ld", start_at_slot, 0, st->entries - 1);
- start_at_slot = st->current_entry;
}
if(stop_at_slot < 0 || stop_at_slot >= st->entries) {
error("stop_at_slot is invalid %ld, expected %ld to %ld", stop_at_slot, 0, st->entries - 1);
- stop_at_slot = 0;
}
if(points_new > (before_new - after_new) / group / st->update_every + 1) {
error("points_new %ld is more than points %ld", points_new, (before_new - after_new) / group / st->update_every + 1);
}
+#endif
- // error("SHIFT: %s: wanted %ld points, got %ld - group=%ld, wanted duration=%u, got %u - wanted %ld - %ld, got %ld - %ld", st->id, points, points_new, group, before - after, before_new - after_new, after, before, after_new, before_new);
+ //info("RRD2RRDR(): %s: wanted %ld points, got %ld - group=%ld, wanted duration=%u, got %u - wanted %ld - %ld, got %ld - %ld", st->id, points, points_new, group, before - after, before_new - after_new, after, before, after_new, before_new);
after = after_new;
before = before_new;
RRDR *r = rrdr_create(st, points);
if(!r) return NULL;
- if(!r->d) {
- rrdr_free(r);
- return NULL;
- }
+ if(!r->d) return r;
// find how many dimensions we have
long dimensions = r->d;
r->before = now;
r->after = now;
+ //info("RRD2RRDR(): %s: STARTING", st->id);
+
long slot = start_at_slot, counter = 0, stop_now = 0, added = 0, group_count = 0, add_this = 0;
for(; !stop_now ; now -= dt, slot--, counter++) {
if(unlikely(slot < 0)) slot = st->entries - 1;
}
// do the calculations
- for(rd = st->dimensions, c = 0 ; likely(rd && c < dimensions) ; rd = rd->next, c++) {
+ for(rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
storage_number n = rd->values[slot];
if(unlikely(!does_storage_number_exist(n))) continue;
}
rrdr_done(r);
+ //info("RRD2RRDR(): %s: END %ld loops made, %ld points generated", st->id, counter, rrdr_rows(r));
//error("SHIFT: %s: wanted %ld points, got %ld", st->id, points, rrdr_rows(r));
return r;
}
}
// generate the local date time
- struct tm *tm = localtime(&now);
+ struct tm tmbuf, *tm = localtime_r(&now, &tmbuf);
if(!tm) { error("localtime() failed."); continue; }
if(now > last_timestamp) last_timestamp = now;
element_chart_id: null,
element_legend: null, // the element with the legend of the chart (if created by us)
element_legend_id: null,
-
+
chart_url: null, // string - the url to download chart info
chart: null, // object - the chart as downloaded from the server
this.library.initialize(function() { this_state_object.updateChart(callback); });
return;
}
-
+
this.clearSelection();
this.chartURL();
if(this.debug) this.log('updating from ' + this.current.url);
var this_state_object = this;
$.ajax( {
url: this.current.url,
- crossDomain: true
+ crossDomain: true,
+ cache: false
})
.then(function(data) {
this_state_object.updateChartWithData(data);
$.ajax( {
url: this.chart_url,
- crossDomain: true
+ crossDomain: true,
+ cache: false
})
.done(function(chart) {
chart.url = this_state_object.chart_url;
this.element.innerHTML = '<div class="netdata-message netdata-' + type + '-message" style="font-size: x-small; overflow: hidden; width: 100%; height: 100%;"><small>'
+ msg
+ '</small></div>';
-
+
// reset the creation datetime
// since we overwrote the whole element
this.created_ms = 0
NETDATA.peityInitialize = function(callback) {
if(typeof netdataNoPeitys == 'undefined' || !netdataNoPeitys) {
- $.getScript(NETDATA.peity_js)
+ $.ajax({
+ url: NETDATA.peity_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('peity', NETDATA.peity_js);
})
NETDATA.sparklineInitialize = function(callback) {
if(typeof netdataNoSparklines == 'undefined' || !netdataNoSparklines) {
- $.getScript(NETDATA.sparkline_js)
+ $.ajax({
+ url: NETDATA.sparkline_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('sparkline', NETDATA.sparkline_js);
})
NETDATA.dygraphInitialize = function(callback) {
if(typeof netdataNoDygraphs == 'undefined' || !netdataNoDygraphs) {
- $.getScript(NETDATA.dygraph_js)
+ $.ajax({
+ url: NETDATA.dygraph_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('dygraph', NETDATA.dygraph_js);
})
else {
NETDATA._loadCSS(NETDATA.morris_css);
- $.getScript(NETDATA.morris_js)
+ $.ajax({
+ url: NETDATA.morris_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('morris', NETDATA.morris_js);
})
NETDATA.raphaelInitialize = function(callback) {
if(typeof netdataStopRaphael == 'undefined') {
- $.getScript(NETDATA.raphael_js)
+ $.ajax({
+ url: NETDATA.raphael_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('raphael', NETDATA.raphael_js);
})
NETDATA.googleInitialize = function(callback) {
if(typeof netdataNoGoogleCharts == 'undefined' || !netdataNoGoogleCharts) {
- $.getScript(NETDATA.google_js)
+ $.ajax({
+ url: NETDATA.google_js,
+ cache: true,
+ dataType: "script"
+ })
.done(function() {
NETDATA.registerChartLibrary('google', NETDATA.google_js);
NETDATA.errorReset();
NETDATA._loadjQuery(function() {
- $.getScript(NETDATA.serverDefault + 'lib/visible.js').then(function() {
+ $.ajax({
+ url: NETDATA.serverDefault + 'lib/visible.js',
+ cache: true,
+ dataType: "script"
+ })
+ .then(function() {
NETDATA._loadCSS(NETDATA.dashboard_css);
if(typeof netdataDontStart == 'undefined' || !netdataDontStart)