Skip to content

Commit

Permalink
refactor tracker report functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine committed Mar 10, 2024
1 parent 37685bd commit d4aaff7
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 271 deletions.
11 changes: 11 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
-- 2.1.3 (2024-03-09)
BREAKING
* API user endpoint output changed to JSON
FEATURES
* Peak number of simultaneous open connections is now tracked.
* Maximum size of client http request is now tracked.
* Number of errors (bad tracker secrets, bad client requests) is now tracked.
* Show jemalloc stats in Gazelle and Grafana report endpoints.
BUILD
* refactor report functions to produce only report payload

-- 2.1.2 (2024-02-17)
FEATURES
* show resource usage in Gazelle and Grafana report endpoints
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ docker run -v $(pwd)/ocelot.conf:/srv/ocelot.conf ocelot
* `-c <path/to/ocelot.conf>` - Path to config file. If unspecified, the current working directory is used.
* `-v` - Print queue status every time a flush is initiated.

You can run a test ocelot daemon alongside a production daemon by specifying
a separate configuration file, and setting `readonly = true`. This will
prevent the database peer tables from being reset.

### Signals

* `SIGHUP` - Reload config
Expand Down
2 changes: 2 additions & 0 deletions ocelot.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ log_path = /tmp/ocelot
# the report path should be placed on a tmpfs partition in production
report_path = /tmp/ocelot

# set to true if prevent peer data from being zeroed out on startup
# useful to test a new version alongside an instance running in production
readonly = false
10 changes: 9 additions & 1 deletion src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "response.h"
#include "events.h"

std::mutex peak_open_mutex;

// Define the connection mother (first half) and connection middlemen (second half)

//---------- Connection mother - spawns middlemen and lets them deal with the connection
Expand Down Expand Up @@ -119,7 +121,13 @@ void connection_mother::handle_connect(ev::io &watcher, int events_flags) {
// Spawn a new middleman
if (stats.open_connections < max_middlemen) {
stats.opened_connections++;
stats.open_connections++;
{
const std::lock_guard<std::mutex> lock(peak_open_mutex);
unsigned int current_open = stats.open_connections++;
if (stats.peak_connections < current_open) {
stats.peak_connections = current_open;
}
}
new connection_middleman(listen_socket, work, this);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/jemalloc_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,9 @@ small: 247840 131452 0 129036
large: 290816 815 0 808 0 971 0 815 0 2351 0
total: 538656 132267 0 129844 0
*/
if (!(in = strstr(in, "allocated nmalloc (#/sec) ndalloc (#/sec)"))) {
if (!(in = strstr(in, "(#/sec)\nsmall:"))) {
return 30;
}
if (!(in = strstr(in, "\nsmall:"))) {
return 31;
}

if (!(in = parse_sz(in, " ", &out->small.allocated))) {
return 40;
Expand Down
22 changes: 15 additions & 7 deletions src/ocelot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ static schedule *sched;

struct stats_t stats;

const char * version() {
return "2.1.3";
}

static void create_daemon() {
pid_t pid;

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

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

stats.open_connections = 0;
stats.peak_connections = 0;
stats.opened_connections = 0;
stats.connection_rate = 0;
stats.requests = 0;
stats.request_rate = 0;
stats.leechers = 0;
stats.seeders = 0;
stats.user_queue_size = 0;
stats.torrent_queue_size = 0;
stats.peer_queue_size = 0;
stats.snatch_queue_size = 0;
stats.token_queue_size = 0;
stats.max_client_request_len = 0;
stats.announcements = 0;
stats.succ_announcements = 0;
stats.scrapes = 0;
stats.bytes_read = 0;
stats.bytes_written = 0;
stats.auth_error_secret = 0;
stats.auth_error_report = 0;
stats.auth_error_announce_key = 0;
stats.client_error = 0;
stats.http_error = 0;
stats.start_time = time(NULL);

// Create worker object, which handles announces and scrapes and all that jazz
Expand Down
13 changes: 13 additions & 0 deletions src/ocelot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

// Copyright [2017-2024] Orpheus

#define OCELOT_VERSION_MAJOR 2
#define OCELOT_VERSION_MINOR 1
#define OCELOT_VERSION_BUGFIX 3
#define OCELOT_VERSION_NREV 0
#define OCELOT_VERSION "2.1.3"

#include <time.h>

#include <string>
Expand Down Expand Up @@ -94,6 +100,7 @@ typedef std::unordered_map<std::string, std::string> params_type;

struct stats_t {
std::atomic<uint32_t> open_connections;
std::atomic<uint32_t> peak_connections;
std::atomic<uint64_t> opened_connections;
std::atomic<uint64_t> connection_rate;
std::atomic<uint32_t> leechers;
Expand All @@ -103,13 +110,19 @@ struct stats_t {
std::atomic<uint32_t> peer_queue_size;
std::atomic<uint32_t> snatch_queue_size;
std::atomic<uint32_t> token_queue_size;
std::atomic<uint32_t> max_client_request_len;
std::atomic<uint64_t> requests;
std::atomic<uint64_t> request_rate;
std::atomic<uint64_t> announcements;
std::atomic<uint64_t> succ_announcements;
std::atomic<uint64_t> scrapes;
std::atomic<uint64_t> bytes_read;
std::atomic<uint64_t> bytes_written;
std::atomic<uint64_t> auth_error_secret;
std::atomic<uint64_t> auth_error_report;
std::atomic<uint64_t> auth_error_announce_key;
std::atomic<uint64_t> client_error;
std::atomic<uint64_t> http_error;
time_t start_time;
};
extern struct stats_t stats;
Expand Down
Loading

0 comments on commit d4aaff7

Please sign in to comment.