Skip to content

Instantly share code, notes, and snippets.

@aledsage
Created December 14, 2012 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aledsage/4284263 to your computer and use it in GitHub Desktop.
Save aledsage/4284263 to your computer and use it in GitHub Desktop.
Proposed "feeds" for polling an underlying resource for populating brooklyn attributes
// FROM JBOSS AS 7, polling its http management api
@Override
protected void connectSensors() {
super.connectSensors();
httpFeed = HttpFeed.builder()
.entity(this)
.period(200)
.baseUri(String.format("http://%s:%s/management/subsystem/web/connector/http/read-resource", host, port))
.baseUriVars(ImmutableMap.of("include-runtime","true"))
.poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS)
.onSuccess(HttpValueFunctions.responseCode()))
.poll(new HttpPollConfig<Boolean>(SERVICE_UP)
.onSuccess(HttpValueFunctions.responseCodeEquals(200)))
.poll(new HttpPollConfig<Integer>(REQUEST_COUNT)
.onSuccess(HttpValueFunctions.jsonContents("requestCount", Integer.class)))
.poll(new HttpPollConfig<Integer>(ERROR_COUNT)
.onSuccess(HttpValueFunctions.jsonContents("errorCount", Integer.class)))
.poll(new HttpPollConfig<Integer>(TOTAL_PROCESSING_TIME)
.onSuccess(HttpValueFunctions.jsonContents("processingTime", Integer.class)))
.poll(new HttpPollConfig<Integer>(MAX_PROCESSING_TIME)
.onSuccess(HttpValueFunctions.jsonContents("maxTime", Integer.class)))
.poll(new HttpPollConfig<Long>(BYTES_RECEIVED)
.onSuccess(HttpValueFunctions.jsonContents("bytesReceived", Long.class)))
.poll(new HttpPollConfig<Long>(BYTES_SENT)
.onSuccess(HttpValueFunctions.jsonContents("bytesSent", Long.class)))
.build();
}
@Override
protected void disconnectSensors() {
super.disconnectSensors();
if (httpFeed != null) httpFeed.stop();
}
// ===
// FROM JBOSS AS 6, POLLING ITS JMX API
@Override
public void connectSensors() {
super.connectSensors();
String requestProcessorMbeanName = "jboss.web:type=GlobalRequestProcessor,name=http-*";
String serverMbeanName = "jboss.system:type=Server";
jmxFeed = JmxFeed.builder()
.entity(this)
.period(500, TimeUnit.MILLISECONDS)
.pollAttribute(new JmxAttributePollConfig<Integer>(ERROR_COUNT)
.objectName(requestProcessorMbeanName)
.attributeName("errorCount"))
.pollAttribute(new JmxAttributePollConfig<Integer>(REQUEST_COUNT)
.objectName(requestProcessorMbeanName)
.attributeName("requestCount"))
.pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME)
.objectName(requestProcessorMbeanName)
.attributeName("processingTime"))
.pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP)
.objectName(serverMbeanName)
.attributeName("Started")
.onError(Functions.constant(false)))
.build();
}
@Override
public void disconnectSensors() {
super.disconnectSensors();
if (jmxFeed != null) jmxFeed.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment