Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

adds ability to control what values (if any) for avg_rt will be sent if ... #213

Merged
merged 1 commit into from

2 participants

@prymitive
Collaborator

...no requests were done, fixes #212

I did basic testing and it looks ok, please review

Usage:

--carbon-idle-avg none - don't push any avg_rt value if no requests were made
--carbon-idle-avg last - use last computed avg_rt value (default)
--carbon-idle-avg zero - push 0 if no requests were made

@unbit
Owner

i am not sure to understamd the problem here, it is better to not send avg when it is zero ?

@prymitive
Collaborator

if you want to accurately average some metrics than you want only those metrics, if there are no requests than sending zero will move average values toward zero.

Example: during 10 minutes you only have 2 requests serviced in 1 second each, so we should have 1s (1+1/2) avg_rt average, but sending zeros will gives us 0.2s (1+1/10).

Number of samples counts in average computation, so we should not send any metrics for time periods with no requests

@unbit unbit merged commit 9b8646a into from
@prymitive prymitive deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. @prymitive

    adds ability to control what values (if any) for avg_rt will be sent …

    prymitive authored
    …if no requests were done, fixes #212
This page is out of date. Refresh to see the latest.
Showing with 52 additions and 4 deletions.
  1. +52 −4 plugins/carbon/carbon.c
View
56 plugins/carbon/carbon.c
@@ -35,6 +35,10 @@ struct uwsgi_carbon {
char *hostname_dot_replacement;
char *hostname;
int resolve_hostname;
+ char *idle_avg;
+ int push_avg;
+ int zero_avg;
+ uint64_t last_requests;
struct uwsgi_stats_pusher *pusher;
} u_carbon;
@@ -50,6 +54,7 @@ static struct uwsgi_option carbon_options[] = {
{"carbon-hostname-dots", required_argument, 0, "set char to use as a replacement for dots in hostname (dots are not replaced by default)", uwsgi_opt_set_str, &u_carbon.hostname_dot_replacement, 0},
{"carbon-name-resolve", no_argument, 0, "allow using hostname as carbon server address (default disabled)", uwsgi_opt_true, &u_carbon.resolve_hostname, 0},
{"carbon-resolve-names", no_argument, 0, "allow using hostname as carbon server address (default disabled)", uwsgi_opt_true, &u_carbon.resolve_hostname, 0},
+ {"carbon-idle-avg", required_argument, 0, "average values source during idle period (no requests), can be \"last\", \"zero\", \"none\" (default is last)", uwsgi_opt_set_str, &u_carbon.idle_avg, 0},
{0, 0, 0, 0, 0, 0, 0},
};
@@ -121,6 +126,22 @@ static void carbon_post_init() {
}
}
+ u_carbon.push_avg = 1;
+ u_carbon.zero_avg = 0;
+ if (!u_carbon.idle_avg) {
+ u_carbon.idle_avg = "last";
+ }
+ else if (!strcmp(u_carbon.idle_avg, "zero")) {
+ u_carbon.zero_avg = 1;
+ }
+ else if (!strcmp(u_carbon.idle_avg, "none")) {
+ u_carbon.push_avg = 0;
+ }
+ else if (strcmp(u_carbon.idle_avg, "last")) {
+ uwsgi_log("[carbon] invalid value for carbon-idle-avg: \"%s\"\n", u_carbon.idle_avg);
+ exit(1);
+ }
+
if (!u_carbon.last_busyness_values) {
u_carbon.last_busyness_values = uwsgi_calloc(sizeof(unsigned long long) * uwsgi.numproc);
}
@@ -237,6 +258,8 @@ static void carbon_push_stats(int retry_cycle, time_t now) {
unsigned long long worker_busyness = 0;
unsigned long long total_harakiri = 0;
+ int do_avg_push;
+
wok = carbon_write(fd, "%s%s.%s.requests %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) uwsgi.workers[0].requests, (unsigned long long) now);
if (!wok) goto clear;
@@ -287,8 +310,19 @@ static void carbon_push_stats(int retry_cycle, time_t now) {
if (!wok) goto clear;
}
- wok = carbon_write(fd, "%s%s.%s.worker%d.avg_rt %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) avg_rt, (unsigned long long) now);
- if (!wok) goto clear;
+ do_avg_push = 1;
+ if (!u_carbon.last_requests || u_carbon.last_requests == uwsgi.workers[0].requests) {
+ if (!u_carbon.push_avg) {
+ do_avg_push = 0;
+ }
+ else if (u_carbon.zero_avg) {
+ avg_rt = 0;
+ }
+ }
+ if (do_avg_push) {
+ wok = carbon_write(fd, "%s%s.%s.worker%d.avg_rt %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) avg_rt, (unsigned long long) now);
+ if (!wok) goto clear;
+ }
wok = carbon_write(fd, "%s%s.%s.worker%d.tx %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) uwsgi.workers[i].tx, (unsigned long long) now);
if (!wok) goto clear;
@@ -309,8 +343,20 @@ static void carbon_push_stats(int retry_cycle, time_t now) {
if (!wok) goto clear;
}
- wok = carbon_write(fd, "%s%s.%s.avg_rt %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) (active_workers ? total_avg_rt / active_workers : 0), (unsigned long long) now);
- if (!wok) goto clear;
+ do_avg_push = 1;
+ uint64_t c_total_avg_rt = (active_workers ? total_avg_rt / active_workers : 0);
+ if (!u_carbon.last_requests || u_carbon.last_requests == uwsgi.workers[0].requests) {
+ if (!u_carbon.push_avg) {
+ do_avg_push = 0;
+ }
+ else if (u_carbon.zero_avg) {
+ c_total_avg_rt = 0;
+ }
+ }
+ if (do_avg_push) {
+ wok = carbon_write(fd, "%s%s.%s.avg_rt %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) c_total_avg_rt, (unsigned long long) now);
+ if (!wok) goto clear;
+ }
wok = carbon_write(fd, "%s%s.%s.tx %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) total_tx, (unsigned long long) now);
if (!wok) goto clear;
@@ -338,6 +384,8 @@ static void carbon_push_stats(int retry_cycle, time_t now) {
usl->healthy = 1;
usl->errors = 0;
+ u_carbon.last_requests = uwsgi.workers[0].requests;
+
clear:
close(fd);
nxt:
Something went wrong with that request. Please try again.