summaryrefslogtreecommitdiffstats
path: root/src/server/rpc.c
diff options
context:
space:
mode:
authorStephan Schwaer2015-05-05 18:18:32 +0200
committerStephan Schwaer2015-05-05 18:18:32 +0200
commitd3ee0d21a16b6e696297b8e1f0c4ad8abdecca37 (patch)
treeb823abbb74ff769e30507560b125495a413fe90b /src/server/rpc.c
parentRemoved dnbd3_printClients, added clients to statistics json in rpc. (diff)
downloaddnbd3-d3ee0d21a16b6e696297b8e1f0c4ad8abdecca37.tar.gz
dnbd3-d3ee0d21a16b6e696297b8e1f0c4ad8abdecca37.tar.xz
dnbd3-d3ee0d21a16b6e696297b8e1f0c4ad8abdecca37.zip
[Server] Added statistics of images and uptime to json.
Diffstat (limited to 'src/server/rpc.c')
-rw-r--r--src/server/rpc.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/server/rpc.c b/src/server/rpc.c
index ae01a0e..af3507c 100644
--- a/src/server/rpc.c
+++ b/src/server/rpc.c
@@ -1,7 +1,3 @@
-#include <unistd.h>
-#include <string.h>
-#include <jansson.h>
-
#include "rpc.h"
#include "server.h"
#include "net.h"
@@ -9,6 +5,12 @@
#include "log.h"
#include "locks.h"
#include "helper.h"
+#include "image.h"
+
+#include <unistd.h>
+#include <string.h>
+#include <jansson.h>
+#include <inttypes.h>
static void clientsToJson(json_t *jsonClients);
@@ -16,12 +18,16 @@ void rpc_sendStatsJson(int sock)
{
uint64_t receivedBytes = uplink_getTotalBytesReceived();
uint64_t sentBytes = net_getTotalBytesSent();
+ 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_object_set( statisticsJson, "clients", jsonClients );
+
+ json_t *statisticsJson = json_pack( "{sIsI}", "receivedBytes", (json_int_t) receivedBytes, "sentBytes", (json_int_t) sentBytes );
+ json_object_set_new( statisticsJson, "clients", jsonClients );
+ json_object_set_new( statisticsJson, "images", image_fillJson() );
+ json_object_set_new( statisticsJson, "uptime", json_integer( uptime ) );
char *jsonString = json_dumps( statisticsJson, 0 );
char buffer[500];
@@ -30,7 +36,6 @@ void rpc_sendStatsJson(int sock)
write( sock, buffer, strlen( buffer ) );
write( sock, jsonString, strlen( jsonString ) );
json_decref( statisticsJson );
- json_decref( jsonClients );
free( jsonString );
}
@@ -46,9 +51,8 @@ static void clientsToJson(json_t *jsonClients)
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( jsonClients, clientStats );
- json_decref( clientStats );
+ clientStats = json_pack( "{sssssI}", "client", clientName, "image", imageName , "bytesSent", (json_int_t)_clients[i]->bytesSent );
+ json_array_append_new( jsonClients, clientStats );
spin_unlock( &_clients[i]->lock );
}
spin_unlock( &_clients_lock );