@cryptotaxi247 / netdata-1 / commits / ee5515591

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

thiagoftsm committed Feb 7, 2020 at 20:14 UTC ee55155912c17139a3a0ab2815f15651e63e5a9c
5 files changed +65 -10
daemon/system-info.sh
+9 -9
@@ -370,13 +370,13 @@ echo "NETDATA_SYSTEM_VIRTUALIZATION=${VIRTUALIZATION}"
370 echo "NETDATA_SYSTEM_VIRT_DETECTION=${VIRT_DETECTION}"
371 echo "NETDATA_SYSTEM_CONTAINER=${CONTAINER}"
372 echo "NETDATA_SYSTEM_CONTAINER_DETECTION=${CONT_DETECTION}"
373 -echo "NETDATA_CPU_LOGICAL_CPU_COUNT=${LCPU_COUNT}"
374 -echo "NETDATA_CPU_VENDOR=${CPU_VENDOR}"
375 -echo "NETDATA_CPU_MODEL=${CPU_MODEL}"
376 -echo "NETDATA_CPU_FREQ=${CPU_FREQ}"
377 -echo "NETDATA_CPU_DETECTION=${CPU_INFO_SOURCE}"
378 -echo "NETDATA_TOTAL_RAM=${TOTAL_RAM}"
379 -echo "NETDATA_RAM_DETECTION=${RAM_DETECTION}"
380 -echo "NETDATA_TOTAL_DISK_SIZE=${DISK_SIZE}"
381 -echo "NETDATA_DISK_DETECTION=${DISK_DETECTION}"
373 +echo "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT=${LCPU_COUNT}"
374 +echo "NETDATA_SYSTEM_CPU_VENDOR=${CPU_VENDOR}"
375 +echo "NETDATA_SYSTEM_CPU_MODEL=${CPU_MODEL}"
376 +echo "NETDATA_SYSTEM_CPU_FREQ=${CPU_FREQ}"
377 +echo "NETDATA_SYSTEM_CPU_DETECTION=${CPU_INFO_SOURCE}"
378 +echo "NETDATA_SYSTEM_TOTAL_RAM=${TOTAL_RAM}"
379 +echo "NETDATA_SYSTEM_RAM_DETECTION=${RAM_DETECTION}"
380 +echo "NETDATA_SYSTEM_TOTAL_DISK_SIZE=${DISK_SIZE}"
381 +echo "NETDATA_SYSTEM_DISK_DETECTION=${DISK_DETECTION}"
382
database/rrd.h
+4
@@ -624,6 +624,10 @@ struct rrdhost_system_info {
624 char *host_os_version;
625 char *host_os_version_id;
626 char *host_os_detection;
627 + char *host_cores;
628 + char *host_cpu_freq;
629 + char *host_ram_total;
630 + char *host_disk_space;
631 char *container_os_name;
632 char *container_os_id;
633 char *container_os_id_like;
database/rrdhost.c
+47 -1
@@ -573,6 +573,10 @@ void rrdhost_system_info_free(struct rrdhost_system_info *system_info) {
573 freez(system_info->host_os_version);
574 freez(system_info->host_os_version_id);
575 freez(system_info->host_os_detection);
576 + freez(system_info->host_cores);
577 + freez(system_info->host_cpu_freq);
578 + freez(system_info->host_ram_total);
579 + freez(system_info->host_disk_space);
580 freez(system_info->container_os_name);
581 freez(system_info->container_os_id);
582 freez(system_info->container_os_id_like);
@@ -786,6 +790,22 @@ struct label *load_auto_labels()
790 label_list =
791 add_label_to_list(label_list, "_kernel_version", localhost->system_info->kernel_version, LABEL_SOURCE_AUTO);
792
793 + if (localhost->system_info->host_cores)
794 + label_list =
795 + add_label_to_list(label_list, "_system_cores", localhost->system_info->host_cores, LABEL_SOURCE_AUTO);
796 +
797 + if (localhost->system_info->host_cpu_freq)
798 + label_list =
799 + add_label_to_list(label_list, "_system_cpu_freq", localhost->system_info->host_cpu_freq, LABEL_SOURCE_AUTO);
800 +
801 + if (localhost->system_info->host_ram_total)
802 + label_list =
803 + add_label_to_list(label_list, "_system_ram_total", localhost->system_info->host_ram_total, LABEL_SOURCE_AUTO);
804 +
805 + if (localhost->system_info->host_disk_space)
806 + label_list =
807 + add_label_to_list(label_list, "_system_disk_space", localhost->system_info->host_disk_space, LABEL_SOURCE_AUTO);
808 +
809 if (localhost->system_info->architecture)
810 label_list =
811 add_label_to_list(label_list, "_architecture", localhost->system_info->architecture, LABEL_SOURCE_AUTO);
@@ -1308,7 +1328,7 @@ restart_after_removal:
1328
1329 // ----------------------------------------------------------------------------
1330 // RRDHOST - set system info from environment variables
1311 -
1331 +// system_info fields must be heap allocated or NULL
1332 int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value) {
1333 int res = 0;
1334
@@ -1366,6 +1386,22 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch
1386 freez(system_info->kernel_name);
1387 system_info->kernel_name = strdupz(value);
1388 }
1389 + else if(!strcmp(name, "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT")){
1390 + freez(system_info->host_cores);
1391 + system_info->host_cores = strdupz(value);
1392 + }
1393 + else if(!strcmp(name, "NETDATA_SYSTEM_CPU_FREQ")){
1394 + freez(system_info->host_cpu_freq);
1395 + system_info->host_cpu_freq = strdupz(value);
1396 + }
1397 + else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_RAM")){
1398 + freez(system_info->host_ram_total);
1399 + system_info->host_ram_total = strdupz(value);
1400 + }
1401 + else if(!strcmp(name, "NETDATA_SYSTEM_TOTAL_DISK_SIZE")){
1402 + freez(system_info->host_disk_space);
1403 + system_info->host_disk_space = strdupz(value);
1404 + }
1405 else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_VERSION")){
1406 freez(system_info->kernel_version);
1407 system_info->kernel_version = strdupz(value);
@@ -1390,6 +1426,16 @@ int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, ch
1426 freez(system_info->container_detection);
1427 system_info->container_detection = strdupz(value);
1428 }
1429 + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_VENDOR"))
1430 + return res;
1431 + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_MODEL"))
1432 + return res;
1433 + else if (!strcmp(name, "NETDATA_SYSTEM_CPU_DETECTION"))
1434 + return res;
1435 + else if (!strcmp(name, "NETDATA_SYSTEM_RAM_DETECTION"))
1436 + return res;
1437 + else if (!strcmp(name, "NETDATA_SYSTEM_DISK_DETECTION"))
1438 + return res;
1439 else {
1440 res = 1;
1441 }
libnetdata/libnetdata.c
+1
@@ -168,6 +168,7 @@ char *strdupz(const char *s) {
168 return t;
169 }
170
171 +// If ptr is NULL, no operation is performed.
172 void freez(void *ptr) {
173 free(ptr);
174 }
web/api/web_api_v1.c
+4
@@ -827,6 +827,10 @@ inline int web_client_api_request_v1_info_fill_buffer(RRDHOST *host, BUFFER *wb)
827 buffer_sprintf(wb, "\t\"os_version\": \"%s\",\n", (host->system_info->host_os_version) ? host->system_info->host_os_version : "");
828 buffer_sprintf(wb, "\t\"os_version_id\": \"%s\",\n", (host->system_info->host_os_version_id) ? host->system_info->host_os_version_id : "");
829 buffer_sprintf(wb, "\t\"os_detection\": \"%s\",\n", (host->system_info->host_os_detection) ? host->system_info->host_os_detection : "");
830 + buffer_sprintf(wb, "\t\"cores_total\": \"%s\",\n", (host->system_info->host_cores) ? host->system_info->host_cores : "");
831 + buffer_sprintf(wb, "\t\"total_disk_space\": \"%s\",\n", (host->system_info->host_disk_space) ? host->system_info->host_disk_space : "");
832 + buffer_sprintf(wb, "\t\"cpu_freq\": \"%s\",\n", (host->system_info->host_cpu_freq) ? host->system_info->host_cpu_freq : "");
833 + buffer_sprintf(wb, "\t\"ram_total\": \"%s\",\n", (host->system_info->host_ram_total) ? host->system_info->host_ram_total : "");
834
835 if (host->system_info->container_os_name)
836 buffer_sprintf(wb, "\t\"container_os_name\": \"%s\",\n", host->system_info->container_os_name);