mirror of
https://github.com/netdata/netdata.git
synced 2025-05-02 16:30:12 +00:00
Add install type info to -W buildinfo
output. (#12010)
* Add install type info to `-W buildinfo` ouptut. By reading it from the `.install-type` file and presenting it properly. * Move get_value_from_key from daemon/analytics to libnetdata. It will be used also in the buildinfo code. * Restructure install type handling for buildinfo. * Restructure to make code more reusable. Allowing for deduplication and also enabling other potential callers. * Fix incorrect variable name in analytics changes.
This commit is contained in:
parent
2b313d1ff2
commit
f70a97206e
3 changed files with 87 additions and 38 deletions
|
@ -1,6 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "buildinfo.h"
|
||||||
|
|
||||||
struct analytics_data analytics_data;
|
struct analytics_data analytics_data;
|
||||||
extern void analytics_exporting_connectors (BUFFER *b);
|
extern void analytics_exporting_connectors (BUFFER *b);
|
||||||
|
@ -359,47 +360,23 @@ void analytics_alarms_notifications(void)
|
||||||
buffer_free(b);
|
buffer_free(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_value_from_key(char *buffer, char *key)
|
|
||||||
{
|
|
||||||
char *s = NULL, *t = NULL;
|
|
||||||
s = t = buffer + strlen(key) + 2;
|
|
||||||
if (s) {
|
|
||||||
while (*s == '\'')
|
|
||||||
s++;
|
|
||||||
while (*++t != '\0');
|
|
||||||
while (--t > s && *t == '\'')
|
|
||||||
*t = '\0';
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Checks for the existence of .install_type file and reads it
|
|
||||||
*/
|
|
||||||
void analytics_get_install_type(void)
|
void analytics_get_install_type(void)
|
||||||
{
|
{
|
||||||
char *install_type_filename;
|
struct install_type_info t = get_install_type();
|
||||||
analytics_set_data_str(&analytics_data.netdata_install_type, "");
|
|
||||||
analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, "");
|
|
||||||
|
|
||||||
int install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
|
if (t.install_type == NULL) {
|
||||||
install_type_filename = mallocz(sizeof(char) * install_type_filename_len);
|
analytics_set_data_str(&analytics_data.netdata_install_type, "unknown");
|
||||||
snprintfz(install_type_filename, install_type_filename_len - 1, "%s/%s", netdata_configured_user_config_dir, ".install-type");
|
} else {
|
||||||
|
analytics_set_data_str(&analytics_data.netdata_install_type, t.install_type);
|
||||||
FILE *fp = fopen(install_type_filename, "r");
|
|
||||||
if (fp) {
|
|
||||||
char *s, buf[256 + 1];
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
while ((s = fgets_trim_len(buf, 256, fp, &len))) {
|
|
||||||
if (!strncmp(buf, "INSTALL_TYPE='", 14))
|
|
||||||
analytics_set_data_str(&analytics_data.netdata_install_type, (char *)get_value_from_key(buf, "INSTALL_TYPE"));
|
|
||||||
else if (!strncmp(buf, "PREBUILT_DISTRO='", 17))
|
|
||||||
analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, (char *)get_value_from_key(buf, "PREBUILT_DISTRO"));
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
freez(install_type_filename);
|
|
||||||
|
if (t.prebuilt_distro != NULL) {
|
||||||
|
analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, t.prebuilt_distro);
|
||||||
|
}
|
||||||
|
|
||||||
|
freez(t.prebuilt_arch);
|
||||||
|
freez(t.prebuilt_distro);
|
||||||
|
freez(t.install_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "./config.h"
|
#include "./config.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "buildinfo.h"
|
||||||
|
|
||||||
// Optional features
|
// Optional features
|
||||||
|
|
||||||
|
@ -207,9 +208,71 @@
|
||||||
|
|
||||||
#define FEAT_YES_NO(x) ((x) ? "YES" : "NO")
|
#define FEAT_YES_NO(x) ((x) ? "YES" : "NO")
|
||||||
|
|
||||||
|
|
||||||
|
char *get_value_from_key(char *buffer, char *key) {
|
||||||
|
char *s = NULL, *t = NULL;
|
||||||
|
s = t = buffer + strlen(key) + 2;
|
||||||
|
if (s) {
|
||||||
|
while (*s == '\'')
|
||||||
|
s++;
|
||||||
|
while (*++t != '\0');
|
||||||
|
while (--t > s && *t == '\'')
|
||||||
|
*t = '\0';
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct install_type_info get_install_type() {
|
||||||
|
char *install_type_filename;
|
||||||
|
struct install_type_info ret = {.install_type = NULL, .prebuilt_arch = NULL, .prebuilt_distro = NULL};
|
||||||
|
|
||||||
|
int install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
|
||||||
|
install_type_filename = mallocz(sizeof(char) * install_type_filename_len);
|
||||||
|
snprintfz(install_type_filename, install_type_filename_len - 1, "%s/%s", netdata_configured_user_config_dir, ".install-type");
|
||||||
|
|
||||||
|
FILE *fp = fopen(install_type_filename, "r");
|
||||||
|
if (fp) {
|
||||||
|
char *s, buf[256 + 1];
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
while ((s = fgets_trim_len(buf, 256, fp, &len))) {
|
||||||
|
if (!strncmp(buf, "INSTALL_TYPE='", 14))
|
||||||
|
ret.install_type = strdupz((char *)get_value_from_key(buf, "INSTALL_TYPE"));
|
||||||
|
else if (!strncmp(buf, "PREBUILT_ARCH='", 15))
|
||||||
|
ret.prebuilt_arch = strdupz((char *)get_value_from_key(buf, "PREBUILT_ARCH"));
|
||||||
|
else if (!strncmp(buf, "PREBUILT_DISTRO='", 17))
|
||||||
|
ret.prebuilt_distro = strdupz((char *)get_value_from_key(buf, "PREBUILT_DISTRO"));
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
freez(install_type_filename);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void print_build_info(void) {
|
void print_build_info(void) {
|
||||||
|
struct install_type_info t = get_install_type();
|
||||||
|
|
||||||
printf("Configure options: %s\n", CONFIGURE_COMMAND);
|
printf("Configure options: %s\n", CONFIGURE_COMMAND);
|
||||||
|
|
||||||
|
if (t.install_type == NULL) {
|
||||||
|
printf("Install type: unknown\n");
|
||||||
|
} else {
|
||||||
|
printf("Install type: %s\n", t.install_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.prebuilt_arch != NULL) {
|
||||||
|
printf(" Binary architecture: %s\n", t.prebuilt_arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.prebuilt_distro != NULL) {
|
||||||
|
printf(" Packaging distro: %s\n", t.prebuilt_distro);
|
||||||
|
}
|
||||||
|
|
||||||
|
freez(t.install_type);
|
||||||
|
freez(t.prebuilt_arch);
|
||||||
|
freez(t.prebuilt_distro);
|
||||||
|
|
||||||
printf("Features:\n");
|
printf("Features:\n");
|
||||||
printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
|
printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
|
||||||
printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
|
printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
|
||||||
|
@ -250,7 +313,6 @@ void print_build_info(void) {
|
||||||
printf(" Prometheus Remote Write: %s\n", FEAT_YES_NO(FEAT_REMOTE_WRITE));
|
printf(" Prometheus Remote Write: %s\n", FEAT_YES_NO(FEAT_REMOTE_WRITE));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define FEAT_JSON_BOOL(x) ((x) ? "true" : "false")
|
#define FEAT_JSON_BOOL(x) ((x) ? "true" : "false")
|
||||||
// This intentionally does not use JSON-C so it works even if JSON-C is not present
|
// This intentionally does not use JSON-C so it works even if JSON-C is not present
|
||||||
// This is used for anonymous statistics reporting, so it intentionally
|
// This is used for anonymous statistics reporting, so it intentionally
|
||||||
|
|
|
@ -3,8 +3,18 @@
|
||||||
#ifndef NETDATA_BUILDINFO_H
|
#ifndef NETDATA_BUILDINFO_H
|
||||||
#define NETDATA_BUILDINFO_H 1
|
#define NETDATA_BUILDINFO_H 1
|
||||||
|
|
||||||
|
struct install_type_info {
|
||||||
|
char *install_type;
|
||||||
|
char *prebuilt_arch;
|
||||||
|
char *prebuilt_distro;
|
||||||
|
};
|
||||||
|
|
||||||
extern void print_build_info(void);
|
extern void print_build_info(void);
|
||||||
|
|
||||||
extern void print_build_info_json(void);
|
extern void print_build_info_json(void);
|
||||||
|
|
||||||
|
extern char *get_value_from_key(char *buffer, char *key);
|
||||||
|
|
||||||
|
extern struct install_type_info get_install_type();
|
||||||
|
|
||||||
#endif // NETDATA_BUILDINFO_H
|
#endif // NETDATA_BUILDINFO_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue