| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_RRD2JSON_H |
| 4 | #define NETDATA_RRD2JSON_H 1 |
| 5 | |
| 6 | #include "web/api/web_api.h" |
| 7 | |
| 8 | #include "web/api/queries/rrdr.h" |
| 9 | |
| 10 | #include "web/api/formatters/csv/csv.h" |
| 11 | #include "web/api/formatters/ssv/ssv.h" |
| 12 | #include "web/api/formatters/json/json.h" |
| 13 | #include "web/api/formatters/value/value.h" |
| 14 | |
| 15 | #include "web/api/formatters/rrdset2json.h" |
| 16 | #include "web/api/formatters/charts2json.h" |
| 17 | #include "web/api/formatters/jsonwrap.h" |
| 18 | |
| 19 | #include "web/server/web_client.h" |
| 20 | |
| 21 | void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb); |
| 22 | |
| 23 | int data_query_execute(ONEWAYALLOC *owa, BUFFER *wb, struct query_target *qt, time_t *latest_timestamp); |
| 24 | |
| 25 | void rrdr_json_group_by_labels(BUFFER *wb, const char *key, RRDR *r, RRDR_OPTIONS options); |
| 26 | |
| 27 | int rrdset2value_api_v1( |
| 28 | RRDSET *st |
| 29 | , BUFFER *wb |
| 30 | , NETDATA_DOUBLE *n |
| 31 | , const char *dimensions |
| 32 | , size_t points |
| 33 | , time_t after |
| 34 | , time_t before |
| 35 | , RRDR_TIME_GROUPING group_method |
| 36 | , const char *group_options |
| 37 | , time_t resampling_time |
| 38 | , uint32_t options |
| 39 | , time_t *db_after |
| 40 | , time_t *db_before |
| 41 | , size_t *db_points_read |
| 42 | , size_t *db_points_per_tier |
| 43 | , size_t *result_points_generated |
| 44 | , int *value_is_null |
| 45 | , NETDATA_DOUBLE *anomaly_rate |
| 46 | , time_t timeout |
| 47 | , size_t tier |
| 48 | , QUERY_SOURCE query_source |
| 49 | , STORAGE_PRIORITY priority |
| 50 | ); |
| 51 | |
| 52 | // Same contract as rrdset2value_api_v1 but uses a caller-provided |
| 53 | // onewayalloc arena. Lets a caller that issues many back-to-back queries |
| 54 | // (e.g. evaluating all alerts on one host) amortise the mmap/munmap cost |
| 55 | // of owa create/destroy across the whole burst. The caller owns the owa's |
| 56 | // lifetime; between calls they should invoke onewayalloc_reset() to reclaim |
| 57 | // trailing pages and keep peak memory bounded. `owa` must be non-NULL. |
| 58 | int rrdset2value_api_v1_with_owa( |
| 59 | ONEWAYALLOC *owa |
| 60 | , RRDSET *st |
| 61 | , BUFFER *wb |
| 62 | , NETDATA_DOUBLE *n |
| 63 | , const char *dimensions |
| 64 | , size_t points |
| 65 | , time_t after |
| 66 | , time_t before |
| 67 | , RRDR_TIME_GROUPING group_method |
| 68 | , const char *group_options |
| 69 | , time_t resampling_time |
| 70 | , uint32_t options |
| 71 | , time_t *db_after |
| 72 | , time_t *db_before |
| 73 | , size_t *db_points_read |
| 74 | , size_t *db_points_per_tier |
| 75 | , size_t *result_points_generated |
| 76 | , int *value_is_null |
| 77 | , NETDATA_DOUBLE *anomaly_rate |
| 78 | , time_t timeout |
| 79 | , size_t tier |
| 80 | , QUERY_SOURCE query_source |
| 81 | , STORAGE_PRIORITY priority |
| 82 | ); |
| 83 | |
| 84 | static inline bool rrdr_dimension_should_be_exposed(RRDR_DIMENSION_FLAGS rrdr_dim_flags, RRDR_OPTIONS options) { |
| 85 | if(unlikely((options & RRDR_OPTION_RETURN_RAW) && (rrdr_dim_flags & RRDR_DIMENSION_QUERIED))) |
| 86 | return true; |
| 87 | |
| 88 | if(unlikely(rrdr_dim_flags & RRDR_DIMENSION_HIDDEN)) return false; |
| 89 | if(unlikely(!(rrdr_dim_flags & RRDR_DIMENSION_QUERIED))) return false; |
| 90 | if(unlikely((options & RRDR_OPTION_NONZERO) && !(rrdr_dim_flags & RRDR_DIMENSION_NONZERO))) return false; |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | #endif /* NETDATA_RRD2JSON_H */ |