| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_STATUS_FILE_H |
| 4 | #define NETDATA_STATUS_FILE_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | #include "daemon/config/netdata-conf-profile.h" |
| 8 | #include "database/rrd-database-mode.h" |
| 9 | #include "database/rrd-metadata.h" |
| 10 | #include "claim/cloud-status.h" |
| 11 | #include "machine-guid.h" |
| 12 | #include "status-file-dmi.h" |
| 13 | |
| 14 | #define STATUS_FILE_VERSION 28 |
| 15 | |
| 16 | typedef enum { |
| 17 | DAEMON_STATUS_NONE, |
| 18 | DAEMON_STATUS_INITIALIZING, |
| 19 | DAEMON_STATUS_RUNNING, |
| 20 | DAEMON_STATUS_EXITING, |
| 21 | DAEMON_STATUS_EXITED, |
| 22 | } DAEMON_STATUS; |
| 23 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(DAEMON_STATUS); |
| 24 | |
| 25 | typedef enum { |
| 26 | DAEMON_OS_TYPE_UNKNOWN, |
| 27 | DAEMON_OS_TYPE_LINUX, |
| 28 | DAEMON_OS_TYPE_FREEBSD, |
| 29 | DAEMON_OS_TYPE_MACOS, |
| 30 | DAEMON_OS_TYPE_WINDOWS, |
| 31 | } DAEMON_OS_TYPE; |
| 32 | ENUM_STR_DEFINE_FUNCTIONS_EXTERN(DAEMON_OS_TYPE); |
| 33 | |
| 34 | typedef struct daemon_status_file { |
| 35 | uint32_t v; // the version of the status file |
| 36 | |
| 37 | char version[32]; // the netdata version |
| 38 | DAEMON_STATUS status; // the daemon status |
| 39 | EXIT_REASON exit_reason; // the exit reason (maybe empty) |
| 40 | ND_PROFILE profile; // the profile of the agent |
| 41 | DAEMON_OS_TYPE os_type; |
| 42 | RRD_DB_MODE db_mode; |
| 43 | CLOUD_STATUS cloud_status; |
| 44 | uint8_t db_tiers; |
| 45 | bool kubernetes; |
| 46 | bool sentry_available; // true when sentry support is compiled in |
| 47 | |
| 48 | time_t boottime; // system boottime |
| 49 | time_t uptime; // netdata uptime |
| 50 | usec_t timestamp_ut; // the timestamp of the status file |
| 51 | char timestamp_ut_rfc3339[RFC3339_MAX_LENGTH]; // pre-calculated RFC3339 for async-signal-safe use |
| 52 | size_t restarts; // the number of times this agent has restarted (ever) |
| 53 | size_t crashes; // the number of times this agent has crashed (ever) |
| 54 | size_t posts; // the number of posts to the backend |
| 55 | ssize_t reliability; // consecutive restarts: > 0 reliable, < 0 crashing |
| 56 | pid_t pid; // the process id of the netdata agent |
| 57 | |
| 58 | ND_MACHINE_GUID host_id; // the machine guid of the system |
| 59 | |
| 60 | ND_UUID boot_id; // the boot id of the system |
| 61 | ND_UUID invocation; // the netdata invocation id generated the file |
| 62 | ND_UUID node_id; // the Netdata Cloud node id of the agent |
| 63 | ND_UUID claim_id; // the Netdata Cloud claim id of the agent |
| 64 | ND_UUID machine_id; // the unique machine id of the system |
| 65 | |
| 66 | struct { |
| 67 | usec_t init_started_ut; |
| 68 | time_t init; |
| 69 | usec_t exit_started_ut; |
| 70 | time_t exit; |
| 71 | } timings; |
| 72 | |
| 73 | uint64_t oom_protection; |
| 74 | uint64_t netdata_max_rss; |
| 75 | OS_SYSTEM_MEMORY memory; |
| 76 | OS_SYSTEM_DISK_SPACE var_cache; |
| 77 | |
| 78 | struct { |
| 79 | uint64_t dbengine; // Size of dbengine files |
| 80 | uint64_t sqlite; // Size of sqlite files |
| 81 | uint64_t other; // Size of other files (total - dbengine - sqlite) |
| 82 | usec_t last_updated_ut; // Last time the footprint was updated (microseconds) |
| 83 | char last_updated_ut_rfc3339[RFC3339_MAX_LENGTH]; // pre-calculated RFC3339 for async-signal-safe use |
| 84 | } disk_footprint; |
| 85 | |
| 86 | // Metrics statistics |
| 87 | RRDSTATS_METADATA metrics_metadata; |
| 88 | |
| 89 | char install_type[32]; |
| 90 | char architecture[32]; // ECS: host.architecture |
| 91 | char virtualization[32]; |
| 92 | char container[32]; |
| 93 | char kernel_version[32]; // ECS: os.kernel |
| 94 | char os_name[32]; // ECS: os.name |
| 95 | char os_version[32]; // ECS: os.version |
| 96 | char os_id[64]; // ECS: os.family |
| 97 | char os_id_like[64]; // ECS: os.platform |
| 98 | char timezone[32]; |
| 99 | char cloud_provider_type[32]; |
| 100 | char cloud_instance_type[32]; |
| 101 | char cloud_instance_region[32]; |
| 102 | bool read_system_info; |
| 103 | size_t system_cpus; |
| 104 | |
| 105 | DMI_INFO hw; |
| 106 | |
| 107 | struct { |
| 108 | // normalized information from cloud provider and h/w information |
| 109 | char vendor[64]; |
| 110 | char name[96]; |
| 111 | char type[16]; |
| 112 | } product; |
| 113 | |
| 114 | char stack_traces[63]; // the backend for capturing stack traces |
| 115 | |
| 116 | struct { |
| 117 | SPINLOCK spinlock; |
| 118 | long line; |
| 119 | char filename[256]; |
| 120 | char function[128]; |
| 121 | char errno_str[64]; |
| 122 | char message[512]; |
| 123 | char stack_trace[4096]; |
| 124 | char thread[ND_THREAD_TAG_MAX + 1]; |
| 125 | pid_t thread_id; |
| 126 | SIGNAL_CODE signal_code; |
| 127 | uintptr_t fault_address; |
| 128 | uint32_t worker_job_id; |
| 129 | bool sentry; // true when the error was also reported to sentry |
| 130 | } fatal; |
| 131 | } DAEMON_STATUS_FILE; |
| 132 | |
| 133 | // these are used instead of locks when locks cannot be used (signal handler, out of memory, etc) |
| 134 | #define dsf_acquire(ds) __atomic_load_n(&(ds).v, __ATOMIC_ACQUIRE) |
| 135 | #define dsf_release(ds) __atomic_store_n(&(ds).v, (ds).v, __ATOMIC_RELEASE) |
| 136 | |
| 137 | // saves the current status |
| 138 | void daemon_status_file_update_status(DAEMON_STATUS status); |
| 139 | |
| 140 | // returns true when the event is duplicate and should not be reported again |
| 141 | bool daemon_status_file_deadly_signal_received(EXIT_REASON reason, SIGNAL_CODE code, void *fault_address, bool chained_handler); |
| 142 | |
| 143 | // check for a crash |
| 144 | void daemon_status_file_check_crash(void); |
| 145 | |
| 146 | bool daemon_status_file_has_last_crashed(DAEMON_STATUS_FILE *ds); |
| 147 | bool daemon_status_file_was_incomplete_shutdown(void); |
| 148 | |
| 149 | void daemon_status_file_startup_step(const char *step); |
| 150 | void daemon_status_file_shutdown_step(const char *step, const char *step_timings); |
| 151 | void daemon_status_file_shutdown_timeout(BUFFER *trace); |
| 152 | |
| 153 | void daemon_status_file_init(void); |
| 154 | void daemon_status_file_register_fatal(const char *filename, const char *function, const char *message, const char *errno_str, const char *stack_trace, long line); |
| 155 | |
| 156 | const char *daemon_status_file_get_install_type(void); |
| 157 | const char *daemon_status_file_get_architecture(void); |
| 158 | const char *daemon_status_file_get_virtualization(void); |
| 159 | const char *daemon_status_file_get_container(void); |
| 160 | const char *daemon_status_file_get_os_name(void); |
| 161 | const char *daemon_status_file_get_os_version(void); |
| 162 | const char *daemon_status_file_get_os_id(void); |
| 163 | const char *daemon_status_file_get_os_id_like(void); |
| 164 | const char *daemon_status_file_get_timezone(void); |
| 165 | const char *daemon_status_file_get_cloud_provider_type(void); |
| 166 | const char *daemon_status_file_get_cloud_instance_type(void); |
| 167 | const char *daemon_status_file_get_cloud_instance_region(void); |
| 168 | |
| 169 | const char *daemon_status_file_get_fatal_filename(void); |
| 170 | const char *daemon_status_file_get_fatal_function(void); |
| 171 | const char *daemon_status_file_get_fatal_message(void); |
| 172 | const char *daemon_status_file_get_fatal_errno(void); |
| 173 | const char *daemon_status_file_get_fatal_stack_trace(void); |
| 174 | const char *daemon_status_file_get_fatal_thread(void); |
| 175 | const char *daemon_status_file_get_stack_trace_backend(void); |
| 176 | const char *daemon_status_file_get_sys_vendor(void); |
| 177 | const char *daemon_status_file_get_product_name(void); |
| 178 | const char *daemon_status_file_get_product_type(void); |
| 179 | |
| 180 | pid_t daemon_status_file_get_fatal_thread_id(void); |
| 181 | long daemon_status_file_get_fatal_line(void); |
| 182 | DAEMON_STATUS daemon_status_file_get_status(void); |
| 183 | size_t daemon_status_file_get_restarts(void); |
| 184 | ssize_t daemon_status_file_get_reliability(void); |
| 185 | ND_MACHINE_GUID daemon_status_file_get_host_id(void); |
| 186 | size_t daemon_status_file_get_fatal_worker_job_id(void); |
| 187 | |
| 188 | #endif //NETDATA_STATUS_FILE_H |