summaryrefslogtreecommitdiffstats
path: root/src/server/rpc.c
diff options
context:
space:
mode:
authorSimon Rettberg2015-05-08 10:53:06 +0200
committerSimon Rettberg2015-05-08 10:53:06 +0200
commit2ab53f3a518dcd8b703e515ffd123adce181044c (patch)
tree96e52eddf2c9808ace02cfc5d4bb0457e8153ae0 /src/server/rpc.c
parent[SERVER] Fix premature connection close for RPC replies (diff)
downloaddnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.tar.gz
dnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.tar.xz
dnbd3-2ab53f3a518dcd8b703e515ffd123adce181044c.zip
[SERVER] Add image ID for easier handling in RPC, export RID via RPC, make names of the byte count fields in RPC consistent
Diffstat (limited to 'src/server/rpc.c')
-rw-r--r--src/server/rpc.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/server/rpc.c b/src/server/rpc.c
index d02ff92..ea1eccf 100644
--- a/src/server/rpc.c
+++ b/src/server/rpc.c
@@ -17,14 +17,14 @@ static void clientsToJson(json_t *jsonClients);
void rpc_sendStatsJson(int sock)
{
- const uint64_t receivedBytes = uplink_getTotalBytesReceived();
- const uint64_t sentBytes = net_getTotalBytesSent();
+ const uint64_t bytesReceived = uplink_getTotalBytesReceived();
+ const uint64_t bytesSent = net_getTotalBytesSent();
const int uptime = dnbd3_serverUptime();
json_t *jsonClients = json_array();
clientsToJson( jsonClients );
- json_t *statisticsJson = json_pack( "{sIsI}", "receivedBytes", (json_int_t) receivedBytes, "sentBytes", (json_int_t) sentBytes );
+ json_t *statisticsJson = json_pack( "{sIsI}", "bytesReceived", (json_int_t) bytesReceived, "bytesSent", (json_int_t) bytesSent );
json_object_set_new( statisticsJson, "clients", jsonClients );
json_object_set_new( statisticsJson, "images", image_fillJson() );
json_object_set_new( statisticsJson, "uptime", json_integer( uptime ) );
@@ -47,15 +47,17 @@ static void clientsToJson(json_t *jsonClients)
json_t *clientStats;
int i;
char clientName[100];
- const char *imageName;
spin_lock( &_clients_lock );
for (i = 0; i < _num_clients; ++i) {
if ( _clients[i] == NULL ) continue;
spin_lock( &_clients[i]->lock );
- host_to_string( &_clients[i]->host, clientName, sizeof(clientName) );
- imageName =_clients[i]->image != NULL ? _clients[i]->image->lower_name : "NULL";
- clientStats = json_pack( "{sssssI}", "client", clientName, "image", imageName , "bytesSent", (json_int_t)_clients[i]->bytesSent );
- json_array_append_new( jsonClients, clientStats );
+ if ( _clients[i]->image != NULL ) {
+ if ( !host_to_string( &_clients[i]->host, clientName, sizeof(clientName) ) ) {
+ strcpy( clientName, "???" );
+ }
+ clientStats = json_pack( "{sssisI}", "client", clientName, "image", _clients[i]->image->id, "bytesSent", (json_int_t)_clients[i]->bytesSent );
+ json_array_append_new( jsonClients, clientStats );
+ }
spin_unlock( &_clients[i]->lock );
}
spin_unlock( &_clients_lock );