summaryrefslogtreecommitdiffstats
path: root/daemon/analytics.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
commita836a244a3d2bdd4da1ee2641e3e957850668cea (patch)
treecb87c75b3677fab7144f868435243f864048a1e6 /daemon/analytics.c
parentAdding upstream version 1.38.1. (diff)
downloadnetdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.tar.xz
netdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.zip
Adding upstream version 1.39.0.upstream/1.39.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'daemon/analytics.c')
-rw-r--r--daemon/analytics.c102
1 files changed, 50 insertions, 52 deletions
diff --git a/daemon/analytics.c b/daemon/analytics.c
index a2f52bc8..b3c802b8 100644
--- a/daemon/analytics.c
+++ b/daemon/analytics.c
@@ -141,22 +141,14 @@ void analytics_set_data_str(char **name, char *value)
}
/*
- * Get data, used by web api v1
- */
-void analytics_get_data(char *name, BUFFER *wb)
-{
- buffer_strcat(wb, name);
-}
-
-/*
* Log hits on the allmetrics page, with prometheus parameter
*/
void analytics_log_prometheus(void)
{
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.prometheus_hits < ANALYTICS_MAX_PROMETHEUS_HITS)) {
analytics_data.prometheus_hits++;
- char b[7];
- snprintfz(b, 6, "%d", analytics_data.prometheus_hits);
+ char b[21];
+ snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
}
}
@@ -168,8 +160,8 @@ void analytics_log_shell(void)
{
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.shell_hits < ANALYTICS_MAX_SHELL_HITS)) {
analytics_data.shell_hits++;
- char b[7];
- snprintfz(b, 6, "%d", analytics_data.shell_hits);
+ char b[21];
+ snprintfz(b, 20, "%zu", analytics_data.shell_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
}
}
@@ -181,8 +173,8 @@ void analytics_log_json(void)
{
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.json_hits < ANALYTICS_MAX_JSON_HITS)) {
analytics_data.json_hits++;
- char b[7];
- snprintfz(b, 6, "%d", analytics_data.json_hits);
+ char b[21];
+ snprintfz(b, 20, "%zu", analytics_data.json_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
}
}
@@ -194,8 +186,8 @@ void analytics_log_dashboard(void)
{
if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.dashboard_hits < ANALYTICS_MAX_DASHBOARD_HITS)) {
analytics_data.dashboard_hits++;
- char b[7];
- snprintfz(b, 6, "%d", analytics_data.dashboard_hits);
+ char b[21];
+ snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
analytics_set_data(&analytics_data.netdata_dashboard_used, b);
}
}
@@ -204,18 +196,18 @@ void analytics_log_dashboard(void)
* Called when setting the oom score
*/
void analytics_report_oom_score(long long int score){
- char b[7];
- snprintfz(b, 6, "%d", (int)score);
+ char b[21];
+ snprintfz(b, 20, "%lld", score);
analytics_set_data(&analytics_data.netdata_config_oom_score, b);
}
void analytics_mirrored_hosts(void)
{
RRDHOST *host;
- int count = 0;
- int reachable = 0;
- int unreachable = 0;
- char b[11];
+ size_t count = 0;
+ size_t reachable = 0;
+ size_t unreachable = 0;
+ char b[21];
rrd_rdlock();
rrdhost_foreach_read(host)
@@ -229,11 +221,11 @@ void analytics_mirrored_hosts(void)
}
rrd_unlock();
- snprintfz(b, 10, "%d", count);
+ snprintfz(b, 20, "%zu", count);
analytics_set_data(&analytics_data.netdata_mirrored_host_count, b);
- snprintfz(b, 10, "%d", reachable);
+ snprintfz(b, 20, "%zu", reachable);
analytics_set_data(&analytics_data.netdata_mirrored_hosts_reachable, b);
- snprintfz(b, 10, "%d", unreachable);
+ snprintfz(b, 20, "%zu", unreachable);
analytics_set_data(&analytics_data.netdata_mirrored_hosts_unreachable, b);
}
@@ -303,8 +295,8 @@ void analytics_collectors(void)
analytics_set_data(&analytics_data.netdata_collectors, (char *)buffer_tostring(ap.both));
{
- char b[7];
- snprintfz(b, 6, "%d", ap.c);
+ char b[21];
+ snprintfz(b, 20, "%d", ap.c);
analytics_set_data(&analytics_data.netdata_collectors_count, b);
}
@@ -362,16 +354,16 @@ void analytics_alarms_notifications(void)
buffer_free(b);
}
-void analytics_get_install_type(void)
+static void analytics_get_install_type(struct rrdhost_system_info *system_info)
{
- if (localhost->system_info->install_type == NULL) {
+ if (system_info->install_type == NULL) {
analytics_set_data_str(&analytics_data.netdata_install_type, "unknown");
} else {
- analytics_set_data_str(&analytics_data.netdata_install_type, localhost->system_info->install_type);
+ analytics_set_data_str(&analytics_data.netdata_install_type, system_info->install_type);
}
- if (localhost->system_info->prebuilt_dist != NULL) {
- analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, localhost->system_info->prebuilt_dist);
+ if (system_info->prebuilt_dist != NULL) {
+ analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, system_info->prebuilt_dist);
}
}
@@ -396,15 +388,16 @@ void analytics_https(void)
void analytics_charts(void)
{
RRDSET *st;
- int c = 0;
+ size_t c = 0;
rrdset_foreach_read(st, localhost)
if(rrdset_is_available_for_viewers(st)) c++;
rrdset_foreach_done(st);
+ analytics_data.charts_count = c;
{
- char b[7];
- snprintfz(b, 6, "%d", c);
+ char b[21];
+ snprintfz(b, 20, "%zu", c);
analytics_set_data(&analytics_data.netdata_charts_count, b);
}
}
@@ -412,7 +405,7 @@ void analytics_charts(void)
void analytics_metrics(void)
{
RRDSET *st;
- long int dimensions = 0;
+ size_t dimensions = 0;
rrdset_foreach_read(st, localhost) {
if (rrdset_is_available_for_viewers(st)) {
RRDDIM *rd;
@@ -426,17 +419,18 @@ void analytics_metrics(void)
}
rrdset_foreach_done(st);
+ analytics_data.metrics_count = dimensions;
{
- char b[7];
- snprintfz(b, 6, "%ld", dimensions);
+ char b[21];
+ snprintfz(b, 20, "%zu", dimensions);
analytics_set_data(&analytics_data.netdata_metrics_count, b);
}
}
void analytics_alarms(void)
{
- int alarm_warn = 0, alarm_crit = 0, alarm_normal = 0;
- char b[10];
+ size_t alarm_warn = 0, alarm_crit = 0, alarm_normal = 0;
+ char b[21];
RRDCALC *rc;
foreach_rrdcalc_in_rrdhost_read(localhost, rc) {
if (unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
@@ -455,11 +449,11 @@ void analytics_alarms(void)
}
foreach_rrdcalc_in_rrdhost_done(rc);
- snprintfz(b, 9, "%d", alarm_normal);
+ snprintfz(b, 20, "%zu", alarm_normal);
analytics_set_data(&analytics_data.netdata_alarms_normal, b);
- snprintfz(b, 9, "%d", alarm_warn);
+ snprintfz(b, 20, "%zu", alarm_warn);
analytics_set_data(&analytics_data.netdata_alarms_warning, b);
- snprintfz(b, 9, "%d", alarm_crit);
+ snprintfz(b, 20, "%zu", alarm_crit);
analytics_set_data(&analytics_data.netdata_alarms_critical, b);
}
@@ -476,7 +470,8 @@ void analytics_misc(void)
analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "");
#endif
- analytics_set_data(&analytics_data.netdata_config_exporting_enabled, appconfig_get_boolean(&exporting_config, CONFIG_SECTION_EXPORTING, "enabled", CONFIG_BOOLEAN_NO) ? "true" : "false");
+ analytics_data.exporting_enabled = appconfig_get_boolean(&exporting_config, CONFIG_SECTION_EXPORTING, "enabled", CONFIG_BOOLEAN_NO);
+ analytics_set_data(&analytics_data.netdata_config_exporting_enabled, analytics_data.exporting_enabled ? "true" : "false");
analytics_set_data(&analytics_data.netdata_config_is_private_registry, "false");
analytics_set_data(&analytics_data.netdata_config_use_private_registry, "false");
@@ -539,20 +534,20 @@ void analytics_gather_mutable_meta_data(void)
freez(claim_id);
{
- char b[7];
- snprintfz(b, 6, "%d", analytics_data.prometheus_hits);
+ char b[21];
+ snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
- snprintfz(b, 6, "%d", analytics_data.shell_hits);
+ snprintfz(b, 20, "%zu", analytics_data.shell_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
- snprintfz(b, 6, "%d", analytics_data.json_hits);
+ snprintfz(b, 20, "%zu", analytics_data.json_hits);
analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
- snprintfz(b, 6, "%d", analytics_data.dashboard_hits);
+ snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
analytics_set_data(&analytics_data.netdata_dashboard_used, b);
- snprintfz(b, 6, "%zu", rrdhost_hosts_available());
+ snprintfz(b, 20, "%zu", rrdhost_hosts_available());
analytics_set_data(&analytics_data.netdata_config_hosts_available, b);
}
}
@@ -637,7 +632,7 @@ static const char *verify_required_directory(const char *dir)
* This is called after the rrdinit
* These values will be sent on the START event
*/
-void set_late_global_environment()
+void set_late_global_environment(struct rrdhost_system_info *system_info)
{
analytics_set_data(&analytics_data.netdata_config_stream_enabled, default_rrdpush_enabled ? "true" : "false");
analytics_set_data_str(&analytics_data.netdata_config_memory_mode, (char *)rrd_memory_mode_name(default_rrd_memory_mode));
@@ -681,7 +676,7 @@ void set_late_global_environment()
buffer_free(bi);
}
- analytics_get_install_type();
+ analytics_get_install_type(system_info);
}
void get_system_timezone(void)
@@ -894,6 +889,9 @@ void set_global_environment()
analytics_data.shell_hits = 0;
analytics_data.json_hits = 0;
analytics_data.dashboard_hits = 0;
+ analytics_data.charts_count = 0;
+ analytics_data.metrics_count = 0;
+ analytics_data.exporting_enabled = false;
char *default_port = appconfig_get(&netdata_config, CONFIG_SECTION_WEB, "default port", NULL);
int clean = 0;