| /* Simple Osmocom System Monitor (osysmon) */ |
| |
| /* (C) 2018 by Harald Welte <laforge@gnumonks.org> |
| * All Rights Reserved. |
| * |
| * SPDX-License-Identifier: GPL-2.0+ |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 2 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| * MA 02110-1301, USA. |
| */ |
| |
| #include <unistd.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <signal.h> |
| |
| #include "config.h" |
| #include "osysmon.h" |
| #include "value_node.h" |
| |
| #include <osmocom/core/msgb.h> |
| #include <osmocom/core/logging.h> |
| #include <osmocom/core/application.h> |
| |
| static struct log_info log_info = {}; |
| |
| static int osysmon_go_parent(struct vty *vty) |
| { |
| switch (vty->node) { |
| case CTRL_CLIENT_NODE: |
| case CTRL_CLIENT_GETVAR_NODE: |
| return osysmon_ctrl_go_parent(vty); |
| } |
| return vty->node; |
| } |
| |
| static int osysmon_is_config_node(struct vty *vty, int node) |
| { |
| switch (node) { |
| /* no non-config-nodes */ |
| default: |
| return 1; |
| } |
| } |
| |
| |
| static struct vty_app_info vty_info = { |
| .name = "osysmon", |
| .copyright = |
| "Copyright (C) 2008-2018 Harald Welte\r\n" |
| "License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>\r\n" |
| "This is free software: you are free to change and redistribute it.\r\n" |
| "There is NO WARRANTY, to the extent permitted by law.\r\n", |
| .version = PACKAGE_VERSION, |
| .go_parent_cb = osysmon_go_parent, |
| .is_config_node = osysmon_is_config_node, |
| }; |
| |
| |
| static const char *config_file = "osmo-sysmon.cfg"; |
| struct osysmon_state *g_oss; |
| |
| |
| static void print_node(struct value_node *node, unsigned int indent) |
| { |
| unsigned int i; |
| |
| if (node->value) { |
| for (i = 0; i < indent; i++) |
| fputc(' ', stdout); |
| printf("%s: %s\n", node->name, node->value); |
| } else { |
| struct value_node *vn; |
| for (i = 0; i < indent; i++) |
| fputc(' ', stdout); |
| printf("%s\n", node->name); |
| llist_for_each_entry(vn, &node->children, list) |
| print_node(vn, indent+2); |
| } |
| } |
| |
| static void display_update(struct value_node *root) |
| { |
| print_node(root, 0); |
| } |
| |
| static void signal_handler(int signal) |
| { |
| fprintf(stderr, "Signal %u received", signal); |
| |
| switch(signal) { |
| case SIGUSR1: |
| talloc_report(g_oss, stderr); |
| break; |
| default: |
| break; |
| } |
| } |
| |
| int main(int argc, char **argv) |
| { |
| int rc; |
| |
| osmo_init_logging2(NULL, &log_info); |
| |
| g_oss = talloc_zero(NULL, struct osysmon_state); |
| INIT_LLIST_HEAD(&g_oss->ctrl_clients); |
| INIT_LLIST_HEAD(&g_oss->netdevs); |
| INIT_LLIST_HEAD(&g_oss->files); |
| |
| vty_init(&vty_info); |
| osysmon_sysinfo_init(); |
| osysmon_ctrl_init(); |
| osysmon_rtnl_init(); |
| osysmon_file_init(); |
| |
| rc = vty_read_config_file(config_file, NULL); |
| if (rc < 0) { |
| fprintf(stderr, "Failed to parse the config file %s\n", config_file); |
| exit(2); |
| } |
| |
| signal(SIGUSR1, &signal_handler); |
| signal(SIGUSR2, &signal_handler); |
| osmo_init_ignore_signals(); |
| |
| while (1) { |
| struct value_node *root = value_node_add(g_oss, NULL, "root", NULL); |
| osysmon_sysinfo_poll(root); |
| osysmon_ctrl_poll(root); |
| osysmon_rtnl_poll(root); |
| osysmon_file_poll(root); |
| |
| display_update(root); |
| value_node_del(root); |
| sleep(1); |
| } |
| |
| exit(0); |
| } |