]> arthur.barton.de Git - netdata.git/commitdiff
added noreset flag to prevent apps.plugin charts from showing "reset or overflow...
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 19 Nov 2015 00:54:13 +0000 (02:54 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Thu, 19 Nov 2015 00:54:13 +0000 (02:54 +0200)
src/apps_plugin.c
src/plugins_d.c
src/rrd.c
src/rrd.h
src/rrd2json.c

index 99a1de056667465e72c69b309966257e1878a98c..8860938f0031b955908c19b2f1e24ebcfba5bc7d 100755 (executable)
@@ -1743,105 +1743,105 @@ void show_charts(void)
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu %s\n", w->name, (unsigned long long)(Hertz * update_every), w->hidden?"hidden":"");
+               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu %s\n", w->name, (unsigned long long)(Hertz * update_every), w->hidden?"hidden,noreset":"noreset");
        }
 
        fprintf(stdout, "CHART apps.mem '' 'Apps Dedicated Memory (w/o shared)' 'MB' apps apps stacked 20003 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute %ld %ld\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
+               fprintf(stdout, "DIMENSION %s '' absolute %ld %ld noreset\n", w->name, sysconf(_SC_PAGESIZE), 1024L*1024L);
        }
 
        fprintf(stdout, "CHART apps.threads '' 'Apps Threads' 'threads' apps apps stacked 20005 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
+               fprintf(stdout, "DIMENSION %s '' absolute 1 1 noreset\n", w->name);
        }
 
        fprintf(stdout, "CHART apps.processes '' 'Apps Processes' 'processes' apps apps stacked 20004 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
+               fprintf(stdout, "DIMENSION %s '' absolute 1 1 noreset\n", w->name);
        }
 
        fprintf(stdout, "CHART apps.cpu_user '' 'Apps CPU User Time (%ld%% = %ld core%s)' 'cpu time %%' apps none stacked 20020 %d\n", (processors * 100), processors, (processors>1)?"s":"", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu\n", w->name, Hertz * processors * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu noreset\n", w->name, Hertz * processors * update_every);
        }
 
        fprintf(stdout, "CHART apps.cpu_system '' 'Apps CPU System Time (%ld%% = %ld core%s)' 'cpu time %%' apps none stacked 20021 %d\n", (processors * 100), processors, (processors>1)?"s":"", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu\n", w->name, Hertz * processors * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 100 %llu noreset\n", w->name, Hertz * processors * update_every);
        }
 
        fprintf(stdout, "CHART apps.major_faults '' 'Apps Major Page Faults (swaps in)' 'page faults/s' apps apps stacked 20010 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, update_every);
        }
 
        fprintf(stdout, "CHART apps.minor_faults '' 'Apps Minor Page Faults' 'page faults/s' apps none stacked 20011 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, update_every);
        }
 
        fprintf(stdout, "CHART apps.lreads '' 'Apps Disk Logical Reads' 'kilobytes/s' apps none stacked 20042 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, 1024 * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, 1024 * update_every);
        }
 
        fprintf(stdout, "CHART apps.lwrites '' 'Apps I/O Logical Writes' 'kilobytes/s' apps none stacked 20042 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, 1024 * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, 1024 * update_every);
        }
 
        fprintf(stdout, "CHART apps.preads '' 'Apps Disk Reads' 'kilobytes/s' apps apps stacked 20002 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, 1024 * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, 1024 * update_every);
        }
 
        fprintf(stdout, "CHART apps.pwrites '' 'Apps Disk Writes' 'kilobytes/s' apps apps stacked 20002 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' incremental 1 %d\n", w->name, 1024 * update_every);
+               fprintf(stdout, "DIMENSION %s '' incremental 1 %d noreset\n", w->name, 1024 * update_every);
        }
 
        fprintf(stdout, "CHART apps.files '' 'Apps Open Files' 'open files' apps apps stacked 20050 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
+               fprintf(stdout, "DIMENSION %s '' absolute 1 1 noreset\n", w->name);
        }
 
        fprintf(stdout, "CHART apps.sockets '' 'Apps Open Sockets' 'open sockets' apps apps stacked 20051 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
+               fprintf(stdout, "DIMENSION %s '' absolute 1 1 noreset\n", w->name);
        }
 
        fprintf(stdout, "CHART apps.pipes '' 'Apps Pipes' 'open pipes' apps none stacked 20053 %d\n", update_every);
        for (w = target_root; w ; w = w->next) {
                if(w->target || (!w->processes && !w->exposed)) continue;
 
-               fprintf(stdout, "DIMENSION %s '' absolute 1 1\n", w->name);
+               fprintf(stdout, "DIMENSION %s '' absolute 1 1 noreset\n", w->name);
        }
 
        fprintf(stdout, "CHART netdata.apps_cpu '' 'Apps Plugin CPU' 'milliseconds/s' netdata netdata stacked 10000 %d\n", update_every);
index 584268b9037aac9805bd87fd091778cc4ebc7517..37b1ef57e91d27651472c922545993ef9c45d16e 100755 (executable)
@@ -287,7 +287,7 @@ void *pluginsd_worker_thread(void *arg)
                                char *algorithm = words[3];
                                char *multiplier_s = words[4];
                                char *divisor_s = words[5];
-                               char *hidden = words[6];
+                               char *options = words[6];
 
                                if(unlikely(!id || !*id)) {
                                        error("PLUGINSD: '%s' is requesting a DIMENSION, without an id. Disabling it.", cd->fullfilename);
@@ -320,13 +320,18 @@ void *pluginsd_worker_thread(void *arg)
                                        , rrddim_algorithm_name(rrddim_algorithm_id(algorithm))
                                        , multiplier
                                        , divisor
-                                       , hidden?hidden:""
+                                       , options?options:""
                                        );
 
                                RRDDIM *rd = rrddim_find(st, id);
                                if(unlikely(!rd)) {
                                        rd = rrddim_add(st, id, name, multiplier, divisor, rrddim_algorithm_id(algorithm));
-                                       if(unlikely(hidden && strcmp(hidden, "hidden") == 0)) rd->hidden = 1;
+                                       rd->flags = 0x00000000;
+                                       if(options && *options) {
+                                               if(strstr(options, "hidden") != NULL) rd->flags |= RRDDIM_FLAG_HIDDEN;
+                                               if(strstr(options, "noreset") != NULL) rd->flags |= RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS;
+                                               if(strstr(options, "nooverflow") != NULL) rd->flags |= RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS;
+                                       }
                                }
                                else if(unlikely(st->debug)) debug(D_PLUGINSD, "PLUGINSD: dimension %s/%s already exists. Not adding it again.", st->id, id);
                        }
index 307f6de459045ec096225fc52b5c1b49bf3d85ef..24add69fc05abee55e28d74c1bfcc9b4f48d797b 100755 (executable)
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -516,7 +516,7 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
        if(rd) {
                // we have a file mapped for rd
                rd->mapped = rrd_memory_mode;
-               rd->hidden = 0;
+               rd->flags = 0x00000000;
                rd->next = NULL;
                rd->name = NULL;
        }
@@ -730,7 +730,7 @@ int rrddim_hide(RRDSET *st, const char *id)
                return 1;
        }
 
-       rd->hidden = 1;
+       rd->flags |= RRDDIM_FLAG_HIDDEN;
        return 0;
 }
 
@@ -744,7 +744,7 @@ int rrddim_unhide(RRDSET *st, const char *id)
                return 1;
        }
 
-       rd->hidden = 0;
+       if(rd->flags & RRDDIM_FLAG_HIDDEN) rd->flags ^= RRDDIM_FLAG_HIDDEN;
        return 0;
 }
 
@@ -755,6 +755,7 @@ collected_number rrddim_set_by_pointer(RRDSET *st, RRDDIM *rd, collected_number
        gettimeofday(&rd->last_collected_time, NULL);
        rd->collected_value = value;
        rd->updated = 1;
+       rd->counter++;
 
        return rd->last_collected_value;
 }
@@ -904,6 +905,11 @@ unsigned long long rrdset_done(RRDSET *st)
        // at this stage we do not interpolate anything
        for( rd = st->dimensions ; likely(rd) ; rd = rd->next ) {
 
+               if(unlikely(!rd->updated || rd->counter <= 1)) {
+                       rd->calculated_value = 0;
+                       continue;
+               }
+
                if(unlikely(st->debug)) debug(D_RRD_STATS, "%s/%s: "
                        " last_collected_value = " COLLECTED_NUMBER_FORMAT
                        " collected_value = " COLLECTED_NUMBER_FORMAT
@@ -964,15 +970,15 @@ unsigned long long rrdset_done(RRDSET *st)
                                // if the new is smaller than the old (an overflow, or reset), set the old equal to the new
                                // to reset the calculation (it will give zero as the calculation for this second)
                                if(unlikely(rd->last_collected_value > rd->collected_value)) {
-                                       debug(D_RRD_STATS, "%s.%s: Detect RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
+                                       debug(D_RRD_STATS, "%s.%s: RESET or OVERFLOW. Last collected value = " COLLECTED_NUMBER_FORMAT ", current = " COLLECTED_NUMBER_FORMAT
                                                        , st->name, rd->name
                                                        , rd->last_collected_value
                                                        , rd->collected_value);
-                                       storage_flags = SN_EXISTS_RESET;
+                                       if(!(rd->flags & RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS)) storage_flags = SN_EXISTS_RESET;
                                        rd->last_collected_value = rd->collected_value;
                                }
 
-                               rd->calculated_value += (calculated_number)(rd->collected_value - rd->last_collected_value);
+                               rd->calculated_value = (calculated_number)(rd->collected_value - rd->last_collected_value);
 
                                if(unlikely(st->debug))
                                        debug(D_RRD_STATS, "%s/%s: CALC INC "
@@ -1090,7 +1096,7 @@ unsigned long long rrdset_done(RRDSET *st)
                                continue;
                        }
 
-                       if(likely(rd->updated && iterations < st->gap_when_lost_iterations_above)) {
+                       if(likely(rd->updated && rd->counter > 1 && iterations < st->gap_when_lost_iterations_above)) {
                                rd->values[st->current_entry] = pack_storage_number(
                                                  new_value
                                                * (calculated_number)rd->multiplier
index 17882366aeef6d144494ab016148a692494214d1..c1b16816d7d3bb8ad19edd0e6834de64d54a5f61 100755 (executable)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -22,7 +22,7 @@ extern int rrd_delete_unupdated_dimensions;
 #define RRD_ID_LENGTH_MAX 1024
 
 #define RRDSET_MAGIC           "NETDATA RRD SET FILE V013"
-#define RRDDIMENSION_MAGIC     "NETDATA RRD DIMENSION FILE V013"
+#define RRDDIMENSION_MAGIC     "NETDATA RRD DIMENSION FILE V015"
 
 typedef long long total_number;
 #define TOTAL_NUMBER_FORMAT "%lld"
@@ -75,6 +75,11 @@ extern int rrd_memory_mode_id(const char *name);
 extern int rrddim_algorithm_id(const char *name);
 extern const char *rrddim_algorithm_name(int chart_type);
 
+// ----------------------------------------------------------------------------
+// flags
+
+#define RRDDIM_FLAG_HIDDEN 0x00000001 // this dimension will not be offered to callers
+#define RRDDIM_FLAG_DONT_DETECT_RESETS_OR_OVERFLOWS 0x00000002 // do not offer RESET or OVERFLOW info to callers
 
 // ----------------------------------------------------------------------------
 // RRD DIMENSION
@@ -99,7 +104,6 @@ struct rrddim {
        long multiplier;                                                                // the multiplier of the collected values
        long divisor;                                                                   // the divider of the collected values
 
-       int hidden;                                                                             // if set to non zero, this dimension will not be offered to callers
        int mapped;                                                                             // if set to non zero, this dimension is mapped to a file
 
        // ------------------------------------------------------------------------
@@ -109,8 +113,12 @@ struct rrddim {
                                                                                                        // instead of strcmp() every item in the binary index
                                                                                                        // we first compare the hashes
 
+       uint32_t flags;
+
        char cache_filename[FILENAME_MAX+1];                    // the filename we load/save from/to this set
 
+       unsigned long counter;                                                  // the number of times we added values to this rrdim
+
        int updated;                                                                    // set to 0 after each calculation, to 1 after each collected value
                                                                                                        // we use this to detect that a dimension is not updated
 
index 84ba5866756a3acfffc5c59d80dd64a234db13d4..888c8f492981824faf82db1a8d42e2157d04b90e 100755 (executable)
@@ -93,7 +93,7 @@ unsigned long rrd_stats_one_json(RRDSET *st, char *options, struct web_buffer *w
                        , rd->id
                        , rd->name
                        , rd->entries
-                       , rd->hidden
+                       , (rd->flags & RRDDIM_FLAG_HIDDEN)?1:0
                        , rrddim_algorithm_name(rd->algorithm)
                        , rd->multiplier
                        , rd->divisor
@@ -540,7 +540,7 @@ RRDR *rrd2rrdr(RRDSET *st, long points, time_t after, time_t before, int group_m
 
                                // update the dimension options
                                if(found_non_zero[c]) r->od[c] |= RRDR_NONZERO;
-                               if(rd->hidden) r->od[c] |= RRDR_HIDDEN;
+                               if(rd->flags & RRDDIM_FLAG_HIDDEN) r->od[c] |= RRDR_HIDDEN;
 
                                // store the specific point options
                                co[c] = group_options[c];
@@ -673,7 +673,7 @@ unsigned long rrd_stats_json(int type, RRDSET *st, struct web_buffer *wb, int po
        // initialize them
        for( rd = st->dimensions, c = 0 ; rd && c < dimensions ; rd = rd->next, c++) {
                group_values[c] = 0;
-               print_hidden[c] = rd->hidden;
+               print_hidden[c] = (rd->flags & RRDDIM_FLAG_HIDDEN)?1:0;
                found_non_zero[c] = 0;
                found_non_existing[c] = 0;
        }