summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-26 09:40:24 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-26 12:45:11 +0200
commit491bf6f5e9f5c6dde5d9d1ae26d0392ec247cb9d (patch)
treea04d7914b53e44179193535d3f7f5a12b976f5c9 /src/rest.c
parent3c395ecea2bb538cf5182a64df503329a0a1cbcc (diff)
rest: add free and used cache to GET /cache/list
Add "used_cache" and "free_cache" fields to the payload of GET /cache/list.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/rest.c b/src/rest.c
index 87259cf..5ac1c3f 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -4130,13 +4130,14 @@ static int og_cmd_image_scope_list(json_t *element,
static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const char *ip)
{
+ uint64_t img_size, cache_size = 0, used_cache = 0, free_cache = 0;
const char *img_name, *msglog, *img_checksum;
json_t *client_data, *cache_arr, *img_info;
- uint64_t img_size, cache_size = 0;
dbi_result result;
result = dbi_conn_queryf(dbi->conn,
- "SELECT ordenadores_particiones.tamano "
+ "SELECT ordenadores_particiones.tamano, "
+ "ordenadores_particiones.used_size, ordenadores_particiones.free_size "
"FROM ordenadores_particiones JOIN ordenadores "
"ON ordenadores.idordenador = ordenadores_particiones.idordenador "
"WHERE ordenadores.ip = '%s' AND codpar = 202", ip);
@@ -4149,6 +4150,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch
if (dbi_result_next_row(result)) {
cache_size = dbi_result_get_longlong(result, "tamano") * 1024;
+ used_cache = dbi_result_get_longlong(result, "used_size");
+ free_cache = dbi_result_get_longlong(result, "free_size");
}
dbi_result_free(result);
@@ -4200,6 +4203,8 @@ static int og_dbi_client_cache_get(struct og_dbi *dbi, json_t *clients, const ch
json_object_set_new(client_data, "ip", json_string(ip));
json_object_set_new(client_data, "cache_size", json_integer(cache_size));
+ json_object_set_new(client_data, "used_cache", json_integer(used_cache));
+ json_object_set_new(client_data, "free_cache", json_integer(free_cache));
json_object_set_new(client_data, "images", cache_arr);
json_array_append_new(clients, client_data);
dbi_result_free(result);