portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r1674403 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/jetapp/ webapp/WEB-INF/ webapp/jetapp/ webapp/jetapp/charts/ webapp/jetapp/charts/scripts/ webapp/jetapp/scripts/
Date Fri, 17 Apr 2015 21:09:49 GMT
Author: taylor
Date: Fri Apr 17 21:09:48 2015
New Revision: 1674403

URL: http://svn.apache.org/r1674403
Log:
JS2-1320: hook in live stats to memory portlet.

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/app-memory.js
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/data.js

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppChartPortlet.java
Fri Apr 17 21:09:48 2015
@@ -12,16 +12,26 @@ public class JetAppChartPortlet extends
 
     protected static String[][] DEV_SCRIPTS = {
 //            { "/jetapp/charts/scripts/jquery-2.1.3.min.js", "chart_jquery"},
+            { "/wro/J2_ADMIN_EXTERNAL_JS.js", J2_ADMIN_EXTERNAL_SCRIPT_ID},
+            { "/jetapp/scripts/TextMessages.js", "j2admin_text"},
+            { "/jetapp/scripts/ServerService.js", "j2admin_server"},
+            { "/jetapp/scripts/RestApiService.js", "j2admin_services"},
+            { "/jetapp/scripts/PortletService.js", "j2admin_portlet"},
+            { "/jetapp/scripts/StatisticsRestServices.js", "j2admin_rest_stats"},
+            { "/jetapp/app.js", "j2admin_app"},
+            { "/jetapp/scripts/controllers.js", "j2admin_controllers"},
+            { "/jetapp/scripts/chartControllers.js", "j2admin_chart_controllers"},
+            { "/jetapp/scripts/directives.js", "j2admin_directives"},
+            { "/jetapp/scripts/filters.js", "j2admin_filters"},
             { "/jetapp/charts/scripts/d3.min.js", "chart_d3"},
             { "/jetapp/charts/scripts/nv.d3.min.js", "chart_nvd3js"},
             { "/jetapp/charts/scripts/data.js", "chart_data"},
-            { "/jetapp/charts/scripts/app-memory.js", "chart_memory"},
+//            { "/jetapp/charts/scripts/app-memory.js", "chart_memory"},
             { "/jetapp/charts/scripts/app-caches.js", "chart_caches"},
             { "/jetapp/charts/scripts/app-pages.js", "chart_pages"},
             { "/jetapp/charts/scripts/app-users.js", "chart_users"}
     };
 
-
     @Override
     protected void doHeaders(RenderRequest request, RenderResponse response) {
         //super.doHeaders(request, response);

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/jetapp/JetAppPortletFilter.java
Fri Apr 17 21:09:48 2015
@@ -36,6 +36,7 @@ public class JetAppPortletFilter impleme
 
     protected final static String JET_DASHBOARD_ANGULAR_FLAG = "jet.dashboard.angular.flag";
 
+    protected FilterConfig filterConfig = null;
 
     public void doFilter(RenderRequest request, RenderResponse response,
                          FilterChain filterChain) throws IOException, PortletException {
@@ -47,15 +48,22 @@ public class JetAppPortletFilter impleme
     }
 
     public void init(FilterConfig filterConfig) throws PortletException {
+        this.filterConfig = filterConfig;
     }
 
+    protected final String ANGULAR = "<script>\n    angular.element(document).ready(function()
{\n" +
+            "        angular.bootstrap(document, ['j2admin']);\n" +
+            "    });\n</script>\n";
+
     protected void includeAngular(RenderRequest request, RenderResponse response) throws
PortletException, IOException {
+//        if (filterConfig != null) {
+//            String flag = filterConfig.getPortletContext().getInitParameter("jetapp");
+//            System.out.println("Flag = " + flag);
+//        }
         String useAngular = request.getPreferences().getValue("jetapp", null);
         if (useAngular != null && useAngular.equalsIgnoreCase("true")) {
             if (!alreadyContributedAngular(request)) {
-                response.getWriter().println("<script>\n    angular.element(document).ready(function()
{\n" +
-                        "        angular.bootstrap(document, ['j2admin']);\n" +
-                        "    });\n</script>\n");
+                response.getPortletOutputStream().write(ANGULAR.getBytes());
             }
         }
     }

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/portlet.xml Fri
Apr 17 21:09:48 2015
@@ -2725,6 +2725,10 @@
     <portlet-name>ProfilerAdmin</portlet-name>
     <display-name>Profiler Maintenance</display-name>
     <portlet-class>org.apache.jetspeed.jetapp.ProfilerAdminPortlet</portlet-class>
+    <init-param>
+      <name>jetapp</name>
+      <value>true</value>
+    </init-param>
     <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
@@ -2778,6 +2782,10 @@
         <name>View</name>
         <value>/jetapp/charts/chart-memory.html</value>
       </preference>
+        <preference>
+            <name>jetapp</name>
+            <value>true</value>
+        </preference>
     </portlet-preferences>
   </portlet>
 
@@ -2803,6 +2811,10 @@
         <name>View</name>
         <value>/jetapp/charts/chart-pages.html</value>
       </preference>
+      <preference>
+            <name>jetapp</name>
+            <value>true</value>
+      </preference>
     </portlet-preferences>
   </portlet>
 
@@ -2828,6 +2840,10 @@
         <name>View</name>
         <value>/jetapp/charts/chart-users.html</value>
       </preference>
+      <preference>
+            <name>jetapp</name>
+            <value>true</value>
+      </preference>
     </portlet-preferences>
   </portlet>
 
@@ -2853,6 +2869,10 @@
         <name>View</name>
         <value>/jetapp/charts/chart-caches.html</value>
       </preference>
+        <preference>
+            <name>jetapp</name>
+            <value>true</value>
+        </preference>
     </portlet-preferences>
   </portlet>
 

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/app.js Fri Apr 17
21:09:48 2015
@@ -9,12 +9,14 @@ angular.module('j2admin', [
     'j2admin.filters',
 //    'j2admin.services',
     'j2admin.directives',
-    'j2admin.controllers'
+    'j2admin.controllers',
+    'j2admin.chartControllers'
 ])
     .factory('ServerService', ['$cookies', ServerService])
     .factory('TextMessages', [TextMessages])
     .factory('DataService', ['$http', '$q', 'ServerService', RestService])
     .factory('PortletService', ['$http', '$q', 'ServerService', PortletService])
+    .factory('StatisticsService', ['$http', '$q', 'ServerService', StatisticsRestService])
     .config(['$routeProvider', function ($routeProvider) {
         $routeProvider.when('/monitor', {templateUrl: 'views/monitor.html'});
         $routeProvider.otherwise({redirectTo: '/monitor'});

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-caches.html
Fri Apr 17 21:09:48 2015
@@ -1 +1 @@
-    <svg class="caches-container"></svg>
+    <svg class="caches-container" height="225"></svg>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-memory.html
Fri Apr 17 21:09:48 2015
@@ -1,3 +1,15 @@
-
-    <svg class="memory-container"></svg>
-
+<div ng-controller="MemoryController" ng-init="init()">
+    <!-- <div class="legend">
+        <select id="root-list" ng-options="root.name for root in roots track by root.id"
ng-model="currentRoot_" ng-disabled="!roots.length">
+        </select>
+        <br /><br />
+        <a href="#" id="add-cg-root" class="add-root pull-right" ng-click="addRoot('CUSTOM_GROUP')">CG+</a>
+        <br /><br /><br />
+        <a href="#" id="add-hg-root" class="add-root pull-right" ng-click="addRoot('HOSTGROUP')">HG+</a>
+        <br /><br /><br />
+        <a href="#" id="add-sg-root" class="add-root pull-right" ng-click="addRoot('SERVICE_GROUP')">SG+</a>
+    </div>
+
+    <div id="canvas-container"></div> -->
+    <svg class="memory-container" height="225"></svg>
+</div>
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-pages.html
Fri Apr 17 21:09:48 2015
@@ -1,3 +1,3 @@
 
-    <svg class="pages-container"></svg>
+    <svg class="pages-container" height="225"></svg>
 

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/chart-users.html
Fri Apr 17 21:09:48 2015
@@ -1 +1 @@
-    <svg class="users-container"></svg>
+    <svg class="users-container" height="225"></svg>

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/app-memory.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/app-memory.js?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/app-memory.js
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/app-memory.js
Fri Apr 17 21:09:48 2015
@@ -1,4 +1,4 @@
-function bytesToSize(bytes)
+/* function bytesToSize(bytes)
 {
     var precision = 1,
         kilobyte = 1024,
@@ -6,7 +6,7 @@ function bytesToSize(bytes)
         gigabyte = megabyte * 1024,
         terabyte = gigabyte * 1024;
 
-    var text = ""
+    var text = "";
 
     if ((bytes >= 0) && (bytes < kilobyte))
     {
@@ -41,7 +41,7 @@ $(function() {
     var datum = [];
 
     datum.push({label: "Free", value: memoryUsage.memory.free});
-    datum.push({label: "Used", value: (memoryUsage.memory.total - memoryUsage.memory.free)});
+    datum.push({label: "Used", value: memoryUsage.memory.total - memoryUsage.memory.free});
 
     nv.addGraph(function() {
         var chart = nv.models.pieChart()
@@ -73,4 +73,4 @@ $(function() {
 
         return chart;
     });
-});
\ No newline at end of file
+}); */
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/data.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/data.js?rev=1674403&r1=1674402&r2=1674403&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/data.js
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/charts/scripts/data.js
Fri Apr 17 21:09:48 2015
@@ -1,7 +1,7 @@
-var memoryUsage = {"memory": {
-    "total" : 257434565,
-    "free" :  200333444
-}};
+//var memoryUsage = {"memory": [
+//    {"total" : 257434565},
+//    {"free" :  200333444}
+//]};
 
 var pageHits = {"pages": [
     {"/default-page": 300},

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js?rev=1674403&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
(added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/StatisticsRestServices.js
Fri Apr 17 21:09:48 2015
@@ -0,0 +1,48 @@
+/**
+ * Created by swooten on 4/2/15.
+ */
+'use strict';
+
+/* Statistics Services */
+
+var StatisticsRestService = function ($http, $q, ServerService) {
+
+    //Needs to be unique like service?
+    var service = {
+
+        statistics: [],
+
+        /**
+         * Get JVM runtime info via query. The query is specified as an object with the
+         * following fields;
+         *
+         * 'id' : matches profile id
+         * 'title' : contains within title
+         * 'concreteClass' : contains within class name
+         *
+         */
+        memoryUsage: function () {
+            var deferred = $q.defer();
+            var self = this;
+            var url = ServerService.api('/statistics/runtime');
+            var config = ServerService.apiConfig();
+            config.params = {
+                "type": "json"
+            };
+            $http.get(url, config)
+                .success(function success(data, status, headers, config) {
+                    deferred.resolve(data, status);
+                })
+                .error(function error(data, status) {
+                    if (status == 404) {
+                        deferred.resolve(data, status);
+                    }
+                    else {
+                        deferred.reject(data, status);
+                    }
+                });
+            return deferred.promise;
+        }
+    }
+    return service;
+}
\ No newline at end of file

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js?rev=1674403&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js
(added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/jetapp/scripts/chartControllers.js
Fri Apr 17 21:09:48 2015
@@ -0,0 +1,122 @@
+/**
+ * Created by swooten on 4/6/15.
+ */
+'use strict';
+
+function bytesToSize(bytes)
+{
+    var precision = 1,
+        kilobyte = 1024,
+        megabyte = kilobyte * 1024,
+        gigabyte = megabyte * 1024,
+        terabyte = gigabyte * 1024;
+
+    var text = "";
+
+    if ((bytes >= 0) && (bytes < kilobyte))
+    {
+        text = bytes + ' B';
+    }
+    else if ((bytes >= kilobyte) && (bytes < megabyte))
+    {
+        text = (bytes / kilobyte).toFixed(precision) + ' KB';
+    }
+    else if ((bytes >= megabyte) && (bytes < gigabyte))
+    {
+        text = (bytes / megabyte).toFixed(precision) + ' MB';
+    }
+    else if ((bytes >= gigabyte) && (bytes < terabyte))
+    {
+        text = (bytes / gigabyte).toFixed(precision) + ' GB';
+    }
+    else if (bytes >= terabyte)
+    {
+        text = (bytes / terabyte).toFixed(precision) + ' TB';
+    }
+    else
+    {
+        text = bytes + ' B';
+    }
+
+    return text;
+}
+
+/* Controllers: */
+angular.module('j2admin.chartControllers', [])
+    .controller('MemoryController', function ($scope, $q, StatisticsService, PortletService)
{
+        $scope.memoryUsage = [];
+
+        // ---- init function
+        $scope.init = function () {
+
+ /*           $scope.readResourceURL = readResourceURL;
+            PortletService.lookupPreferences(readResourceURL).then(
+                function success(prefs, status) {
+                    $scope.prefs = prefs;
+                    //$scope.perPage = prefs.rowsPerPage;
+                    // $scope.columnDefs[1].displayName = (!!~prefs.service.indexOf('cpu'))
? "CPU %" : "Memory %";
+                    $scope.getData();
+
+                    if ($scope.initialized == false) {
+                        //$interval(refresh, $scope.prefs.refreshSeconds * 1000);
+                    }
+
+                    $scope.initialized = true;
+                },
+                function error(msg, status) {
+                    console.log(msg);
+                    $scope.addFailureAlert(msg, status);
+                }
+            ); */
+
+            // -- retrieve runtime memory usage
+            StatisticsService.memoryUsage().then(
+                function success(memory, status) {
+                    $scope.memoryUsage = memory;
+                    var datum = [];
+
+                    datum.push({label: "Free", value: $scope.memoryUsage.memory.free});
+                    datum.push({label: "Used", value: $scope.memoryUsage.memory.total - $scope.memoryUsage.memory.free});
+
+                    nv.addGraph(function() {
+                        var chart = nv.models.pieChart()
+                            .x(function(d) { return (d.label + ": " + bytesToSize(d.value)
+ " (" + (d.value / $scope.memoryUsage.memory.total * 100).toFixed(1) + "%)" ) })    //Specify
the data accessors.
+                            .y(function(d) { return d.value })
+                            .tooltips(false)
+                            .donut(true)
+                            .donutRatio(0.4)
+                            .showLabels(true)
+                            .donutLabelsOutside(true)
+                            .showLegend(false)
+                            .duration(500);
+
+                        d3.select(".memory-container")
+                            .datum(datum)
+                            .call(chart);
+
+                        nv.utils.windowResize(chart.update);
+
+                        var svg = d3.select("svg");
+                        var donut = svg.selectAll("g.nv-pie").filter(
+                            function (d, i) {
+                                return i == 1;
+                            });
+
+                        donut.select("text").text("new text");
+                        donut.append("text", "g")
+                            .text("Total: " + bytesToSize($scope.memoryUsage.memory.total))
+                            .attr("class","css-label-class")
+                            .attr("text-anchor", "middle");
+
+                        return chart;
+                    });
+
+                },
+                function error(msg, status) {
+                    console.log(msg);
+                    $scope.addFailureAlert(msg, status);
+                }
+            );
+        }
+    }
+);



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message