Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gauge for sessions count #291

Merged
merged 5 commits into from
May 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,16 @@ void session_config_free(void) {
free(client_certificate);
}

// Keep a session count for stats gauge
static void update_session_count(bool add) {
static int current_session_count = 0;

if (add) __sync_fetch_and_add(&current_session_count, 1);
else __sync_fetch_and_sub(&current_session_count, 1);
log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "update_session_count: %d", current_session_count);
// We atomically update current_session_count, but don't atomically get its value for the stat.
// That should be ok, it will always at least be a valid value for some point in recent time.
stats_timer_cluster("sessions", current_session_count);
}

static void print_errors(const int iter, const char *type_str, const char *fcn_name,
Expand Down Expand Up @@ -337,7 +341,6 @@ static void session_cleanup(void *s) {

if (!session) return;

stats_counter_cluster("sessions", -1);
stats_timer_cluster("session-duration", time(NULL) - session_start_time);
log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "Destroying cURL handle");

Expand Down Expand Up @@ -1131,7 +1134,6 @@ static CURL *update_session(bool tmp_session) {
// We do this when the thread is initialized. We want the hashtable to survive reinitialization of the handle,
// since the hashtable keeps track of the health status of connections causing the reinitialization

stats_counter_cluster("sessions", 1);
log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "Opening cURL session");

// if tmp_session, we need to get a new session for this request; otherwise see if we already have a session
Expand Down