From: Niklas Larsson Date: Wed, 25 May 2016 13:45:08 +0000 (+0200) Subject: core/manager: Add uptime field to FullyBooted X-Git-Tag: 14.0.0-beta1~137^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F2904%2F4;p=thirdparty%2Fasterisk.git core/manager: Add uptime field to FullyBooted Add Uptime and LastReload to event FullyBooted. ASTERISK-26058 #close Reported by: Niklas Larsson Change-Id: I909b330801c0990d78df9b272ab0adc95aecb15e --- diff --git a/main/asterisk.c b/main/asterisk.c index 6cfbc1b336..25c6c95690 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -260,6 +260,12 @@ int daemon(int, int); /* defined in libresolv of all places */ Informational message + + Seconds since start + + + Seconds since last reload + @@ -1020,9 +1026,25 @@ static char *handle_clear_profile(struct ast_cli_entry *e, int cmd, struct ast_c static void publish_fully_booted(void) { RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref); + int uptime = 0; + int lastreloaded = 0; + struct timeval tmp; + struct timeval curtime = ast_tvnow(); - json_object = ast_json_pack("{s: s}", - "Status", "Fully Booted"); + if (ast_startuptime.tv_sec) { + tmp = ast_tvsub(curtime, ast_startuptime); + uptime = (int) tmp.tv_sec; + } + + if (ast_lastreloadtime.tv_sec) { + tmp = ast_tvsub(curtime, ast_lastreloadtime); + lastreloaded = (int) tmp.tv_sec; + } + + json_object = ast_json_pack("{s: s, s: i, s: i}", + "Status", "Fully Booted", + "Uptime", uptime, + "LastReload", lastreloaded); ast_manager_publish_event("FullyBooted", EVENT_FLAG_SYSTEM, json_object); } @@ -4221,6 +4243,9 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou char *buf; int moduleresult; /*!< Result from the module load subsystem */ + /* Set time as soon as possible */ + ast_lastreloadtime = ast_startuptime = ast_tvnow(); + /* This needs to remain as high up in the initial start up as possible. * daemon causes a fork to occur, which has all sorts of unintended * consequences for things that interact with threads. This call *must* @@ -4689,7 +4714,6 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou __ast_mm_init_phase_2(); #endif /* defined(__AST_DEBUG_MALLOC) */ - ast_lastreloadtime = ast_startuptime = ast_tvnow(); ast_cli_register_multiple(cli_asterisk_shutdown, ARRAY_LEN(cli_asterisk_shutdown)); ast_cli_register_multiple(cli_asterisk, ARRAY_LEN(cli_asterisk)); ast_register_cleanup(main_atexit); diff --git a/main/manager.c b/main/manager.c index d2fdc403db..94415b7a0d 100644 --- a/main/manager.c +++ b/main/manager.c @@ -4157,10 +4157,26 @@ static int action_login(struct mansession *s, const struct message *m) && ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) { struct ast_str *auth = ast_str_alloca(MAX_AUTH_PERM_STRING); const char *cat_str = authority_to_str(EVENT_FLAG_SYSTEM, &auth); + long uptime = 0; + long lastreloaded = 0; + struct timeval tmp; + struct timeval curtime = ast_tvnow(); + + if (ast_startuptime.tv_sec) { + tmp = ast_tvsub(curtime, ast_startuptime); + uptime = tmp.tv_sec; + } + + if (ast_lastreloadtime.tv_sec) { + tmp = ast_tvsub(curtime, ast_lastreloadtime); + lastreloaded = tmp.tv_sec; + } astman_append(s, "Event: FullyBooted\r\n" "Privilege: %s\r\n" - "Status: Fully Booted\r\n\r\n", cat_str); + "Uptime: %ld\r\n" + "LastReload: %ld\r\n" + "Status: Fully Booted\r\n\r\n", cat_str, uptime, lastreloaded); } return 0; }