aboutsummaryrefslogtreecommitdiffstats
path: root/cli.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-05-02 15:37:34 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-05-02 15:37:34 +0000
commit69841867537dfa3d428ff5006c5f4a76a4a781ab (patch)
tree3b65f539dfb3e4461436cdc4d8a48891221a677c /cli.c
parentf90d5056f66da9d01d4223b369c4bcba0bf83681 (diff)
Show uptime
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@951 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'cli.c')
-rwxr-xr-xcli.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/cli.c b/cli.c
index e5fc66120..2c17a5d57 100755
--- a/cli.c
+++ b/cli.c
@@ -173,6 +173,92 @@ static char version_help[] =
"Usage: show version\n"
" Shows Asterisk version information.\n ";
+static char *format_uptimestr(time_t timeval)
+{
+ int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0;
+ char timestr[256];
+ int pos = 0;
+#define SECOND (1)
+#define MIN (SECOND*60)
+#define HOUR (MIN*60)
+#define DAY (HOUR*24)
+#define WEEK (DAY*7)
+#define YEAR (DAY*365)
+
+ if (timeval > YEAR) {
+ years = (timeval / YEAR);
+ timeval -= (years * YEAR);
+ if (years > 1)
+ pos += sprintf(timestr + pos, "%d years, ", years);
+ else
+ pos += sprintf(timestr + pos, "1 year, ");
+ }
+ if (timeval > WEEK) {
+ weeks = (timeval / WEEK);
+ timeval -= (weeks * WEEK);
+ if (weeks > 1)
+ pos += sprintf(timestr + pos, "%d weeks, ", weeks);
+ else
+ pos += sprintf(timestr + pos, "1 week, ");
+ }
+ if (timeval > DAY) {
+ days = (timeval / DAY);
+ timeval -= (days * DAY);
+ if (days > 1)
+ pos += sprintf(timestr + pos, "%d days, ", days);
+ else
+ pos += sprintf(timestr + pos, "1 day, ");
+
+ }
+ if (timeval > HOUR) {
+ hours = (timeval / HOUR);
+ timeval -= (hours * HOUR);
+ if (hours > 1)
+ pos += sprintf(timestr + pos, "%d hours, ", hours);
+ else
+ pos += sprintf(timestr + pos, "1 hour, ");
+ }
+ if (timeval > MIN) {
+ mins = (timeval / MIN);
+ timeval -= (mins * MIN);
+ if (mins > 1)
+ pos += sprintf(timestr + pos, "%d minutes, ", mins);
+ else if (mins > 0)
+ pos += sprintf(timestr + pos, "1 minute, ");
+ }
+ secs = timeval;
+
+ if (secs > 0)
+ pos += sprintf(timestr + pos, "%d seconds", secs);
+
+ return timestr ? strdup(timestr) : NULL;
+}
+
+static int handle_showuptime(int fd, int argc, char *argv[])
+{
+ time_t curtime, tmptime;
+ char *timestr;
+
+ time(&curtime);
+ if (ast_startuptime) {
+ tmptime = curtime - ast_startuptime;
+ timestr = format_uptimestr(tmptime);
+ if (timestr) {
+ ast_cli(fd, "System uptime: %s\n", timestr);
+ free(timestr);
+ }
+ }
+ if (ast_lastreloadtime) {
+ tmptime = curtime - ast_lastreloadtime;
+ timestr = format_uptimestr(tmptime);
+ if (timestr) {
+ ast_cli(fd, "Last reload: %s\n", timestr);
+ free(timestr);
+ }
+ }
+ return RESULT_SUCCESS;
+}
+
static int handle_modlist(int fd, int argc, char *argv[])
{
if (argc != 2)
@@ -476,6 +562,7 @@ static struct ast_cli_entry builtins[] = {
{ { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch },
{ { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help },
{ { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
+ { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", modlist_help },
{ { "show", "version", NULL }, handle_version, "Display version info", version_help },
{ { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch },
{ { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },