stats.c File Reference

This file describes the data structure used to collect runtime performance numbers. More...

#include "config.h"
#include <sys/time.h>
#include <sys/types.h>
#include "daemon/stats.h"
#include "daemon/worker.h"
#include "daemon/daemon.h"
#include "services/mesh.h"
#include "services/outside_network.h"
#include "services/listen_dnsport.h"
#include "util/config_file.h"
#include "util/tube.h"
#include "util/timehist.h"
#include "util/net_help.h"
#include "validator/validator.h"
#include "iterator/iterator.h"
#include "sldns/sbuffer.h"
#include "services/cache/rrset.h"
#include "services/cache/infra.h"
#include "services/authzone.h"
#include "validator/val_kcache.h"
#include "validator/val_neg.h"

Macros

#define STATS_THREAD_WAIT   60000
 How long to wait for threads to transmit statistics, in msec.
 

Functions

static void stats_timeval_add (long long *d_sec, long long *d_usec, long long add_sec, long long add_usec)
 add timers and the values do not overflow or become negative
 
void server_stats_init (struct ub_server_stats *stats, struct config_file *cfg)
 Initialize server stats to 0. More...
 
void server_stats_querymiss (struct ub_server_stats *stats, struct worker *worker)
 add query if it missed the cache
 
void server_stats_prefetch (struct ub_server_stats *stats, struct worker *worker)
 add query if was cached and also resulted in a prefetch
 
void server_stats_log (struct ub_server_stats *stats, struct worker *worker, int threadnum)
 display the stats to the log
 
static void set_neg_cache_stats (struct worker *worker, struct ub_server_stats *svr, int reset)
 Set the neg cache stats.
 
static size_t get_rrset_bogus (struct worker *worker, int reset)
 get rrsets bogus number from validator
 
static size_t get_queries_ratelimit (struct worker *worker, int reset)
 get number of ratelimited queries from iterator
 
void server_stats_compile (struct worker *worker, struct ub_stats_info *s, int reset)
 Compile stats into structure for this thread worker. More...
 
void server_stats_obtain (struct worker *worker, struct worker *who, struct ub_stats_info *s, int reset)
 Obtain the stats info for a given thread. More...
 
void server_stats_reply (struct worker *worker, int reset)
 Send stats over comm tube in reply to query cmd. More...
 
void server_stats_add (struct ub_stats_info *total, struct ub_stats_info *a)
 Addup stat blocks. More...
 
void server_stats_insquery (struct ub_server_stats *stats, struct comm_point *c, uint16_t qtype, uint16_t qclass, struct edns_data *edns, struct comm_reply *repinfo)
 Add stats for this query. More...
 
void server_stats_insrcode (struct ub_server_stats *stats, sldns_buffer *buf)
 Add rcode for this query. More...
 
void server_stats_downstream_cookie (struct ub_server_stats *stats, struct edns_data *edns)
 Add DNS Cookie stats for this query. More...
 

Detailed Description

This file describes the data structure used to collect runtime performance numbers.

These 'statistics' may be of interest to the operator.

Function Documentation

◆ server_stats_init()

void server_stats_init ( struct ub_server_stats stats,
struct config_file cfg 
)

Initialize server stats to 0.

Parameters
statswhat to init (this is alloced by the caller).
cfgwith extended statistics option.

References ub_server_stats::extended, and config_file::stat_extended.

Referenced by worker_stats_clear().

◆ server_stats_compile()

void server_stats_compile ( struct worker worker,
struct ub_stats_info s,
int  reset 
)

Compile stats into structure for this thread worker.

Also clears the statistics counters (if that is set by config file).

Parameters
workerthe worker to compile stats for, also the executing worker.
sstats block.
resetif true, depending on config stats are reset. if false, statistics are not reset.

References mesh_area::all, ub_server_stats::ans_bogus, mesh_area::ans_bogus, ub_server_stats::ans_expired, mesh_area::ans_expired, mesh_area::ans_nodata, ub_server_stats::ans_rcode, mesh_area::ans_rcode, ub_server_stats::ans_rcode_nodata, ub_server_stats::ans_secure, mesh_area::ans_secure, worker::back, rbtree_type::count, worker::env, get_queries_ratelimit(), get_rrset_bogus(), get_slabhash_stats(), ub_server_stats::hist, mesh_area::histogram, ub_server_stats::infra_cache_count, module_env::mesh, ub_stats_info::mesh_dropped, ub_stats_info::mesh_jostled, ub_stats_info::mesh_num_reply_states, ub_stats_info::mesh_num_states, ub_stats_info::mesh_replies_sent, ub_stats_info::mesh_replies_sum_wait_sec, ub_stats_info::mesh_time_median, module_env::msg_cache, ub_server_stats::msg_cache_count, ub_server_stats::msg_cache_max_collisions, NUM_BUCKETS_HIST, mesh_area::num_reply_states, outside_network::num_tcp_outgoing, outside_network::num_udp_outgoing, ub_server_stats::qtcp_outgoing, ub_server_stats::qudp_outgoing, ub_server_stats::queries_ratelimited, mesh_area::replies_sent, mesh_area::replies_sum_wait, ub_server_stats::rpz_action, mesh_area::rpz_action, ub_server_stats::rrset_bogus, module_env::rrset_cache, ub_server_stats::rrset_cache_count, ub_server_stats::rrset_cache_max_collisions, worker::stats, mesh_area::stats_dropped, mesh_area::stats_jostled, ub_stats_info::svr, rrset_cache::table, timehist_export(), timehist_quartile(), UB_STATS_RCODE_NUM, UB_STATS_RPZ_ACTION_NUM, ub_server_stats::unwanted_replies, and outside_network::unwanted_replies.

Referenced by server_stats_obtain(), and server_stats_reply().

◆ server_stats_obtain()

void server_stats_obtain ( struct worker worker,
struct worker who,
struct ub_stats_info s,
int  reset 
)

Obtain the stats info for a given thread.

Uses pipe to communicate.

Parameters
workerthe worker that is executing (the first worker).
whoon who to get the statistics info.
sthe stats block to fill in.
resetif stats can be reset.

References worker::cmd, server_stats_compile(), STATS_THREAD_WAIT, worker::thr_id, worker::thread_num, tube_read_msg(), tube_wait_timeout(), VERB_ALGO, VERB_OPS, verbose(), verbosity, worker_cmd_stats, worker_cmd_stats_noreset, and worker_send_cmd().

Referenced by do_stats().

◆ server_stats_reply()

void server_stats_reply ( struct worker worker,
int  reset 
)

Send stats over comm tube in reply to query cmd.

Parameters
workerthis worker.
resetif true, depending on config stats are reset. if false, statistics are not reset.

References worker::cmd, worker::daemon, server_stats_compile(), tube_write_msg(), VERB_ALGO, verbose(), and daemon::workers.

◆ server_stats_add()

void server_stats_add ( struct ub_stats_info total,
struct ub_stats_info a 
)

Addup stat blocks.

Parameters
totalsum of the two entries.
ato add to it.

References ub_server_stats::ans_bogus, ub_server_stats::ans_expired, ub_server_stats::ans_rcode, ub_server_stats::ans_rcode_nodata, ub_server_stats::ans_secure, ub_server_stats::extended, ub_server_stats::hist, ub_server_stats::max_query_list_size, ub_server_stats::max_query_time_us, ub_stats_info::mesh_dropped, ub_stats_info::mesh_jostled, ub_stats_info::mesh_num_reply_states, ub_stats_info::mesh_num_states, ub_stats_info::mesh_replies_sent, ub_stats_info::mesh_replies_sum_wait_sec, ub_stats_info::mesh_time_median, NUM_BUCKETS_HIST, ub_server_stats::num_queries, ub_server_stats::num_queries_cookie_client, ub_server_stats::num_queries_cookie_invalid, ub_server_stats::num_queries_cookie_valid, ub_server_stats::num_queries_ip_ratelimited, ub_server_stats::num_queries_missed_cache, ub_server_stats::num_queries_prefetch, ub_server_stats::num_queries_timed_out, ub_server_stats::num_query_cachedb, ub_server_stats::num_query_dnscrypt_cert, ub_server_stats::num_query_dnscrypt_cleartext, ub_server_stats::num_query_dnscrypt_crypted, ub_server_stats::num_query_dnscrypt_crypted_malformed, ub_server_stats::qbit_AA, ub_server_stats::qbit_AD, ub_server_stats::qbit_CD, ub_server_stats::qbit_QR, ub_server_stats::qbit_RA, ub_server_stats::qbit_RD, ub_server_stats::qbit_TC, ub_server_stats::qbit_Z, ub_server_stats::qclass, ub_server_stats::qclass_big, ub_server_stats::qEDNS, ub_server_stats::qEDNS_DO, ub_server_stats::qhttps, ub_server_stats::qipv6, ub_server_stats::qopcode, ub_server_stats::qquic, ub_server_stats::qtcp, ub_server_stats::qtcp_outgoing, ub_server_stats::qtls, ub_server_stats::qtls_resume, ub_server_stats::qtype, ub_server_stats::qtype_big, ub_server_stats::qudp_outgoing, ub_server_stats::rpz_action, stats_timeval_add(), ub_server_stats::sum_query_list_size, ub_stats_info::svr, ub_server_stats::tcp_accept_usage, UB_STATS_OPCODE_NUM, UB_STATS_QCLASS_NUM, UB_STATS_QTYPE_NUM, UB_STATS_RCODE_NUM, UB_STATS_RPZ_ACTION_NUM, ub_server_stats::unwanted_queries, and ub_server_stats::unwanted_replies.

Referenced by do_stats().

◆ server_stats_insquery()

void server_stats_insquery ( struct ub_server_stats stats,
struct comm_point c,
uint16_t  qtype,
uint16_t  qclass,
struct edns_data edns,
struct comm_reply repinfo 
)

Add stats for this query.

Parameters
statsthe stats
ccommpoint with type and buffer.
qtypequery type
qclassquery class
ednsedns record
repinforeply info with remote address

References comm_point::buffer, ub_server_stats::qclass, ub_server_stats::qclass_big, ub_server_stats::qopcode, ub_server_stats::qtype, ub_server_stats::qtype_big, sldns_buffer_read_u16_at(), UB_STATS_QCLASS_NUM, and UB_STATS_QTYPE_NUM.

◆ server_stats_insrcode()

void server_stats_insrcode ( struct ub_server_stats stats,
struct sldns_buffer buf 
)

Add rcode for this query.

Parameters
statsthe stats
bufbuffer with rcode. If buffer is length0: not counted.

References ub_server_stats::extended, and sldns_buffer_limit().

◆ server_stats_downstream_cookie()

void server_stats_downstream_cookie ( struct ub_server_stats stats,
struct edns_data edns 
)