Skip to content

Commit

Permalink
Merge branch 'i261-statsapi-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 7656a0e + 7f882fa commit e44389e
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 0 deletions.
152 changes: 152 additions & 0 deletions docs/en/09-api/01-chapter10.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,158 @@ When an API path declares its results as an "Item List" this is the format that
API Contents
-----

### System Info ###

Get RunDeck server information and stats.

URL:

/system/info

Parameters: none

Result: Success response, with included system info and stats in this format:

<system>
<timestamp epoch="1305909785806" unit="ms">
<datetime>2011-05-20T16:43:05Z</datetime>
</timestamp>
<rundeck>
<version>1.2.1</version>
<build>1.2.1-0-beta</build>
<node>Venkman.local</node>
<base>/Users/greg/rundeck121</base>
</rundeck>
<os>
<arch>x86_64</arch>
<name>Mac OS X</name>
<version>10.6.7</version>
</os>
<jvm>
<name>Java HotSpot(TM) 64-Bit Server VM</name>
<vendor>Apple Inc.</vendor>
<version>19.1-b02-334</version>
</jvm>
<stats>
<uptime duration="300584" unit="ms">
<since epoch="1305909485222" unit="ms">
<datetime>2011-05-20T16:38:05Z</datetime>
</since>
</uptime>
<cpu>
<loadAverage unit="percent">0.40234375</loadAverage>
<processors>4</processors>
</cpu>
<memory unit="byte">
<max>477233152</max>
<free>76626216</free>
<total>257163264</total>
</memory>
<scheduler>
<running>0</running>
</scheduler>
<threads>
<active>24</active>
</threads>
</stats>
</system>

Description of included elements:

`timestamp` describes the current system time known to the server. The `@epoch`
attribute includes the milliseconds since the unix epoch.

`datetime`

: The W3C date and time

`rundeck` includes information about the RunDeck application.

`rundeck/version`

: RunDeck version

`rundeck/build`

: RunDeck build stamp

`rundeck/node`

: Server node name

`rundeck/base`

: Server base directory

`os/arch`

: Operating System architecture

`os/name`

: Operating System Name

`os/version`

: Operating System Version

`jvm/name`

: JVM name

`jvm/vendor`

: JVM vendor

`jvm/version`

: JVM version

`stats` section includes some system statistics:

`uptime` describes the JVM uptime as duration in ms, and includes absolute
startup time:

`uptime/since`

: JVM startup time as time since the unix epoch

`uptime/since/datetime`

: JVM startup time as W3C date time.

`cpu/loadAverage`

: JVM load average percentage for the system for the previous minute (see [getSystemLoadAverage](http://download.oracle.com/javase/6/docs/api/java/lang/management/OperatingSystemMXBean.html#getSystemLoadAverage()))

`cpu/processors`

: Number of available system processors. note that loadAverage might be
calculated based on the total number of available processors

The `memory` section describes memory usage in bytes:

`max`

: Maximum JVM memory that can be allocated

`free`

: Free memory of the allocated memory

`total`

: Total allocated memory for the JVM

`scheduler/running`

: Number of running jobs in the scheduler

`threads/active`

: Number of active Threads in the JVM


### Listing Jobs ###

List the jobs that exist for a project.
Expand Down
1 change: 1 addition & 0 deletions rundeckapp/grails-app/conf/UrlMappings.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UrlMappings {
"/api/$api_version/resource/$name"(controller: 'framework', action: 'apiResource')
"/api/$api_version/run/command"(controller: 'scheduledExecution', action: 'apiRunCommand')
"/api/$api_version/run/script"(controller: 'scheduledExecution', action: 'apiRunScript')
"/api/$api_version/system/info"(controller: 'api', action: 'apiSystemInfo')
"/api/$api_version/$action?"(controller: 'api', action: 'invalid')

//simplified url mappings for link generation
Expand Down
76 changes: 76 additions & 0 deletions rundeckapp/grails-app/controllers/ApiController.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import java.lang.management.ManagementFactory

/**
* Contains utility actions for API access and responses
*/
class ApiController {
def defaultAction = "invalid"
def quartzScheduler

def invalid = {
response.setStatus(404)
Expand Down Expand Up @@ -75,4 +78,77 @@ class ApiController {
}
}

/**
* API endpoints
*/

/**
* /api/1/system/info: display stats and info about the server
*/
def apiSystemInfo={
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()
return success { delegate ->
delegate.'success' {
message("System Stats for RunDeck ${appVersion} on node ${nodeName}")
}
delegate.'system'{
timestamp(epoch:nowDate.getTime(),unit:'ms'){
datetime(g.w3cDateValue(date:nowDate))
}
rundeck{
version(appVersion)
build(grailsApplication.metadata['build.ident'])
node(nodeName)
base(servletContext.getAttribute("RDECK_BASE"))
}
os {
arch(osArch)
name(osName)
version(osVersion)
}
jvm {
name(vmName)
vendor(vmVendor)
version(vmVersion)
}
stats{
uptime(duration:durationTime,unit: 'ms'){
since(epoch: startupDate.getTime(),unit:'ms'){
datetime(g.w3cDateValue(date: startupDate))
}
}
// errorCount('12')
// requestCount('12')
cpu{
loadAverage(unit:'percent',load)
processors(processorsCount)
}
memory(unit:'byte'){
max(Runtime.getRuntime().maxMemory())
free(Runtime.getRuntime().freeMemory())
total(Runtime.getRuntime().totalMemory())
}
scheduler{
running(quartzScheduler.getCurrentlyExecutingJobs().size())
}
threads{
active(threadActiveCount)
}
}
}
}
}
}

0 comments on commit e44389e

Please sign in to comment.