// SPDX-License-Identifier: GPL-3.0-or-later
#include "query.h"
#include "web/api/formatters/rrd2json.h"
#include "rrdr.h"
#include "average/average.h"
#include "incremental_sum/incremental_sum.h"
#include "max/max.h"
#include "median/median.h"
#include "min/min.h"
#include "sum/sum.h"
#include "stddev/stddev.h"
#include "ses/ses.h"
#include "des/des.h"
// ----------------------------------------------------------------------------
static struct {
const char *name;
uint32_t hash;
RRDR_GROUPING value;
// One time initialization for the module.
// This is called once, when netdata starts.
void (*init)(void);
// Allocate all required structures for a query.
// This is called once for each netdata query.
void *(*create)(struct rrdresult *r);
// Cleanup collected values, but don't destroy the structures.
// This is called when the query engine switches dimensions,
// as part of the same query (so same chart, switching metric).
void (*reset)(struct rrdresult *r);
// Free all resources allocated for the query.
void (*free)(struct rrdresult *r);
// Add a single value into the calculation.
// The module may decide to cache it, or use it in the fly.
void (*add)(struct rrdresult *r, calculated_number value);
// Generate a single result for the values added so far.
// More values and points may be requested later.
// It is up to the module to reset its internal structures
// when flushing it (so for a few modules it may be better to
// continue after a flush as if nothing changed, for others a
// cleanup of the internal structures may be required).
calculated_number (*flush)(struct rrdresult *r, RRDR_VALUE_FLAGS *rrdr_value_options_ptr);
} api_v1_data_groups[] = {
{.name = "average",
.hash = 0,
.value = RRDR_GROUPING_AVERAGE,
.init = NULL,
.create= grouping_create_average,
.reset = grouping_reset_average,
.free = grouping_free_average,
.add = grouping_add_average,
.flush = grouping_flush_average
},
{.name = "mean", // alias on 'average'
.hash = 0,
.value = RRDR_GROUPING_AVERAGE,
.init = NULL,
.create= grouping_create_average,
.reset = grouping_reset_average,
.free = grouping_free_average,
.add = grouping_add_average,
.flush = grouping_flush_average
},
{.name = "incremental_sum",
.hash = 0,
.value = RRDR_GROUPING_INCREMENTAL_SUM,
.init = NULL,
.create= grouping_create_incremental_sum,
.reset = grouping_reset_incremental_sum,
.free = grouping_free_incremental_sum,
.add = grouping_add_incremental_sum,
.flush = grouping_flush_incremental_sum
},
{.name = "incremental-sum",
.hash = 0,
.value = RRDR_GROUPING_INCREMENTAL_SUM,
.init = NULL,
.create= grouping_create_incremental_sum,
.reset = grouping_reset_incremental_sum,
.free = grouping_free_incremental_sum,
.add = grouping_add_incremental_sum,
.flush = grouping_flush_incremental_sum
},
{.name = "median",
.hash = 0,
.value = RRDR_GROUPING_MEDIAN,
.init = NULL,
.create= grouping_create_median,
.reset = grouping_reset_median,
.free = grouping_free_median,
.add = grouping_add_median,
.flush = grouping_flush_median
},
{.name = "min",
.hash = 0,
.value = RRDR_GROUPING_MIN,
.init = NULL,
.create= grouping_create_min,
.reset = grouping_reset_min,
.free = grouping_free_min,
.add = grouping_add_min,
.flush = grouping_flush_min
},
{.name = "max",
.hash = 0,
.value = RRDR_GROUPING_MAX,
.init = NULL,
.create= grouping_create_max,
.reset = grouping_reset_max,
.free = grouping_free_max,
.add = grouping_add_max,
.flush