Add a stat for blobs stored.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4133 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-01-18 22:52:54 +00:00
parent 3285d93576
commit 85a2bc3f0f
5 changed files with 20 additions and 2 deletions

View File

@ -554,6 +554,9 @@ function _receive_websocket_message(message) {
tls_malloc_percent: {group: 'memory', name: 'tls'}, tls_malloc_percent: {group: 'memory', name: 'tls'},
uv_malloc_percent: {group: 'memory', name: 'uv'}, uv_malloc_percent: {group: 'memory', name: 'uv'},
messages_stored: {group: 'stored', name: 'messages'},
blobs_stored: {group: 'stored', name: 'blobs'},
socket_count: {group: 'socket', name: 'total'}, socket_count: {group: 'socket', name: 'total'},
socket_open_count: {group: 'socket', name: 'open'}, socket_open_count: {group: 'socket', name: 'open'},

View File

@ -169,6 +169,7 @@ typedef struct _tf_ssb_t
bool verbose; bool verbose;
int messages_stored; int messages_stored;
int blobs_stored;
int rpc_in; int rpc_in;
int rpc_out; int rpc_out;
@ -1951,6 +1952,7 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats)
.connections = ssb->connections_count, .connections = ssb->connections_count,
.broadcasts = ssb->broadcasts_count, .broadcasts = ssb->broadcasts_count,
.messages_stored = ssb->messages_stored, .messages_stored = ssb->messages_stored,
.blobs_stored = ssb->blobs_stored,
.rpc_in = ssb->rpc_in, .rpc_in = ssb->rpc_in,
.rpc_out = ssb->rpc_out, .rpc_out = ssb->rpc_out,
.request_count = ssb->request_count, .request_count = ssb->request_count,
@ -1964,6 +1966,7 @@ void tf_ssb_get_stats(tf_ssb_t* ssb, tf_ssb_stats_t* out_stats)
}, },
}; };
ssb->messages_stored = 0; ssb->messages_stored = 0;
ssb->blobs_stored = 0;
ssb->rpc_in = 0; ssb->rpc_in = 0;
ssb->rpc_out = 0; ssb->rpc_out = 0;
} }
@ -3019,6 +3022,11 @@ void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_ca
} }
} }
void tf_ssb_notify_blob_stored(tf_ssb_t* ssb, const char* id)
{
ssb->blobs_stored++;
}
void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id) void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id)
{ {
tf_ssb_message_added_callback_node_t* next = NULL; tf_ssb_message_added_callback_node_t* next = NULL;

View File

@ -455,9 +455,13 @@ bool tf_ssb_db_blob_store(tf_ssb_t* ssb, const uint8_t* blob, size_t size, char*
printf("prepare failed: %s\n", sqlite3_errmsg(db)); printf("prepare failed: %s\n", sqlite3_errmsg(db));
} }
if (rows && !out_new) if (rows)
{ {
printf("blob stored %s %zd => %d\n", id, size, result); tf_ssb_notify_blob_stored(ssb, id);
if (!out_new)
{
printf("blob stored %s %zd => %d\n", id, size, result);
}
} }
if (result && out_id) if (result && out_id)

View File

@ -44,6 +44,7 @@ typedef struct _tf_ssb_stats_t
int connections; int connections;
int broadcasts; int broadcasts;
int messages_stored; int messages_stored;
int blobs_stored;
int rpc_in; int rpc_in;
int rpc_out; int rpc_out;
int request_count; int request_count;
@ -136,6 +137,7 @@ typedef void (tf_ssb_message_added_callback_t)(tf_ssb_t* ssb, const char* id, vo
void tf_ssb_add_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data); void tf_ssb_add_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);
void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, void* user_data); void tf_ssb_remove_message_added_callback(tf_ssb_t* ssb, tf_ssb_message_added_callback_t* callback, void* user_data);
void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id); void tf_ssb_notify_message_added(tf_ssb_t* ssb, const char* id);
void tf_ssb_notify_blob_stored(tf_ssb_t* ssb, const char* id);
typedef void (tf_ssb_blob_want_added_callback_t)(tf_ssb_t* ssb, const char* id, void* user_data); typedef void (tf_ssb_blob_want_added_callback_t)(tf_ssb_t* ssb, const char* id, void* user_data);
void tf_ssb_add_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data); void tf_ssb_add_blob_want_added_callback(tf_ssb_t* ssb, tf_ssb_blob_want_added_callback_t* callback, tf_ssb_callback_cleanup_t* cleanup, void* user_data);

View File

@ -738,6 +738,7 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int
tf_ssb_get_stats(task->_ssb, &ssb_stats); tf_ssb_get_stats(task->_ssb, &ssb_stats);
JS_SetPropertyStr(context, result, "messages_stored", JS_NewInt32(context, ssb_stats.messages_stored)); JS_SetPropertyStr(context, result, "messages_stored", JS_NewInt32(context, ssb_stats.messages_stored));
JS_SetPropertyStr(context, result, "blobs_stored", JS_NewInt32(context, ssb_stats.blobs_stored));
JS_SetPropertyStr(context, result, "rpc_in", JS_NewInt32(context, ssb_stats.rpc_in)); JS_SetPropertyStr(context, result, "rpc_in", JS_NewInt32(context, ssb_stats.rpc_in));
JS_SetPropertyStr(context, result, "rpc_out", JS_NewInt32(context, ssb_stats.rpc_out)); JS_SetPropertyStr(context, result, "rpc_out", JS_NewInt32(context, ssb_stats.rpc_out));
JS_SetPropertyStr(context, result, "requests", JS_NewInt32(context, ssb_stats.request_count)); JS_SetPropertyStr(context, result, "requests", JS_NewInt32(context, ssb_stats.request_count));