| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_RRDHOST_STATUS_H |
| 4 | #define NETDATA_RRDHOST_STATUS_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | |
| 8 | typedef enum __attribute__((packed)) { |
| 9 | RRDHOST_STATUS_BASIC = 0, |
| 10 | RRDHOST_STATUS_STREAM = (1 << 0), |
| 11 | RRDHOST_STATUS_ML = (1 << 1), |
| 12 | RRDHOST_STATUS_DYNCFG = (1 << 2), |
| 13 | RRDHOST_STATUS_HEALTH = (1 << 3), |
| 14 | } RRDHOST_STATUS_INFO; |
| 15 | |
| 16 | #define RRDHOST_STATUS_ALL (RRDHOST_STATUS_BASIC|RRDHOST_STATUS_STREAM|RRDHOST_STATUS_ML|RRDHOST_STATUS_DYNCFG|RRDHOST_STATUS_HEALTH) |
| 17 | |
| 18 | typedef enum __attribute__((packed)) { |
| 19 | RRDHOST_DB_STATUS_INITIALIZING = 0, |
| 20 | RRDHOST_DB_STATUS_QUERYABLE, |
| 21 | } RRDHOST_DB_STATUS; |
| 22 | |
| 23 | typedef enum __attribute__((packed)) { |
| 24 | RRDHOST_DB_LIVENESS_STALE = 0, |
| 25 | RRDHOST_DB_LIVENESS_LIVE, |
| 26 | } RRDHOST_DB_LIVENESS; |
| 27 | |
| 28 | typedef enum __attribute__((packed)) { |
| 29 | RRDHOST_INGEST_STATUS_ARCHIVED = 0, // an old host in the database (never connected during this session) |
| 30 | RRDHOST_INGEST_STATUS_INITIALIZING, // contexts are still loading |
| 31 | RRDHOST_INGEST_STATUS_REPLICATING, // receiving replication |
| 32 | RRDHOST_INGEST_STATUS_ONLINE, // currently collecting data |
| 33 | RRDHOST_INGEST_STATUS_OFFLINE, // a disconnected node |
| 34 | } RRDHOST_INGEST_STATUS; |
| 35 | |
| 36 | typedef enum __attribute__((packed)) { |
| 37 | RRDHOST_INGEST_TYPE_LOCALHOST = 0, |
| 38 | RRDHOST_INGEST_TYPE_VIRTUAL, |
| 39 | RRDHOST_INGEST_TYPE_CHILD, |
| 40 | RRDHOST_INGEST_TYPE_ARCHIVED, |
| 41 | } RRDHOST_INGEST_TYPE; |
| 42 | |
| 43 | typedef enum __attribute__((packed)) { |
| 44 | RRDHOST_STREAM_STATUS_DISABLED = 0, |
| 45 | RRDHOST_STREAM_STATUS_REPLICATING, |
| 46 | RRDHOST_STREAM_STATUS_ONLINE, |
| 47 | RRDHOST_STREAM_STATUS_OFFLINE, |
| 48 | } RRDHOST_STREAMING_STATUS; |
| 49 | |
| 50 | typedef enum __attribute__((packed)) { |
| 51 | RRDHOST_ML_STATUS_DISABLED = 0, |
| 52 | RRDHOST_ML_STATUS_OFFLINE, |
| 53 | RRDHOST_ML_STATUS_RUNNING, |
| 54 | } RRDHOST_ML_STATUS; |
| 55 | |
| 56 | typedef enum __attribute__((packed)) { |
| 57 | RRDHOST_ML_TYPE_DISABLED = 0, |
| 58 | RRDHOST_ML_TYPE_SELF, |
| 59 | RRDHOST_ML_TYPE_RECEIVED, |
| 60 | } RRDHOST_ML_TYPE; |
| 61 | |
| 62 | typedef enum __attribute__((packed)) { |
| 63 | RRDHOST_HEALTH_STATUS_DISABLED = 0, |
| 64 | RRDHOST_HEALTH_STATUS_INITIALIZING, |
| 65 | RRDHOST_HEALTH_STATUS_RUNNING, |
| 66 | } RRDHOST_HEALTH_STATUS; |
| 67 | |
| 68 | typedef enum __attribute__((packed)) { |
| 69 | RRDHOST_DYNCFG_STATUS_UNAVAILABLE = 0, |
| 70 | RRDHOST_DYNCFG_STATUS_AVAILABLE, |
| 71 | } RRDHOST_DYNCFG_STATUS; |
| 72 | |
| 73 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_DB_STATUS); |
| 74 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_DB_LIVENESS); |
| 75 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_INGEST_STATUS); |
| 76 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_INGEST_TYPE); |
| 77 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_STREAMING_STATUS); |
| 78 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_ML_STATUS); |
| 79 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_ML_TYPE); |
| 80 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_HEALTH_STATUS); |
| 81 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_DYNCFG_STATUS); |
| 82 | |
| 83 | #define rrdhost_db_status_to_string(status) RRDHOST_DB_STATUS_2str(status) |
| 84 | #define rrdhost_db_liveness_to_string(status) RRDHOST_DB_LIVENESS_2str(status) |
| 85 | #define rrdhost_ingest_status_to_string(status) RRDHOST_INGEST_STATUS_2str(status) |
| 86 | #define rrdhost_ingest_type_to_string(type) RRDHOST_INGEST_TYPE_2str(type) |
| 87 | #define rrdhost_streaming_status_to_string(status) RRDHOST_STREAMING_STATUS_2str(status) |
| 88 | #define rrdhost_ml_status_to_string(status) RRDHOST_ML_STATUS_2str(status) |
| 89 | #define rrdhost_ml_type_to_string(type) RRDHOST_ML_TYPE_2str(type) |
| 90 | #define rrdhost_health_status_to_string(status) RRDHOST_HEALTH_STATUS_2str(status) |
| 91 | #define rrdhost_dyncfg_status_to_string(status) RRDHOST_DYNCFG_STATUS_2str(status) |
| 92 | |
| 93 | #include "streaming/stream-handshake.h" |
| 94 | #include "streaming/stream-capabilities.h" |
| 95 | #include "rrd.h" |
| 96 | |
| 97 | typedef struct rrdhost_status_t { |
| 98 | RRDHOST *host; |
| 99 | time_t now; |
| 100 | |
| 101 | struct { |
| 102 | RRDHOST_DYNCFG_STATUS status; |
| 103 | } dyncfg; |
| 104 | |
| 105 | struct { |
| 106 | RRDHOST_DB_STATUS status; |
| 107 | RRDHOST_DB_LIVENESS liveness; |
| 108 | RRD_DB_MODE mode; |
| 109 | time_t first_time_s; |
| 110 | time_t last_time_s; |
| 111 | size_t metrics; |
| 112 | size_t instances; |
| 113 | size_t contexts; |
| 114 | } db; |
| 115 | |
| 116 | struct { |
| 117 | RRDHOST_ML_STATUS status; |
| 118 | RRDHOST_ML_TYPE type; |
| 119 | struct ml_metrics_statistics metrics; |
| 120 | } ml; |
| 121 | |
| 122 | struct { |
| 123 | int16_t hops; |
| 124 | RRDHOST_INGEST_TYPE type; |
| 125 | RRDHOST_INGEST_STATUS status; |
| 126 | SOCKET_PEERS peers; |
| 127 | bool ssl; |
| 128 | STREAM_CAPABILITIES capabilities; |
| 129 | uint32_t id; |
| 130 | time_t since; |
| 131 | STREAM_HANDSHAKE reason; |
| 132 | |
| 133 | struct { |
| 134 | uint32_t metrics; // currently collected |
| 135 | uint32_t instances; // currently collected |
| 136 | uint32_t contexts; // currently collected |
| 137 | } collected; |
| 138 | |
| 139 | struct { |
| 140 | bool in_progress; |
| 141 | NETDATA_DOUBLE completion; |
| 142 | uint32_t instances; |
| 143 | } replication; |
| 144 | } ingest; |
| 145 | |
| 146 | struct { |
| 147 | int16_t hops; |
| 148 | RRDHOST_STREAMING_STATUS status; |
| 149 | SOCKET_PEERS peers; |
| 150 | bool ssl; |
| 151 | bool compression; |
| 152 | STREAM_CAPABILITIES capabilities; |
| 153 | uint32_t id; |
| 154 | time_t since; |
| 155 | STREAM_HANDSHAKE reason; |
| 156 | |
| 157 | struct { |
| 158 | bool in_progress; |
| 159 | NETDATA_DOUBLE completion; |
| 160 | size_t instances; |
| 161 | } replication; |
| 162 | |
| 163 | size_t sent_bytes_on_this_connection_per_type[STREAM_TRAFFIC_TYPE_MAX]; |
| 164 | } stream; |
| 165 | |
| 166 | struct { |
| 167 | RRDHOST_HEALTH_STATUS status; |
| 168 | struct { |
| 169 | uint32_t undefined; |
| 170 | uint32_t uninitialized; |
| 171 | uint32_t clear; |
| 172 | uint32_t warning; |
| 173 | uint32_t critical; |
| 174 | } alerts; |
| 175 | } health; |
| 176 | } RRDHOST_STATUS; |
| 177 | |
| 178 | void rrdhost_status(RRDHOST *host, time_t now, RRDHOST_STATUS *s, RRDHOST_STATUS_INFO info); |
| 179 | RRDHOST_INGEST_STATUS rrdhost_get_ingest_status(RRDHOST *host, time_t now); |
| 180 | RRDHOST_INGEST_STATUS rrdhost_ingestion_status(RRDHOST *host); |
| 181 | int16_t rrdhost_ingestion_hops(RRDHOST *host); |
| 182 | |
| 183 | #endif //NETDATA_RRDHOST_STATUS_H |