diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-02-07 20:14:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-07 12:14:47 -0800 |
commit | ee55155912c17139a3a0ab2815f15651e63e5a9c (patch) | |
tree | 3cbaf6c35e0ac9dba8023a9db9b2979c266992d5 | |
parent | 57055c9ac18e70a812aec4230219e928405cbb26 (diff) |
Update `api/v1/info ` (#7862)
* update_info: New variables
This commit creates inside script and it reads them to Netdata
* update_info: API
This commit changes the web api response
* update_info: Disk space
This commit brings the disk space to info and renames the environment variables inside Netdata
* update_info: Rename variable
This commit renames the environment variable
* update_info: Rename response variable
This commit renames a response variable
* update_info: Labels
This commit creates the missing labels
* update_info: test before free
* update_info: Doc function
This commit brings docummentation to the functions to give instructions to developer
* update_info: Fix info message
This commit removes some info messages from the error.log
* update_info: Remove unecessary ifs, considering free manual
-rwxr-xr-x | daemon/system-info.sh | 18 | ||||
-rw-r--r-- | database/rrd.h | 4 | ||||
-rw-r--r-- | database/rrdhost.c | 48 | ||||
-rw-r--r-- | libnetdata/libnetdata.c | 1 | ||||
-rw-r--r-- | web/api/web_api_v1.c | 4 |
5 files changed, 65 insertions, 10 deletions
diff --git a/daemon/system-info.sh b/daemon/system-info.sh index 6c19c6e636..110b4b3129 100755 --- a/daemon/system-info.sh +++ b/daemon/system-info.sh @@ -370,13 +370,13 @@ echo "NETDATA_SYSTEM_VIRTUALIZATION=${VIRTUALIZATION}" echo "NETDATA_SYSTEM_VIRT_DETECTION=${VIRT_DETECTION}" echo "NETDATA_SYSTEM_CONTAINER=${CONTAINER}" echo "NETDATA_SYSTEM_CONTAINER_DETECTION=${CONT_DETECTION}" -echo "NETDATA_CPU_LOGICAL_CPU_COUNT=${LCPU_COUNT}" -echo "NETDATA_CPU_VENDOR=${CPU_VENDOR}" -echo "NETDATA_CPU_MODEL=${CPU_MODEL}" -echo "NETDATA_CPU_FREQ=${CPU_FREQ}" -echo "NETDATA_CPU_DETECTION=${CPU_INFO_SOURCE}" -echo "NETDATA_TOTAL_RAM=${TOTAL_RAM}" -echo "NETDATA_RAM_DETECTION=${RAM_DETECTION}" -echo "NETDATA_TOTAL_DISK_SIZE=${DISK_SIZE}" -echo "NETDATA_DISK_DETECTION=${DISK_DETECTION}" +echo "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT=${LCPU_COUNT}" +echo "NETDATA_SYSTEM_CPU_VENDOR=${CPU_VENDOR}" +echo "NETDATA_SYSTEM_CPU_MODEL=${CPU_MODEL}" +echo "NETDATA_SYSTEM_CPU_FREQ=${CPU_FREQ}" +echo "NETDATA_SYSTEM_CPU_DETECTION=${CPU_INFO_SOURCE}" +echo "NETDATA_SYSTEM_TOTAL_RAM=${TOTAL_RAM}" +echo "NETDATA_SYSTEM_RAM_DETECTION=${RAM_DETECTION}" +echo "NETDATA_SYSTEM_TOTAL_DISK_SIZE=${DISK_SIZE}" +echo "NETDATA_SYSTEM_DISK_DETECTION=${DISK_DETECTION}" diff --git a/database/rrd.h b/database/rrd.h index f569a09d53..62dbac39e2 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -624,6 +624,10 @@ struct rrdhost_system_info { char *host_os_version; char *host_os_version_id; char *host_os_detection; + char *host_cores; + char *host_cpu_freq; + char *host_ram_total; + char *host_disk_space; char *container_os_name; char *container_os_id; char *container_os_id_like; diff --git a/database/rrdhost.c b/database/rrdhost.c index 6a11fc9020..1b5e460d02 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -573,6 +573,10 @@ void rrdhost_system_info_free(struct rrdhost_system_info *system_info) { freez(system_info->host_os_version); freez(system_info->host_os_version_id); freez(system_info->host_os_detection); + freez(system_info->host_cores); + freez(system_info->host_cpu_freq); + freez(system_info->host_ram_total); + freez(system_info->host_disk_space); freez(system_info->container_os_name); freez(system_info->container_os_id); freez(system_info->container_os_id_like); @@ -786,6 +790,22 @@ struct label *load_auto_labels() label_list = add_label_to_list(label_list, "_kernel_version", localhost->system_info->kernel_version, LABEL_SOURCE_AUTO); + if (localhost->system_info->host_cores) + label_list = + add_label_to_list(label_list, "_system_cores", localhost->system_info->host_cores, LABEL_SOURCE_AUTO); + + if (localhost->system_info->host_cpu_freq) + label_list = + add_label_to_list(label_list, "_system_cpu_freq", localhost->system_info->host_cpu_freq, LABEL_SOURCE_AUTO); + + if (localhost->system_info->host_ram_total) + label_list = + add_label_to_list(label_list, "_system_ram_total", localhost->system_info->host_ram_total, LABEL_SOURCE_AUTO); + + if (localhost->system_info->host_disk_space) + label_list = + add_label_to_list(label_list, "_system_disk_space", localhost->system_info->host_disk_space, LABEL_SOURCE_AUTO); + if (localhost->system_info->architecture) label_list = add_label_to_list(label_list, "_architecture", localhost->system_info->architecture, LABEL_SOURCE_AUTO); @@ -1308,7 +1328,7 @@ restart_after_removal: // ---------------------------------------------------------------------------- // RRDHOST - set system info from environment variables - +// system_info fields must be heap allocated or NULL int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value) { int res = 0; @@ -1366,6 +1386,22 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch freez(system_info->kernel_name); system_info->kernel_name = strdupz(value); } + else if(!strcmp(name, "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT")){ + freez(system_info->host_cores); + system_info->host_cores = strdupz(value); + } + else if(!strcmp(name, "NETDATA_SYSTEM_CPU_FREQ")){ + freez(system_info->host_cpu_freq); + system_info->host_cpu_freq = strdupz(value); + } + else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_RAM")){ + freez(system_info->host_ram_total); + system_info->host_ram_total = strdupz(value); + } + else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_DISK_SIZE")){ + freez(system_info->host_disk_space); + system_info->host_disk_space = strdupz(value); + } else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_VERSION")){ freez(system_info->kernel_version); system_info->kernel_version = strdupz(value); @@ -1390,6 +1426,16 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch freez(system_info->container_detection); system_info->container_detection = strdupz(value); } + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR")) + return res; + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL")) + return res; + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_DETECTION")) + return res; + else if (!strcmp(name, "NETDATA_SYSTEM_RAM_DETECTION")) + return res; + else if (!strcmp(name, "NETDATA_SYSTEM_DISK_DETECTION")) + return res; else { res = 1; } diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c index 095c38c25e..70b656d838 100644 --- a/libnetdata/libnetdata.c +++ b/libnetdata/libnetdata.c @@ -168,6 +168,7 @@ char *strdupz(const char *s) { return t; } +// If ptr is NULL, no operation is performed. void freez(void *ptr) { free(ptr); } diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c index 70bea8d667..899b604348 100644 --- a/web/api/web_api_v1.c +++ b/web/api/web_api_v1.c @@ -827,6 +827,10 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb) buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", (host->system_info->host_os_version) ? host->system_info->host_os_version : ""); buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : ""); buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", (host->system_info->host_os_detection) ? host->system_info->host_os_detection : ""); + buffer_sprintf(wb, "\t\"cores_total\": \"%s\",\n", (host->system_info->host_cores) ? host->system_info->host_cores : ""); + buffer_sprintf(wb, "\t\"total_disk_space\": \"%s\",\n", (host->system_info->host_disk_space) ? host->system_info->host_disk_space : ""); + buffer_sprintf(wb, "\t\"cpu_freq\": \"%s\",\n", (host->system_info->host_cpu_freq) ? host->system_info->host_cpu_freq : ""); + buffer_sprintf(wb, "\t\"ram_total\": \"%s\",\n", (host->system_info->host_ram_total) ? host->system_info->host_ram_total : ""); if (host->system_info->container_os_name) buffer_sprintf(wb, "\t\"container_os_name\": \"%s\",\n", host->system_info->container_os_name); |