mirror of https://gerrit.osmocom.org/osmo-sysmon
Cleaner output if sections are empty
Even with a completely empty config we still get the following output: root sysinfo load: 0.87/0.92/0.98 ram: 243/168/0 uptime: 1d 22:18:19 netdev ping file shellcmd With this patch the sections are skipped if there are no entries and the command no sysinfo can be used to skip displaying the system information. Change-Id: I429fe7626b43aef74ff7458f5c2864888fa9a562
This commit is contained in:
parent
66a83f495f
commit
ef6c8e9569
|
@ -153,6 +153,9 @@ int osysmon_file_poll(struct value_node *parent)
|
|||
struct value_node *vn_file;
|
||||
struct osysmon_file *of;
|
||||
|
||||
if (llist_empty(&g_oss->files))
|
||||
return 0;
|
||||
|
||||
vn_file = value_node_add(parent, "file", NULL);
|
||||
|
||||
llist_for_each_entry(of, &g_oss->files, list)
|
||||
|
|
|
@ -229,6 +229,10 @@ int osysmon_ping_poll(struct value_node *parent)
|
|||
struct value_node *vn_host;
|
||||
int num_host = iterator_count(g_oss->pings->ping_handle);
|
||||
pingobj_iter_t *iter;
|
||||
|
||||
if (!num_host)
|
||||
return 0;
|
||||
|
||||
struct value_node *vn_ping = value_node_add(parent, "ping", NULL);
|
||||
if (!vn_ping)
|
||||
return -ENOMEM;
|
||||
|
@ -257,8 +261,5 @@ int osysmon_ping_poll(struct value_node *parent)
|
|||
add_ttl(iter, vn_host);
|
||||
}
|
||||
|
||||
if (num_host)
|
||||
return ping_send(g_oss->pings->ping_handle);
|
||||
|
||||
return 0;
|
||||
return ping_send(g_oss->pings->ping_handle);
|
||||
}
|
||||
|
|
|
@ -401,6 +401,9 @@ int osysmon_rtnl_poll(struct value_node *parent)
|
|||
{
|
||||
struct value_node *vn_net;
|
||||
|
||||
if (llist_empty(&g_oss->netdevs))
|
||||
return 0;
|
||||
|
||||
if (!g_oss->rcs)
|
||||
g_oss->rcs = rtnl_init(NULL);
|
||||
|
||||
|
|
|
@ -165,6 +165,9 @@ int osysmon_shellcmd_poll(struct value_node *parent)
|
|||
struct value_node *vn_file;
|
||||
struct osysmon_shellcmd *oc;
|
||||
|
||||
if (llist_empty(&g_oss->shellcmds))
|
||||
return 0;
|
||||
|
||||
vn_file = value_node_add(parent, "shellcmd", NULL);
|
||||
|
||||
llist_for_each_entry(oc, &g_oss->shellcmds, list)
|
||||
|
|
|
@ -30,16 +30,6 @@
|
|||
#include "osysmon.h"
|
||||
#include "value_node.h"
|
||||
|
||||
/***********************************************************************
|
||||
* Runtime Code
|
||||
***********************************************************************/
|
||||
|
||||
/* called once on startup before config file parsing */
|
||||
int osysmon_sysinfo_init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static float loadfac(unsigned long in) {
|
||||
return in/65536.0;
|
||||
}
|
||||
|
@ -55,6 +45,48 @@ static float loadfac(unsigned long in) {
|
|||
#define to_minutes(in) (((in)/(SECS_PER_MIN))%MINS_PER_HOUR)
|
||||
#define to_seconds(in) ((in)%SECS_PER_MIN)
|
||||
|
||||
static bool sysinfo_enabled = 1;
|
||||
|
||||
/***********************************************************************
|
||||
* VTY
|
||||
***********************************************************************/
|
||||
|
||||
#define CMD_STR "Display sysinfo\n"
|
||||
DEFUN(cfg_sysinfo, cfg_sysinfo_cmd,
|
||||
"sysinfo",
|
||||
CMD_STR)
|
||||
{
|
||||
sysinfo_enabled = true;
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
DEFUN(cfg_no_sysinfo, cfg_no_sysinfo_cmd,
|
||||
"no sysinfo",
|
||||
NO_STR CMD_STR)
|
||||
{
|
||||
sysinfo_enabled = false;
|
||||
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
static void osysmon_sysinfo_vty_init(void)
|
||||
{
|
||||
install_element(CONFIG_NODE, &cfg_sysinfo_cmd);
|
||||
install_element(CONFIG_NODE, &cfg_no_sysinfo_cmd);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* Runtime Code
|
||||
***********************************************************************/
|
||||
|
||||
/* called once on startup before config file parsing */
|
||||
int osysmon_sysinfo_init()
|
||||
{
|
||||
osysmon_sysinfo_vty_init();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* called periodically */
|
||||
int osysmon_sysinfo_poll(struct value_node *parent)
|
||||
{
|
||||
|
@ -63,6 +95,9 @@ int osysmon_sysinfo_poll(struct value_node *parent)
|
|||
char buf[32];
|
||||
int rc;
|
||||
|
||||
if (!sysinfo_enabled)
|
||||
return 0;
|
||||
|
||||
vn_sysinfo = value_node_add(parent, "sysinfo", NULL);
|
||||
|
||||
rc = sysinfo(&si);
|
||||
|
|
Loading…
Reference in New Issue