Skip to content

Commit d4aaff7

Browse files
author
Spine
committed
refactor tracker report functionality
1 parent 37685bd commit d4aaff7

File tree

13 files changed

+411
-271
lines changed

13 files changed

+411
-271
lines changed

CHANGES

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
-- 2.1.3 (2024-03-09)
2+
BREAKING
3+
* API user endpoint output changed to JSON
4+
FEATURES
5+
* Peak number of simultaneous open connections is now tracked.
6+
* Maximum size of client http request is now tracked.
7+
* Number of errors (bad tracker secrets, bad client requests) is now tracked.
8+
* Show jemalloc stats in Gazelle and Grafana report endpoints.
9+
BUILD
10+
* refactor report functions to produce only report payload
11+
112
-- 2.1.2 (2024-02-17)
213
FEATURES
314
* show resource usage in Gazelle and Grafana report endpoints

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ docker run -v $(pwd)/ocelot.conf:/srv/ocelot.conf ocelot
6969
* `-c <path/to/ocelot.conf>` - Path to config file. If unspecified, the current working directory is used.
7070
* `-v` - Print queue status every time a flush is initiated.
7171

72+
You can run a test ocelot daemon alongside a production daemon by specifying
73+
a separate configuration file, and setting `readonly = true`. This will
74+
prevent the database peer tables from being reset.
75+
7276
### Signals
7377

7478
* `SIGHUP` - Reload config

ocelot.conf.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ log_path = /tmp/ocelot
3737
# the report path should be placed on a tmpfs partition in production
3838
report_path = /tmp/ocelot
3939

40+
# set to true if prevent peer data from being zeroed out on startup
41+
# useful to test a new version alongside an instance running in production
4042
readonly = false

src/events.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "response.h"
1313
#include "events.h"
1414

15+
std::mutex peak_open_mutex;
16+
1517
// Define the connection mother (first half) and connection middlemen (second half)
1618

1719
//---------- Connection mother - spawns middlemen and lets them deal with the connection
@@ -119,7 +121,13 @@ void connection_mother::handle_connect(ev::io &watcher, int events_flags) {
119121
// Spawn a new middleman
120122
if (stats.open_connections < max_middlemen) {
121123
stats.opened_connections++;
122-
stats.open_connections++;
124+
{
125+
const std::lock_guard<std::mutex> lock(peak_open_mutex);
126+
unsigned int current_open = stats.open_connections++;
127+
if (stats.peak_connections < current_open) {
128+
stats.peak_connections = current_open;
129+
}
130+
}
123131
new connection_middleman(listen_socket, work, this);
124132
}
125133
}

src/jemalloc_parse.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,9 @@ small: 247840 131452 0 129036
126126
large: 290816 815 0 808 0 971 0 815 0 2351 0
127127
total: 538656 132267 0 129844 0
128128
*/
129-
if (!(in = strstr(in, "allocated nmalloc (#/sec) ndalloc (#/sec)"))) {
129+
if (!(in = strstr(in, "(#/sec)\nsmall:"))) {
130130
return 30;
131131
}
132-
if (!(in = strstr(in, "\nsmall:"))) {
133-
return 31;
134-
}
135132

136133
if (!(in = parse_sz(in, " ", &out->small.allocated))) {
137134
return 40;

src/ocelot.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ static schedule *sched;
2626

2727
struct stats_t stats;
2828

29-
const char * version() {
30-
return "2.1.3";
31-
}
32-
3329
static void create_daemon() {
3430
pid_t pid;
3531

@@ -113,7 +109,8 @@ int main(int argc, char **argv) {
113109
conf_arg = true;
114110
conf_file_path = argv[++i];
115111
} else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
116-
std::cout << "Ocelot version " << version() << ", compiled " << __DATE__ << ' ' << __TIME__ << std::endl;
112+
// preprocessor concatenation
113+
std::cout << "Ocelot version " OCELOT_VERSION ", compiled " __DATE__ " " __TIME__ << std::endl;
117114
return 0;
118115
} else {
119116
std::cout << "Usage: " << argv[0] << " [-v] [-c configfile] [--daemonize]" << std::endl;
@@ -147,8 +144,7 @@ int main(int argc, char **argv) {
147144
// If we don't set flush on info, the file log takes a long while to actually flush
148145
combined_logger->flush_on(spdlog::level::info);
149146
combined_logger->info(
150-
std::string("Ocelot version ") + version()
151-
+ std::string(", compiled ") + __DATE__ + std::string(" ") + __TIME__
147+
"Ocelot version " OCELOT_VERSION ", compiled " __DATE__ " " __TIME__
152148
);
153149
spdlog::register_logger(combined_logger);
154150

@@ -171,17 +167,29 @@ int main(int argc, char **argv) {
171167
db->load_whitelist(whitelist);
172168

173169
stats.open_connections = 0;
170+
stats.peak_connections = 0;
174171
stats.opened_connections = 0;
175172
stats.connection_rate = 0;
176173
stats.requests = 0;
177174
stats.request_rate = 0;
178175
stats.leechers = 0;
179176
stats.seeders = 0;
177+
stats.user_queue_size = 0;
178+
stats.torrent_queue_size = 0;
179+
stats.peer_queue_size = 0;
180+
stats.snatch_queue_size = 0;
181+
stats.token_queue_size = 0;
182+
stats.max_client_request_len = 0;
180183
stats.announcements = 0;
181184
stats.succ_announcements = 0;
182185
stats.scrapes = 0;
183186
stats.bytes_read = 0;
184187
stats.bytes_written = 0;
188+
stats.auth_error_secret = 0;
189+
stats.auth_error_report = 0;
190+
stats.auth_error_announce_key = 0;
191+
stats.client_error = 0;
192+
stats.http_error = 0;
185193
stats.start_time = time(NULL);
186194

187195
// Create worker object, which handles announces and scrapes and all that jazz

src/ocelot.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
// Copyright [2017-2024] Orpheus
55

6+
#define OCELOT_VERSION_MAJOR 2
7+
#define OCELOT_VERSION_MINOR 1
8+
#define OCELOT_VERSION_BUGFIX 3
9+
#define OCELOT_VERSION_NREV 0
10+
#define OCELOT_VERSION "2.1.3"
11+
612
#include <time.h>
713

814
#include <string>
@@ -94,6 +100,7 @@ typedef std::unordered_map<std::string, std::string> params_type;
94100

95101
struct stats_t {
96102
std::atomic<uint32_t> open_connections;
103+
std::atomic<uint32_t> peak_connections;
97104
std::atomic<uint64_t> opened_connections;
98105
std::atomic<uint64_t> connection_rate;
99106
std::atomic<uint32_t> leechers;
@@ -103,13 +110,19 @@ struct stats_t {
103110
std::atomic<uint32_t> peer_queue_size;
104111
std::atomic<uint32_t> snatch_queue_size;
105112
std::atomic<uint32_t> token_queue_size;
113+
std::atomic<uint32_t> max_client_request_len;
106114
std::atomic<uint64_t> requests;
107115
std::atomic<uint64_t> request_rate;
108116
std::atomic<uint64_t> announcements;
109117
std::atomic<uint64_t> succ_announcements;
110118
std::atomic<uint64_t> scrapes;
111119
std::atomic<uint64_t> bytes_read;
112120
std::atomic<uint64_t> bytes_written;
121+
std::atomic<uint64_t> auth_error_secret;
122+
std::atomic<uint64_t> auth_error_report;
123+
std::atomic<uint64_t> auth_error_announce_key;
124+
std::atomic<uint64_t> client_error;
125+
std::atomic<uint64_t> http_error;
113126
time_t start_time;
114127
};
115128
extern struct stats_t stats;

0 commit comments

Comments
 (0)