[asterisk-commits] core/manager: Add uptime field to FullyBooted (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 3 08:09:53 CDT 2016


Joshua Colp has submitted this change and it was merged.

Change subject: core/manager: Add uptime field to FullyBooted
......................................................................


core/manager: Add uptime field to FullyBooted

Add Uptime and LastReload to event FullyBooted.

ASTERISK-26058 #close
Reported by: Niklas Larsson

Change-Id: I909b330801c0990d78df9b272ab0adc95aecb15e
---
M main/asterisk.c
M main/manager.c
2 files changed, 44 insertions(+), 4 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Verified



diff --git a/main/asterisk.c b/main/asterisk.c
index 6cfbc1b..25c6c95 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -260,6 +260,12 @@
 				<parameter name="Status">
 					<para>Informational message</para>
 				</parameter>
+				<parameter name="Uptime">
+					<para>Seconds since start</para>
+				</parameter>
+				<parameter name="LastReload">
+					<para>Seconds since last reload</para>
+				</parameter>
 			</syntax>
 		</managerEventInstance>
 	</managerEvent>
@@ -1020,9 +1026,25 @@
 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 @@
 	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 @@
 	__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 d2fdc40..94415b7 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -4157,10 +4157,26 @@
 		&& 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;
 }

-- 
To view, visit https://gerrit.asterisk.org/2904
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I909b330801c0990d78df9b272ab0adc95aecb15e
Gerrit-PatchSet: 4
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Niklas Larsson <niklas at tese.se>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list