Skip to content
Snippets Groups Projects
Commit c83f2420 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

modules/stats: 10-100-1000 ms latency tracking

parent 3f597527
Branches
Tags
No related merge requests found
......@@ -79,5 +79,9 @@ Built-in statistics
* ``answer.noerror`` - number of **NOERROR** answers
* ``answer.nxdomain`` - number of **NXDOMAIN** answers
* ``answer.servfail`` - number of **SERVFAIL** answers
* ``answer.10ms`` - number of answers completed in 10ms
* ``answer.100ms`` - number of answers completed in 100ms
* ``answer.1000ms`` - number of answers completed in 1000ms
* ``answer.slow`` - number of answers that took more than 1000ms
* ``query.edns`` - number of queries with EDNS
* ``query.dnssec`` - number of queries with DNSSEC DO=1
......@@ -43,7 +43,7 @@
/** @cond internal Fixed-size map of predefined metrics. */
#define CONST_METRICS(X) \
X(answer,total) X(answer,noerror) X(answer,nxdomain) X(answer,servfail) \
X(answer,cached) X(answer,slow) \
X(answer,cached) X(answer,10ms) X(answer,100ms) X(answer,1000ms) X(answer,slow) \
X(query,edns) X(query,dnssec) \
X(const,end)
......@@ -82,13 +82,6 @@ float time_diff(struct timeval *begin, struct timeval *end)
}
/** @internal Add to map counter */
static inline void stat_add(struct stat_data *data, const char *key, ssize_t incr)
{
void *val = map_get(&data->map, key);
map_set(&data->map, key, (void *)((size_t)val + incr));
}
/** @internal Add to const map counter */
static inline void stat_const_add(struct stat_data *data, enum const_metric key, ssize_t incr)
{
......@@ -161,12 +154,18 @@ static int collect(knot_layer_t *ctx)
if (last->flags & QUERY_CACHED) {
stat_const_add(data, metric_answer_cached, 1);
}
/* Count slow queries (>1000ms) */
/* Histogram of answer latency. */
struct kr_query *first = HEAD(rplan->resolved);
struct timeval now;
gettimeofday(&now, NULL);
float elapsed = time_diff(&first->timestamp, &now);
if (elapsed > 1000.0) {
if (elapsed < 10.0) {
stat_const_add(data, metric_answer_10ms, 1);
} else if (elapsed < 100.0) {
stat_const_add(data, metric_answer_100ms, 1);
} else if (elapsed < 1000.0) {
stat_const_add(data, metric_answer_1000ms, 1);
} else {
stat_const_add(data, metric_answer_slow, 1);
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment