Skip to content

Commit

Permalink
ubus: add statistics call
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Apr 1, 2024
1 parent a470b8f commit 927349c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
struct nw {
struct ubus_context *ubus_ctx;
struct uloop_timeout update_timeout;

struct {
uint64_t update_count;
} statistics;
};
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ static void collect_information(struct uloop_timeout *timeout) {
log_debug("Update %s", buf_hex);
nw_interface_update(instance->ubus_ctx, (char *)buf_hex);

instance->statistics.update_count++;

out_free:
free(buf_hex);
uloop_timeout_set(timeout, UPDATE_INTERVAL);
Expand Down
20 changes: 20 additions & 0 deletions src/ubus.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "node-whisperer.h"
#include "daemon.h"

extern struct nw_information_source information_sources[];

Expand Down Expand Up @@ -89,9 +90,28 @@ static int nw_ubus_get_sources(struct ubus_context *ctx, struct ubus_object *obj
return 0;
}

static int nw_ubus_statistics(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg)
{
struct nw *nw = container_of(ctx, struct nw, ubus_ctx);
struct nw_information_source *source;
void *t, *a;

blob_buf_init(&b, 0);

blobmsg_add_u64(&b, "update_count", nw->statistics.update_count);

ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);

return 0;
}

static const struct ubus_method nw_methods[] = {
UBUS_METHOD("set_sources", nw_ubus_enable_source, source_toggle_arg),
UBUS_METHOD_NOARG("get_sources", nw_ubus_get_sources),
UBUS_METHOD_NOARG("statistics", nw_ubus_statistics),
};

static struct ubus_object_type nw_obj_type =
Expand Down

0 comments on commit 927349c

Please sign in to comment.