Mercurial Hosting > nabble
changeset 29:667e51ca939b
Disk Usage
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 03 Jul 2020 13:03:05 -0600 |
parents | 03e68185c2f5 |
children | ee2236919b6a |
files | src/nabble/view/web/tools/Disk.java src/nabble/view/web/tools/Disk.jtp src/nabble/view/web/tools/Index.java src/nabble/view/web/tools/Index.jtp |
diffstat | 4 files changed, 26 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/src/nabble/view/web/tools/Disk.java Thu Jul 02 21:19:24 2020 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ - -package nabble.view.web.tools; - -import java.io.InputStream; -import java.io.IOException; -import javax.servlet.ServletException; -import java.io.PrintWriter; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import fschmidt.util.java.IoUtils; - - -public final class Disk extends HttpServlet { - - protected void service(HttpServletRequest request,HttpServletResponse response) - throws ServletException, IOException - { - response.setContentType("text/plain"); - PrintWriter out = response.getWriter(); - Process process = Runtime.getRuntime().exec("df -h"); - InputStream input = process.getInputStream(); - byte[] result = IoUtils.readAll(input); - input.close(); - String s = new String(result); - out.write(s); - } -} -
--- a/src/nabble/view/web/tools/Disk.jtp Thu Jul 02 21:19:24 2020 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -<% -package nabble.view.web.tools; - -import java.io.InputStream; -import java.io.IOException; -import javax.servlet.ServletException; -import java.io.PrintWriter; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import fschmidt.util.java.IoUtils; - - -public final class Disk extends HttpServlet { - - protected void service(HttpServletRequest request,HttpServletResponse response) - throws ServletException, IOException - { - response.setContentType("text/plain"); - PrintWriter out = response.getWriter(); - Process process = Runtime.getRuntime().exec("df -h"); - InputStream input = process.getInputStream(); - byte[] result = IoUtils.readAll(input); - input.close(); - String s = new String(result); - out.write(s); - } -} -%>
--- a/src/nabble/view/web/tools/Index.java Thu Jul 02 21:19:24 2020 -0600 +++ b/src/nabble/view/web/tools/Index.java Fri Jul 03 13:03:05 2020 -0600 @@ -65,6 +65,15 @@ loadAverage = new String(result).replaceAll(".*average:",""); } catch(IOException e) {} // not on linux + String diskUsage; + { + Process process = Runtime.getRuntime().exec(new String[]{"bash","-c","df -h | awk '{if ($0~\" /$\") {print $5}}'"}); + InputStream input = process.getInputStream(); + byte[] result = IoUtils.readAll(input); + input.close(); + diskUsage = new String(result).trim(); + } + Map<java.lang.Thread, java.lang.StackTraceElement[]> m = Thread.getAllStackTraces(); int socketRead = 0; int idleThread = 0; @@ -90,7 +99,7 @@ out.print( "\r\n<html>\r\n <head>\r\n <title>Nabble tools</title>\r\n <style type=\"text/css\">\r\n .gray {\r\n background-color: #eeeeee;\r\n padding: .5em;\r\n }\r\n p { padding-left: .5em; }\r\n td.row-label {\r\n font-weight:bold;\r\n padding: .1em .4em .1em 0;\r\n }\r\n td.row-separator { padding-top: 1em; }\r\n\r\n td.category {\r\n font-variant:small-caps;\r\n text-align:center;\r\n padding: 0 .5em;\r\n }\r\n </style>\r\n <script type=\"text/javascript\">\r\n var months = [\"Jan\",\"Feb\",\"Mar\",\"Apr\",\"May\",\"Jun\",\"Jul\",\"Aug\",\"Sep\",\"Oct\",\"Nov\",\"Dec\"];\r\n function fmt(i) { return i <= 9? \"0\" + i : i; };\r\n function formatTime(date) {\r\n var hours = date.getHours();\r\n if( hours < 12 ) {\r\n var xm = \"am\";\r\n if (hours==0)\r\n hours = 12;\r\n } else {\r\n var xm = \"pm\";\r\n if (hours > 12)\r\n hours -= 12;\r\n }\r\n return fmt(hours) + \":\" + fmt(date.getMinutes()) + xm;\r\n };\r\n function formatDate(date) {\r\n return months[date.getMonth()] + \" \" + fmt(date.getDate()) + \", \" + date.getFullYear();\r\n };\r\n function formatDateTime(date) {\r\n return formatDate(date) + \"; \" + formatTime(date);\r\n };\r\n </script>\r\n </head>\r\n <body style=\"font: .8em Verdana, Serif;\">\r\n <p class=\"gray\">\r\n Built time =\r\n <b>\r\n <script type=\"text/javascript\">\r\n document.write(formatDateTime(new Date(" ); out.print( (new Date(ClassLoader.getSystemResource("nabble/view/web/Index.class").openConnection().getLastModified()).getTime()) ); - out.print( ")));\r\n </script>\r\n </b>\r\n </p>\r\n\r\n <table style=\"font-size: 1em;\">\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#fafafa;\">General</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"Admin.jtp\">Caches</a></p>\r\n <p><a href=\"shell.luan\">Shell</a> (<a href=\"ShellHelp.jtp\">\r\n <small>help</small>\r\n </a>)\r\n </p>\r\n <p><a href=\"run.luan\">Run Batch</a></p>\r\n <p><a href=\"SendMail.jtp\">Send mail</a></p>\r\n <p><a href=\"Disk.jtp\">Disks</a></p>\r\n </td>\r\n </tr>\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#e0e0e0;\">Sites</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"AdminNotice.jtp\">Administrator Notice</a></p>\r\n </td>\r\n </tr>\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#d9d9d9;\">Others</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"TestMacro.jtp\">Test Macro</a></p>\r\n <p><a href=\"Profile.jtp\">Profiling</a></p>\r\n <p><a href=\"/tools2\">Generic tools</a></p>\r\n <p><a href=\"OnlineUsers.jtp\">Online Users</a></p>\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <div class=\"gray\" style=\"margin: 1em 0\">\r\n <table style=\"font-size:100%\">\r\n <tr>\r\n <td class=\"row-label\">Free Memory</td>\r\n <td>\r\n " ); + out.print( ")));\r\n </script>\r\n </b>\r\n </p>\r\n\r\n <table style=\"font-size: 1em;\">\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#fafafa;\">General</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"Admin.jtp\">Caches</a></p>\r\n <p><a href=\"shell.luan\">Shell</a> (<a href=\"ShellHelp.jtp\">\r\n <small>help</small>\r\n </a>)\r\n </p>\r\n <p><a href=\"run.luan\">Run Batch</a></p>\r\n <p><a href=\"SendMail.jtp\">Send mail</a></p>\r\n </td>\r\n </tr>\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#e0e0e0;\">Sites</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"AdminNotice.jtp\">Administrator Notice</a></p>\r\n </td>\r\n </tr>\r\n <tr>\r\n <td class=\"category\" style=\"background-color:#d9d9d9;\">Others</td>\r\n <td style=\"padding:.5em 0\">\r\n <p><a href=\"TestMacro.jtp\">Test Macro</a></p>\r\n <p><a href=\"Profile.jtp\">Profiling</a></p>\r\n <p><a href=\"/tools2\">Generic tools</a></p>\r\n <p><a href=\"OnlineUsers.jtp\">Online Users</a></p>\r\n </td>\r\n </tr>\r\n </table>\r\n\r\n <div class=\"gray\" style=\"margin: 1em 0\">\r\n <table style=\"font-size:100%\">\r\n <tr>\r\n <td class=\"row-label\">Free Memory</td>\r\n <td>\r\n " ); out.print( (String.format("%.2f",free)) ); out.print( " Mb\r\n </td>\r\n </tr>\r\n <tr>\r\n <td class=\"row-label\">Used Memory</td>\r\n <td>" ); out.print( (String.format("%.2f",used)) ); @@ -102,7 +111,9 @@ out.print( (loadAverage) ); out.print( "</td>\r\n </tr>\r\n " ); } - out.print( "\r\n <tr>\r\n <td class=\"row-label row-separator\">Pool Active Count</td>\r\n <td class=\"row-separator\">" ); + out.print( "\r\n <tr>\r\n <td class=\"row-label\">Disk Usage</td>\r\n <td>" ); + out.print( (diskUsage) ); + out.print( "</td>\r\n </tr>\r\n <tr>\r\n <td class=\"row-label row-separator\">Pool Active Count</td>\r\n <td class=\"row-separator\">" ); out.print( (Executors.foregroundExecutor.getActiveCount()) ); out.print( " threads</td>\r\n </tr>\r\n <tr>\r\n <td class=\"row-label\">Pool Size</td>\r\n <td>" ); out.print( (Executors.foregroundExecutor.getPoolSize()) );
--- a/src/nabble/view/web/tools/Index.jtp Thu Jul 02 21:19:24 2020 -0600 +++ b/src/nabble/view/web/tools/Index.jtp Fri Jul 03 13:03:05 2020 -0600 @@ -65,6 +65,15 @@ loadAverage = new String(result).replaceAll(".*average:",""); } catch(IOException e) {} // not on linux + String diskUsage; + { + Process process = Runtime.getRuntime().exec(new String[]{"bash","-c","df -h | awk '{if ($0~\" /$\") {print $5}}'"}); + InputStream input = process.getInputStream(); + byte[] result = IoUtils.readAll(input); + input.close(); + diskUsage = new String(result).trim(); + } + Map<java.lang.Thread, java.lang.StackTraceElement[]> m = Thread.getAllStackTraces(); int socketRead = 0; int idleThread = 0; @@ -154,7 +163,6 @@ </p> <p><a href="run.luan">Run Batch</a></p> <p><a href="SendMail.jtp">Send mail</a></p> - <p><a href="Disk.jtp">Disks</a></p> </td> </tr> <tr> @@ -197,6 +205,10 @@ </tr> <% } %> <tr> + <td class="row-label">Disk Usage</td> + <td><%=diskUsage%></td> + </tr> + <tr> <td class="row-label row-separator">Pool Active Count</td> <td class="row-separator"><%=Executors.foregroundExecutor.getActiveCount()%> threads</td> </tr>