Skip to content

Commit

Permalink
Merge branch 'i320-systeminfopage-1.3' into release-1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jun 2, 2011
2 parents 1798bf6 + cd5123e commit ac401a9
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 1 deletion.
127 changes: 127 additions & 0 deletions rundeckapp/grails-app/controllers/MenuController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import grails.converters.JSON
import groovy.xml.MarkupBuilder
import com.dtolabs.client.utils.Constants
import com.dtolabs.rundeck.core.authorization.Decision
import java.lang.management.ManagementFactory

class MenuController {
FrameworkService frameworkService
Expand All @@ -14,6 +15,7 @@ class MenuController {
ScheduledExecutionService scheduledExecutionService
MenuService menuService
RoleService roleService
def quartzScheduler
def list = {
def results = index(params)
render(view:"index",model:results)
Expand Down Expand Up @@ -372,6 +374,131 @@ class MenuController {
redirect(controller:'menu',action:params.fragment?'jobsFragment':'jobs',params:[compact:params.compact?'true':''])
}

def admin={

if (!roleService.isUserInAnyRoles(request, ['admin', 'user_admin'])) {
flash.error = "User Admin role required"
flash.title = "Unauthorized"
response.setStatus(403)
render(template: '/common/error', model: [:])
}
}

def systemInfo = {
if (!roleService.isUserInAnyRoles(request, ['admin', 'user_admin'])) {
flash.error = "User Admin role required"
flash.title = "Unauthorized"
response.setStatus(403)
render(template: '/common/error', model: [:])
}
Date nowDate = new Date();
String nodeName = servletContext.getAttribute("FRAMEWORK_NODE")
String appVersion = grailsApplication.metadata['app.version']
double load = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
int processorsCount = ManagementFactory.getOperatingSystemMXBean().availableProcessors
String osName = ManagementFactory.getOperatingSystemMXBean().name
String osVersion = ManagementFactory.getOperatingSystemMXBean().version
String osArch = ManagementFactory.getOperatingSystemMXBean().arch
String vmName = ManagementFactory.getRuntimeMXBean().vmName
String vmVendor = ManagementFactory.getRuntimeMXBean().vmVendor
String vmVersion = ManagementFactory.getRuntimeMXBean().vmVersion
long durationTime = ManagementFactory.getRuntimeMXBean().uptime
Date startupDate = new Date(nowDate.getTime() - durationTime)
int threadActiveCount = Thread.activeCount()
def build = grailsApplication.metadata['build.ident']
def base = servletContext.getAttribute("RDECK_BASE")

def memmax = Runtime.getRuntime().maxMemory()
def memfree = Runtime.getRuntime().freeMemory()
def memtotal = Runtime.getRuntime().totalMemory()
def schedulerRunningCount = quartzScheduler.getCurrentlyExecutingJobs().size()
def info = [
nowDate: nowDate,
nodeName: nodeName,
appVersion: appVersion,
load: load,
processorsCount: processorsCount,
osName: osName,
osVersion: osVersion,
osArch: osArch,
vmName: vmName,
vmVendor: vmVendor,
vmVersion: vmVersion,
durationTime: durationTime,
startupDate: startupDate,
threadActiveCount: threadActiveCount,
build: build,
base: base,
memmax: memmax,
memfree: memfree,
memtotal: memtotal,
schedulerRunningCount: schedulerRunningCount
]
return [systemInfo: [

[
"stats: uptime": [
duration: info.durationTime,
'duration.unit': 'ms',
datetime: g.w3cDateValue(date: info.startupDate)
]],

["stats: cpu": [

loadAverage: info.load,
'loadAverage.unit': '%',
processors: info.processorsCount
]],
["stats: memory":
[
'max.unit': 'byte',
'free.unit': 'byte',
'total.unit': 'byte',
max: info.memmax,
free: info.memfree,
total: info.memtotal,
used: info.memtotal-info.memfree,
'used.unit': 'byte',
heapusage: (info.memtotal-info.memfree)/info.memtotal,
'heapusage.unit': 'ratio',
'heapusage.info': 'Ratio of Used to Free memory within the Heap (used/total)',
allocated: (info.memtotal)/info.memmax,
'allocated.unit': 'ratio',
'allocated.info': 'Ratio of system memory allocated to maximum allowed (total/max)',
]],
["stats: scheduler":
[running: info.schedulerRunningCount]
],
["stats: threads":
[active: info.threadActiveCount]
],
[timestamp: [
// epoch: info.nowDate.getTime(), 'epoch.unit': 'ms',
datetime: g.w3cDateValue(date: info.nowDate)
]],

[rundeck:
[version: info.appVersion,
build: info.build,
node: info.nodeName,
base: info.base,
]],
[os:
[arch: info.osArch,
name: info.osName,
version: info.osVersion,
]
],
[jvm:
[
name: info.vmName,
vendor: info.vmVendor,
version: info.vmVersion
]
],
]]
}



/**
Expand Down
45 changes: 45 additions & 0 deletions rundeckapp/grails-app/taglib/UtilityTagLib.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,49 @@ class UtilityTagLib{
}
request.pageTimers=null
}
/**
* Humanize data value, based on unit attribute
*/
def humanize={attrs,body->
if(attrs.unit && null!=attrs.value){
if(attrs.unit=='byte'){
long val=attrs.value instanceof String?Long.parseLong(attrs.value):attrs.value
def testset=[
[value: 0, name: 'B'],
[value: 1024, name: 'KiB'],
[value: 1024*1024, name: 'MiB'],
[value: 1024 * 1024 * 1024, name: 'GiB'],
[value: 1024 * 1024 * 1024 * 1024, name: 'TiB'],
]
def found
testset.eachWithIndex {lvl, x -> if (!found && val < lvl.value) {found = testset[x-1]} }
if(!found){
found=testset[-1]
}
out<<g.formatNumber([number : (val/found.value), type : "number", maxFractionDigits: "2"],body)+' '+found.name
}else if(attrs.unit=='hbyte'){
long val=attrs.value instanceof String?Long.parseLong(attrs.value):attrs.value
def testset=[
[value: 0, name: 'B'],
[value: 1000, name: 'KB'],
[value: 1000* 1000, name: 'MB'],
[value: 1000 * 1000 * 1000, name: 'GB'],
[value: 1000 * 1000 * 1000 * 1000, name: 'TB'],
]
def found
testset.eachWithIndex {lvl, x -> if (!found && val < lvl.value) {found = testset[x-1]} }
if(!found){
found=testset[-1]
}
out<<g.formatNumber([number : (val/found.value), type : "number", maxFractionDigits: "2"],body)+' '+found.name
}else if(attrs.unit=='ms'){
attrs.time=attrs.value
out<<timeDuration(attrs,body)
}else if(attrs.unit=='%'){
out << g.formatNumber([number: attrs.value, type: "number", maxFractionDigits: "2"], body) + '%'
}else{
out<<attrs.value+' ('+attrs.unit+')'
}
}
}
}
2 changes: 1 addition & 1 deletion rundeckapp/grails-app/views/common/_topbar.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function doCreateProject(){
<span class="headright">

<g:ifUserInAnyRoles roles="admin,user_admin">
<g:link controller="user" action="list"><img src="${resource(dir:'images',file:'icon-small-admin.png')}" width="16px" height="16px" alt=""/>
<g:link controller="menu" action="admin"><img src="${resource(dir:'images',file:'icon-small-admin.png')}" width="16px" height="16px" alt=""/>
Admin</g:link>
</g:ifUserInAnyRoles>
<span class="logininfo">
Expand Down
56 changes: 56 additions & 0 deletions rundeckapp/grails-app/views/menu/admin.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%{--
- Copyright 2011 DTO Solutions, Inc. (http://dtosolutions.com)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--}%
<%--
admin.gsp
Author: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
Created: 6/1/11 2:22 PM
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="base"/>
<title>Administration</title>
</head>

<body>

<div class="pageTop">
<div class="floatl">
<span class="welcomeMessage">Administration</span>
</div>

<div class="clear"></div>
</div>

<div class="pageBody">
<ul>
<li>
<g:link controller="menu" action="systemInfo">
<g:message code="gui.menu.SystemInfo" default="System Information"/>
</g:link>
</li>
<li>
<g:link controller="user" action="list">
<g:message code="gui.menu.SystemInfo" default="User Profiles"/>
</g:link>
</li>
</ul>
</div>
</body>
</html>
92 changes: 92 additions & 0 deletions rundeckapp/grails-app/views/menu/systemInfo.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
%{--
- Copyright 2011 DTO Solutions, Inc. (http://dtosolutions.com)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--}%
<%--
systemInfo.gsp
Author: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
Created: 6/1/11 9:44 AM
--%>

<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="base"/>
<title>System Info</title>
</head>

<body>

<div class="pageTop">
<div class="floatl">
<span class="welcomeMessage">System Info</span>
</div>

<div class="clear"></div>
</div>

<div class="pageBody">

<g:set var="datapercol" value="${5.0}"/>
<g:set var="colcount" value="${(int)Math.ceil((float)systemInfo.size()/datapercol)}"/>
<table>
<tr>
<g:each in="${0..colcount-1}" var="colnum">
<g:set var="colstart" value="${(int)(colnum)*datapercol}"/>
<g:set var="colmax" value="${(int)(colnum+1)*datapercol-1}"/>
<g:set var="coldata"
value="${systemInfo[colstart..(colmax<systemInfo.size?colmax:systemInfo.size-1)]}"/>
<td style="vertical-align: top;">
<table class="simpleForm">
<g:each in="${coldata}" var="dataset">
<g:each in="${dataset.keySet().sort()}" var="dataname">
<g:if test="${dataset[dataname] instanceof Map}">
<tbody>
<th colspan="2">${dataname.encodeAsHTML()}</th>
<g:each
in="${dataset[dataname].keySet().sort().grep{!it.endsWith('.unit') && !it.endsWith('.info')}}"
var="valuename">
<tr>
<td title="${dataset[dataname][valuename + '.info'] ? dataset[dataname][valuename + '.info'].encodeAsHTML() : ''}">${valuename.encodeAsHTML()}</td>
<td>

<g:if test="${dataset[dataname][valuename+'.unit']=='ratio'}">
<g:render template="/common/progressBar"
model="${[completePercent:(int)(100*dataset[dataname][valuename]),title:dataset[dataname][valuename+'.info']?dataset[dataname][valuename+'.info']:dataset[dataname][valuename],className:'',showpercent:true]}"/>
</g:if>
<g:elseif test="${dataset[dataname][valuename+'.unit']}">
<g:humanize value="${dataset[dataname][valuename]}"
unit="${dataset[dataname][valuename+'.unit']}"/>
</g:elseif>
<g:else>
${dataset[dataname][valuename].encodeAsHTML()}
</g:else>
</td>
</tr>

</g:each>
</tbody>
</g:if>
</g:each>
</g:each>
</table>
</td>
</g:each>
</tr>
</table>
</div>
</body>
</html>

0 comments on commit ac401a9

Please sign in to comment.