| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_RRDHOST_SYSTEM_INFO_H |
| 4 | #define NETDATA_RRDHOST_SYSTEM_INFO_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | #include "rrdlabels.h" |
| 8 | #include "daemon/status-file.h" |
| 9 | |
| 10 | #ifdef RRDHOST_SYSTEM_INFO_INTERNALS |
| 11 | struct rrdhost_system_info { |
| 12 | char *cloud_provider_type; |
| 13 | char *cloud_instance_type; |
| 14 | char *cloud_instance_region; |
| 15 | |
| 16 | char *host_os_name; |
| 17 | char *host_os_id; |
| 18 | char *host_os_id_like; |
| 19 | char *host_os_version; |
| 20 | char *host_os_version_id; |
| 21 | char *host_os_detection; |
| 22 | char *host_cores; |
| 23 | char *host_cpu_freq; |
| 24 | char *host_cpu_model; |
| 25 | char *host_ram_total; |
| 26 | char *host_disk_space; |
| 27 | char *container_os_name; |
| 28 | char *container_os_id; |
| 29 | char *container_os_id_like; |
| 30 | char *container_os_version; |
| 31 | char *container_os_version_id; |
| 32 | char *container_os_detection; |
| 33 | char *kernel_name; |
| 34 | char *kernel_version; |
| 35 | char *architecture; |
| 36 | char *virtualization; |
| 37 | char *virt_detection; |
| 38 | char *container; |
| 39 | char *container_detection; |
| 40 | char *is_k8s_node; |
| 41 | int16_t hops; |
| 42 | bool ml_capable; |
| 43 | bool ml_enabled; |
| 44 | char *install_type; |
| 45 | char *prebuilt_arch; |
| 46 | char *prebuilt_dist; |
| 47 | char *network_default_iface; |
| 48 | char *network_default_iface_ip; |
| 49 | char *network_default_iface_detection; |
| 50 | int mc_version; |
| 51 | char *hw_product_name; |
| 52 | char *hw_sys_vendor; |
| 53 | char *hw_product_type; |
| 54 | }; |
| 55 | #else |
| 56 | struct rrdhost_system_info; |
| 57 | #endif |
| 58 | |
| 59 | // -------------------------------------------------------------------------------------------------------------------- |
| 60 | // allocation and free |
| 61 | |
| 62 | struct rrdhost_system_info *rrdhost_system_info_create(void); |
| 63 | void rrdhost_system_info_free(struct rrdhost_system_info *system_info); |
| 64 | |
| 65 | // -------------------------------------------------------------------------------------------------------------------- |
| 66 | // importing fields |
| 67 | |
| 68 | // detect system info on current system |
| 69 | int rrdhost_system_info_detect(struct rrdhost_system_info *system_info); |
| 70 | |
| 71 | // import from host rrdlabels |
| 72 | struct rrdhost_system_info *rrdhost_system_info_from_host_labels(RRDLABELS *labels); |
| 73 | |
| 74 | // -------------------------------------------------------------------------------------------------------------------- |
| 75 | // setting individual fields |
| 76 | |
| 77 | void rrdhost_system_info_hops_set(struct rrdhost_system_info *si, int16_t hops); |
| 78 | void rrdhost_system_info_ml_capable_set(struct rrdhost_system_info *system_info, bool capable); |
| 79 | void rrdhost_system_info_ml_enabled_set(struct rrdhost_system_info *system_info, bool enabled); |
| 80 | void rrdhost_system_info_mc_version_set(struct rrdhost_system_info *system_info, int version); |
| 81 | |
| 82 | int rrdhost_system_info_set_by_name(struct rrdhost_system_info *system_info, char *name, char *value); |
| 83 | |
| 84 | // -------------------------------------------------------------------------------------------------------------------- |
| 85 | // reading individual fields |
| 86 | |
| 87 | const char *rrdhost_system_info_install_type(struct rrdhost_system_info *si); |
| 88 | const char *rrdhost_system_info_prebuilt_dist(struct rrdhost_system_info *si); |
| 89 | int16_t rrdhost_system_info_hops(struct rrdhost_system_info *si); |
| 90 | |
| 91 | // -------------------------------------------------------------------------------------------------------------------- |
| 92 | // exporting in various forms |
| 93 | |
| 94 | void rrdhost_system_info_to_rrdlabels(struct rrdhost_system_info *system_info, RRDLABELS *labels); |
| 95 | |
| 96 | void rrdhost_system_info_to_json_v1(BUFFER *wb, struct rrdhost_system_info *system_info); |
| 97 | void rrdhost_system_info_to_json_v2(BUFFER *wb, struct rrdhost_system_info *system_info); |
| 98 | void rrdhost_system_info_to_url_encode_stream(BUFFER *wb, struct rrdhost_system_info *system_info); |
| 99 | |
| 100 | typedef int (*add_host_sysinfo_key_value_t)(const char *name, const char *value, nd_uuid_t *uuid); |
| 101 | |
| 102 | // Number of NETDATA_* keys emitted by rrdhost_system_info_foreach(); callers |
| 103 | // compare against the cb-success count to detect partial-store failures. |
| 104 | // Keep in sync with the body of rrdhost_system_info_foreach(). |
| 105 | #define RRDHOST_SYSTEM_INFO_KEY_COUNT 27 |
| 106 | |
| 107 | int rrdhost_system_info_foreach(struct rrdhost_system_info *system_info, add_host_sysinfo_key_value_t cb, nd_uuid_t *uuid); |
| 108 | |
| 109 | struct update_node_info; |
| 110 | void rrdhost_system_info_to_node_info(struct rrdhost_system_info *system_info, struct update_node_info *node_info); |
| 111 | |
| 112 | void rrdhost_system_info_to_streaming_function_array(BUFFER *wb, struct rrdhost_system_info *system_info); |
| 113 | void rrdhost_system_info_to_json_object_fields(BUFFER *wb, struct rrdhost_system_info *system_info); |
| 114 | |
| 115 | bool get_daemon_status_fields_from_system_info(DAEMON_STATUS_FILE *ds); |
| 116 | void rrdhost_system_info_swap(struct rrdhost_system_info *a, struct rrdhost_system_info *b); |
| 117 | |
| 118 | bool localhost_is_docker(); |
| 119 | |
| 120 | #endif //NETDATA_RRDHOST_SYSTEM_INFO_H |