Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example brooklyn groovy code to poll an underlying resource, to update attributes (aka sensors)
// 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 {
// etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment