Created
July 16, 2012 10:31
-
-
Save aledsage/3122026 to your computer and use it in GitHub Desktop.
Example brooklyn groovy code to poll an underlying resource, to update attributes (aka sensors)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Polls a given URL, and uses the HTTP response to set the | |
// two Brooklyn entity attributes SERVICE_UP and REQUEST_COUNT | |
def http = sensorRegistry.register( | |
new HttpSensorAdapter("http://$host:$port/management/subsystem/web/connector/http/read-resource", | |
period: 200*TimeUnit.MILLISECONDS). | |
vars("include-runtime":true) ) | |
with(http) { | |
poll(SERVICE_UP) { responseCode==200 } | |
poll(REQUEST_COUNT) { json.requestCount } | |
// etc | |
} | |
// Subscribes to JMX attribute-change events for given attributes on an given MBean, | |
// to set the Brooklyn entity attributes ERROR_COUNT and REQUEST_COUNT | |
JmxSensorAdapter jmx = sensorRegistry.register(new JmxSensorAdapter(period: 500*TimeUnit.MILLISECONDS)); | |
jmx.objectName("jboss.web:type=GlobalRequestProcessor,name=http-*").with { | |
attribute("errorCount").subscribe(ERROR_COUNT) | |
attribute("requestCount").subscribe(REQUEST_COUNT) | |
// etc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment