summaryrefslogtreecommitdiff
path: root/ot_stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'ot_stats.c')
-rw-r--r--ot_stats.c146
1 files changed, 93 insertions, 53 deletions
diff --git a/ot_stats.c b/ot_stats.c
index d38355a..a2eb084 100644
--- a/ot_stats.c
+++ b/ot_stats.c
@@ -4,7 +4,6 @@
4 $id$ */ 4 $id$ */
5 5
6/* System */ 6/* System */
7#include <inttypes.h>
8#include <pthread.h> 7#include <pthread.h>
9#include <stdatomic.h> 8#include <stdatomic.h>
10#include <stdio.h> 9#include <stdio.h>
@@ -19,6 +18,7 @@
19 18
20/* Opentracker */ 19/* Opentracker */
21#include "ot_accesslist.h" 20#include "ot_accesslist.h"
21#include "ot_event.h"
22#include "ot_hex.h" 22#include "ot_hex.h"
23#include "ot_iovec.h" 23#include "ot_iovec.h"
24#include "ot_ip.h" 24#include "ot_ip.h"
@@ -117,10 +117,6 @@ union stats_network_node {
117 stats_network_node *children[STATS_NETWORK_NODE_COUNT]; 117 stats_network_node *children[STATS_NETWORK_NODE_COUNT];
118}; 118};
119 119
120#ifdef WANT_LOG_NETWORKS
121static stats_network_node *stats_network_counters_root;
122#endif
123
124static int stat_increase_network_count(stats_network_node **pnode, int depth, uintptr_t ip) { 120static int stat_increase_network_count(stats_network_node **pnode, int depth, uintptr_t ip) {
125 int foo = __LDR(ip, depth); 121 int foo = __LDR(ip, depth);
126 stats_network_node *node; 122 stats_network_node *node;
@@ -504,36 +500,6 @@ static void stats_return_numwants(char **reply, const char *reply_en
504} 500}
505#endif 501#endif
506 502
507#ifdef WANT_FULLLOG_NETWORKS
508static void stats_return_fulllog(size_t *iovec_entries, struct iovec **iovector, char *r) {
509 ot_log *loglist = g_logchain_first, *llnext;
510 char *re = r + OT_STATS_TMPSIZE;
511
512 g_logchain_first = g_logchain_last = 0;
513
514 while (loglist) {
515 if (r + (loglist->size + 64) >= re) {
516 r = iovec_next_chunk(iovec_entries, iovector, r, 32 * OT_STATS_TMPSIZE);
517 if (!r)
518 return;
519 re = r + 32 * OT_STATS_TMPSIZE;
520 }
521 char ip_readable[64];
522
523 ip_readable[ip_format(ip_readable, loglist->ip)] = 0;
524 fmt_append(&r, re, "%08ld: %s\n", loglist->time, ip_readable);
525 fmt_bytes(&r, re, loglist->data, loglist->size);
526 fmt_append(&r, re, "\n*\n\n");
527
528 llnext = loglist->next;
529 free(loglist->data);
530 free(loglist);
531 loglist = llnext;
532 }
533 iovec_trim_last(iovec_entries, iovector, r);
534}
535#endif
536
537static void stats_return_everything(char **reply, const char *reply_end) { 503static void stats_return_everything(char **reply, const char *reply_end) {
538 unsigned long long total[OT_COUNTER_COUNT]; 504 unsigned long long total[OT_COUNTER_COUNT];
539 505
@@ -546,10 +512,6 @@ static void stats_return_everything(char **reply, const char *reply_end) {
546 512
547 fmt_append(reply, reply_end, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 513 fmt_append(reply, reply_end, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
548 fmt_append(reply, reply_end, "<stats>\n"); 514 fmt_append(reply, reply_end, "<stats>\n");
549 fmt_append(reply, reply_end, " <tracker_id>%" PRIu32 "</tracker_id>\n", g_tracker_id);
550 fmt_append(reply, reply_end, " <version>\n");
551 stats_return_tracker_version(reply, reply_end);
552 fmt_append(reply, reply_end, " </version>\n");
553 fmt_append(reply, reply_end, " <uptime>%llu</uptime>\n", (unsigned long long)(time(NULL) - ot_start_time)); 515 fmt_append(reply, reply_end, " <uptime>%llu</uptime>\n", (unsigned long long)(time(NULL) - ot_start_time));
554 fmt_append(reply, reply_end, " <torrents>\n"); 516 fmt_append(reply, reply_end, " <torrents>\n");
555 fmt_append(reply, reply_end, " <count_mutex>%zd</count_mutex>\n", mutex_get_torrent_count()); 517 fmt_append(reply, reply_end, " <count_mutex>%zd</count_mutex>\n", mutex_get_torrent_count());
@@ -580,10 +542,99 @@ static void stats_return_everything(char **reply, const char *reply_end) {
580 fmt_append(reply, reply_end, "</stats>"); 542 fmt_append(reply, reply_end, "</stats>");
581} 543}
582 544
545/* The names as the Makefile spells them, so that what a binary reports maps
546 straight back onto the FEATURES lines it was built from */
547static const char *const build_features[] = {
548#ifdef WANT_V4_ONLY
549 "WANT_V4_ONLY",
550#endif
551#ifdef WANT_ACCESSLIST_BLACK
552 "WANT_ACCESSLIST_BLACK",
553#endif
554#ifdef WANT_ACCESSLIST_WHITE
555 "WANT_ACCESSLIST_WHITE",
556#endif
557#ifdef WANT_DYNAMIC_ACCESSLIST
558 "WANT_DYNAMIC_ACCESSLIST",
559#endif
560#ifdef WANT_SYNC_LIVE
561 "WANT_SYNC_LIVE",
562#endif
563#ifdef WANT_IP_FROM_QUERY_STRING
564 "WANT_IP_FROM_QUERY_STRING",
565#endif
566#ifdef WANT_IP_FROM_PROXY
567 "WANT_IP_FROM_PROXY",
568#endif
569#ifdef WANT_COMPRESSION_GZIP
570 "WANT_COMPRESSION_GZIP",
571#endif
572#ifdef WANT_COMPRESSION_GZIP_ALWAYS
573 "WANT_COMPRESSION_GZIP_ALWAYS",
574#endif
575#ifdef WANT_COMPRESSION_ZSTD
576 "WANT_COMPRESSION_ZSTD",
577#endif
578#ifdef WANT_COMPRESSION_ZSTD_ALWAYS
579 "WANT_COMPRESSION_ZSTD_ALWAYS",
580#endif
581#ifdef WANT_FULLSCRAPE
582 "WANT_FULLSCRAPE",
583#endif
584#ifdef WANT_MODEST_FULLSCRAPES
585 "WANT_MODEST_FULLSCRAPES",
586#endif
587#ifdef WANT_KEEPALIVE
588 "WANT_KEEPALIVE",
589#endif
590#ifdef WANT_RESTRICT_STATS
591 "WANT_RESTRICT_STATS",
592#endif
593#ifdef WANT_LOG_NUMWANT
594 "WANT_LOG_NUMWANT",
595#endif
596#ifdef WANT_SPOT_WOODPECKER
597 "WANT_SPOT_WOODPECKER",
598#endif
599#ifdef WANT_SYSLOGS
600 "WANT_SYSLOGS",
601#endif
602#ifdef WANT_DEV_RANDOM
603 "WANT_DEV_RANDOM",
604#endif
605#ifdef WANT_INSECURE_RANDOM_FALLBACK
606 "WANT_INSECURE_RANDOM_FALLBACK",
607#endif
608#ifdef _DEBUG
609 "_DEBUG",
610#endif
611#ifdef _DEBUG_HTTPERROR
612 "_DEBUG_HTTPERROR",
613#endif
614#ifdef _DEBUG_RANDOMTORRENTS
615 "_DEBUG_RANDOMTORRENTS",
616#endif
617 NULL};
618
619void stats_return_tracker_features(char **reply, const char *reply_end) {
620 size_t i;
621
622 fmt_append(reply, reply_end, "events: %s\n", event_mechanism());
623 fmt_append(reply, reply_end, "features:");
624 for (i = 0; build_features[i]; ++i)
625 fmt_append(reply, reply_end, " %s", build_features[i]);
626 if (!build_features[0])
627 fmt_append(reply, reply_end, " none");
628 fmt_append(reply, reply_end, "\n");
629}
630
583void stats_return_tracker_version(char **reply, const char *reply_end) { 631void stats_return_tracker_version(char **reply, const char *reply_end) {
584#define QUOTE(name) #name 632 fmt_append(reply, reply_end, "opentracker %s", OT_VERSION);
585#define SQUOTE(name) QUOTE(name) 633 if (*GIT_VERSION && strcmp(GIT_VERSION, OT_TAG))
586 fmt_append(reply, reply_end, "https://erdgeist.org/gitweb/opentracker/commit/?id=" SQUOTE(GIT_VERSION) "\n"); 634 fmt_append(reply, reply_end, " (%s)", GIT_VERSION);
635 fmt_append(reply, reply_end, "\n");
636 if (*OT_TAG)
637 fmt_append(reply, reply_end, "https://erdgeist.org/gitweb/opentracker/tag/?h=%s\n", OT_TAG);
587} 638}
588 639
589void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) { 640void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int format) {
@@ -610,9 +661,6 @@ void return_stats_for_tracker(char **reply, const char *reply_end, int mode, int
610 case TASK_STATS_HTTPERRORS: 661 case TASK_STATS_HTTPERRORS:
611 stats_httperrors_txt(reply, reply_end); 662 stats_httperrors_txt(reply, reply_end);
612 break; 663 break;
613 case TASK_STATS_VERSION:
614 stats_return_tracker_version(reply, reply_end);
615 break;
616 case TASK_STATS_RENEW: 664 case TASK_STATS_RENEW:
617 stats_return_renew_bucket(reply, reply_end); 665 stats_return_renew_bucket(reply, reply_end);
618 break; 666 break;
@@ -671,11 +719,6 @@ static void stats_make(size_t *iovec_entries, struct iovec **iovector, ot_taskty
671 stats_return_woodpeckers(&r, r_end, 128); 719 stats_return_woodpeckers(&r, r_end, 128);
672 break; 720 break;
673#endif 721#endif
674#ifdef WANT_FULLLOG_NETWORKS
675 case TASK_STATS_FULLLOG:
676 stats_return_fulllog(iovec_entries, iovector, r);
677 return;
678#endif
679 default: 722 default:
680 iovec_free(iovec_entries, iovector); 723 iovec_free(iovec_entries, iovector);
681 return; 724 return;
@@ -693,9 +736,6 @@ void stats_issue_event(struct ot_workstruct *ws, ot_status_event event, PROTO_FL
693 COUNT(OT_COUNTER_TCP_CONNECTIONS, 1); 736 COUNT(OT_COUNTER_TCP_CONNECTIONS, 1);
694 else 737 else
695 COUNT(OT_COUNTER_UDP_CONNECTIONS, 1); 738 COUNT(OT_COUNTER_UDP_CONNECTIONS, 1);
696#ifdef WANT_LOG_NETWORKS
697 stat_increase_network_count(&stats_network_counters_root, 0, event_data);
698#endif
699 break; 739 break;
700 case EVENT_ANNOUNCE: 740 case EVENT_ANNOUNCE:
701 if (proto == FLAG_TCP) 741 if (proto == FLAG_TCP)