main: add a command line option for dumping remote node data
Run for a given number of seconds and dump all found remote hosts/nodes as JSON data Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
51
main.c
51
main.c
@@ -21,13 +21,17 @@
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <libubox/blobmsg_json.h>
|
||||
|
||||
#include "usteer.h"
|
||||
#include "event.h"
|
||||
#include "node.h"
|
||||
|
||||
struct ubus_context *ubus_ctx;
|
||||
struct usteer_config config = {};
|
||||
struct blob_attr *host_info_blob;
|
||||
uint64_t current_time;
|
||||
static int dump_time;
|
||||
|
||||
LIST_HEAD(node_handlers);
|
||||
|
||||
@@ -125,17 +129,50 @@ static int usage(const char *prog)
|
||||
" 5: include extra testing messages\n"
|
||||
" -i <name>: Connect to other instances on interface <name>\n"
|
||||
" -s: Output log messages via syslog instead of stderr\n"
|
||||
" -D <n>: Do not daemonize, wait for <n> seconds and print\n"
|
||||
" remote hosts and nodes\n"
|
||||
"\n", prog);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
usteer_dump_timeout(struct uloop_timeout *t)
|
||||
{
|
||||
struct usteer_remote_host *host;
|
||||
struct usteer_remote_node *rn;
|
||||
struct blob_buf b = {};
|
||||
char *str;
|
||||
void *c;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
c = blobmsg_open_table(&b, "hosts");
|
||||
avl_for_each_element(&remote_hosts, host, avl)
|
||||
usteer_dump_host(&b, host);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
c = blobmsg_open_table(&b, "nodes");
|
||||
for_each_remote_node(rn)
|
||||
usteer_dump_node(&b, &rn->node);
|
||||
blobmsg_close_table(&b, c);
|
||||
|
||||
str = blobmsg_format_json(b.head, true);
|
||||
blob_buf_free(&b);
|
||||
|
||||
puts(str);
|
||||
free(str);
|
||||
|
||||
uloop_end();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct uloop_timeout dump_timer;
|
||||
int ch;
|
||||
|
||||
usteer_init_defaults();
|
||||
|
||||
while ((ch = getopt(argc, argv, "i:sv")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "D:i:sv")) != -1) {
|
||||
switch(ch) {
|
||||
case 'v':
|
||||
config.debug_level++;
|
||||
@@ -146,6 +183,9 @@ int main(int argc, char **argv)
|
||||
case 'i':
|
||||
usteer_interface_add(optarg);
|
||||
break;
|
||||
case 'D':
|
||||
dump_time = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
return usage(argv[0]);
|
||||
}
|
||||
@@ -164,9 +204,14 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
ubus_add_uloop(ubus_ctx);
|
||||
usteer_ubus_init(ubus_ctx);
|
||||
usteer_interface_init();
|
||||
usteer_local_nodes_init(ubus_ctx);
|
||||
if (dump_time) {
|
||||
dump_timer.cb = usteer_dump_timeout;
|
||||
uloop_timeout_set(&dump_timer, dump_time * 1000);
|
||||
} else {
|
||||
usteer_ubus_init(ubus_ctx);
|
||||
usteer_local_nodes_init(ubus_ctx);
|
||||
}
|
||||
uloop_run();
|
||||
|
||||
uloop_done();
|
||||
|
3
remote.c
3
remote.c
@@ -526,6 +526,9 @@ usteer_send_update_timer(struct uloop_timeout *t)
|
||||
struct usteer_node *node;
|
||||
void *c;
|
||||
|
||||
if (avl_is_empty(&local_nodes) && !host_info_blob)
|
||||
return;
|
||||
|
||||
usteer_update_time();
|
||||
uloop_timeout_set(t, config.remote_update_interval);
|
||||
|
||||
|
50
ubus.c
50
ubus.c
@@ -267,27 +267,39 @@ usteer_ubus_set_config(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usteer_dump_node(struct usteer_node *node)
|
||||
void usteer_dump_node(struct blob_buf *buf, struct usteer_node *node)
|
||||
{
|
||||
void *c;
|
||||
|
||||
c = blobmsg_open_table(&b, usteer_node_name(node));
|
||||
blobmsg_add_u32(&b, "freq", node->freq);
|
||||
blobmsg_add_u32(&b, "n_assoc", node->n_assoc);
|
||||
blobmsg_add_u32(&b, "noise", node->noise);
|
||||
blobmsg_add_u32(&b, "load", node->load);
|
||||
blobmsg_add_u32(&b, "max_assoc", node->max_assoc);
|
||||
c = blobmsg_open_table(buf, usteer_node_name(node));
|
||||
blobmsg_add_u32(buf, "freq", node->freq);
|
||||
blobmsg_add_u32(buf, "n_assoc", node->n_assoc);
|
||||
blobmsg_add_u32(buf, "noise", node->noise);
|
||||
blobmsg_add_u32(buf, "load", node->load);
|
||||
blobmsg_add_u32(buf, "max_assoc", node->max_assoc);
|
||||
if (node->rrm_nr)
|
||||
blobmsg_add_field(&b, BLOBMSG_TYPE_ARRAY, "rrm_nr",
|
||||
blobmsg_add_field(buf, BLOBMSG_TYPE_ARRAY, "rrm_nr",
|
||||
blobmsg_data(node->rrm_nr),
|
||||
blobmsg_data_len(node->rrm_nr));
|
||||
if (node->node_info)
|
||||
blobmsg_add_field(&b, BLOBMSG_TYPE_TABLE, "node_info",
|
||||
blobmsg_add_field(buf, BLOBMSG_TYPE_TABLE, "node_info",
|
||||
blob_data(node->node_info),
|
||||
blob_len(node->node_info));
|
||||
|
||||
blobmsg_close_table(&b, c);
|
||||
blobmsg_close_table(buf, c);
|
||||
}
|
||||
|
||||
void usteer_dump_host(struct blob_buf *buf, struct usteer_remote_host *host)
|
||||
{
|
||||
void *c;
|
||||
|
||||
c = blobmsg_open_table(buf, host->addr);
|
||||
blobmsg_add_u32(buf, "id", (uint32_t)(uintptr_t)host->avl.key);
|
||||
if (host->host_info)
|
||||
blobmsg_add_field(buf, BLOBMSG_TYPE_TABLE, "host_info",
|
||||
blobmsg_data(host->host_info),
|
||||
blobmsg_len(host->host_info));
|
||||
blobmsg_close_table(buf, c);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -300,7 +312,7 @@ usteer_ubus_local_info(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
for_each_local_node(node)
|
||||
usteer_dump_node(node);
|
||||
usteer_dump_node(&b, node);
|
||||
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
|
||||
@@ -313,19 +325,11 @@ usteer_ubus_remote_hosts(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
struct blob_attr *msg)
|
||||
{
|
||||
struct usteer_remote_host *host;
|
||||
void *c;
|
||||
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
avl_for_each_element(&remote_hosts, host, avl) {
|
||||
c = blobmsg_open_table(&b, host->addr);
|
||||
blobmsg_add_u32(&b, "id", (uint32_t)(uintptr_t)host->avl.key);
|
||||
if (host->host_info)
|
||||
blobmsg_add_field(&b, BLOBMSG_TYPE_TABLE, "host_info",
|
||||
blobmsg_data(host->host_info),
|
||||
blobmsg_len(host->host_info));
|
||||
blobmsg_close_table(&b, c);
|
||||
}
|
||||
avl_for_each_element(&remote_hosts, host, avl)
|
||||
usteer_dump_host(&b, host);
|
||||
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
|
||||
@@ -342,7 +346,7 @@ usteer_ubus_remote_info(struct ubus_context *ctx, struct ubus_object *obj,
|
||||
blob_buf_init(&b, 0);
|
||||
|
||||
for_each_remote_node(rn)
|
||||
usteer_dump_node(&rn->node);
|
||||
usteer_dump_node(&b, &rn->node);
|
||||
|
||||
ubus_send_reply(ctx, req, b.head);
|
||||
|
||||
|
4
usteer.h
4
usteer.h
@@ -53,6 +53,7 @@ enum usteer_node_type {
|
||||
|
||||
struct sta_info;
|
||||
struct usteer_local_node;
|
||||
struct usteer_remote_host;
|
||||
|
||||
struct usteer_node {
|
||||
struct avl_node avl;
|
||||
@@ -269,4 +270,7 @@ int usteer_lua_init(void);
|
||||
int usteer_lua_ubus_init(void);
|
||||
void usteer_run_hook(const char *name, const char *arg);
|
||||
|
||||
void usteer_dump_node(struct blob_buf *buf, struct usteer_node *node);
|
||||
void usteer_dump_host(struct blob_buf *buf, struct usteer_remote_host *host);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user