]> git.ipfire.org Git - fireperf.git/commitdiff
server: Show current bandwidth
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Jan 2021 16:56:59 +0000 (16:56 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Jan 2021 16:56:59 +0000 (16:56 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/server.c

index cbaf7089714f1962ef3ac332915eb3d185b06f54..e4bbac9990fa18922264432b251b84caf6411936 100644 (file)
@@ -40,6 +40,7 @@ struct fireperf_server_stats {
        // Total number of open connections
        unsigned int connections;
 
+       size_t bytes_received;
        size_t total_bytes_received;
 };
 
@@ -111,15 +112,25 @@ static int dump_stats(struct fireperf_config* conf, struct fireperf_server_stats
        // Format total bytes received
        char* total_bytes_received = format_size(stats->total_bytes_received);
 
+       // Calculate bandwidth
+       char* bps = format_size(stats->bytes_received / delta);
+
        INFO( conf, "--- %s --------------------\n", timestamp);
        DEBUG(conf, "  %-20s: %19.4fs\n", "Delta", delta);
        INFO( conf, "  %-20s: %20u\n", "Open Connection(s)", stats->connections);
+       INFO( conf, "  %-20s: %18s/s\n", "Current Bandwidth", bps);
        INFO( conf, "  %-20s: %20s\n", "Total Bytes Received", total_bytes_received);
 
        // Remember when this was printed last
        stats->last_printed = now;
 
+       // Reset statistics
+       stats->bytes_received = 0;
+
        // Cleanup
+       if (bps)
+               free(bps);
+
        if (total_bytes_received)
                free(total_bytes_received);
 
@@ -203,6 +214,7 @@ static int handle_io_on_connection(struct fireperf_config* conf,
        DEBUG(conf, "Read %zu bytes from socket %d\n", bytes_read, fd);
 
        // Update statistics
+       stats->bytes_received += bytes_read;
        stats->total_bytes_received += bytes_read;
 
        return 0;