protected void connectSensors()

in software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java [65:127]


    protected void connectSensors() {
        super.connectSensors();

        HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this,
                getAttribute(MANAGEMENT_HTTP_PORT) + getConfig(PORT_INCREMENT));
        
        String managementUri = String.format("http://%s:%s/management/subsystem/web/connector/http/read-resource",
                hp.getHost(), hp.getPort());
        sensors().set(MANAGEMENT_URL, managementUri);

        if (isHttpMonitoringEnabled()) {
            log.debug("JBoss sensors for "+this+" reading from "+managementUri);
            Map<String, String> includeRuntimeUriVars = ImmutableMap.of("include-runtime","true");
            boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS);

            httpFeed = HttpFeed.builder()
                    .entity(this)
                    .period(200)
                    .baseUri(managementUri)
                    .credentials(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD))
                    .poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS)
                            .onSuccess(HttpValueFunctions.responseCode())
                            .suppressDuplicates(true))
                    .poll(new HttpPollConfig<Boolean>(MANAGEMENT_URL_UP)
                            .onSuccess(HttpValueFunctions.responseCodeEquals(200))
                            .onFailureOrException(Functions.constant(false))
                            .suppressDuplicates(true))
                    .poll(new HttpPollConfig<Integer>(REQUEST_COUNT)
                            .vars(includeRuntimeUriVars)
                            .onSuccess(HttpValueFunctions.jsonContents("requestCount", Integer.class))
                            .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))
                            .enabled(retrieveUsageMetrics))
                    .poll(new HttpPollConfig<Integer>(ERROR_COUNT)
                            .vars(includeRuntimeUriVars)
                            .onSuccess(HttpValueFunctions.jsonContents("errorCount", Integer.class))
                            .enabled(retrieveUsageMetrics))
                    .poll(new HttpPollConfig<Integer>(TOTAL_PROCESSING_TIME)
                            .vars(includeRuntimeUriVars)
                            .onSuccess(HttpValueFunctions.jsonContents("processingTime", Integer.class))
                            .enabled(retrieveUsageMetrics))
                    .poll(new HttpPollConfig<Integer>(MAX_PROCESSING_TIME)
                            .vars(includeRuntimeUriVars)
                            .onSuccess(HttpValueFunctions.jsonContents("maxTime", Integer.class))
                            .enabled(retrieveUsageMetrics))
                    .poll(new HttpPollConfig<Long>(BYTES_RECEIVED)
                            .vars(includeRuntimeUriVars)
                            // jboss seems to report 0 even if it has received lots of requests; dunno why.
                            .onSuccess(HttpValueFunctions.jsonContents("bytesReceived", Long.class))
                            .enabled(retrieveUsageMetrics))
                    .poll(new HttpPollConfig<Long>(BYTES_SENT)
                            .vars(includeRuntimeUriVars)
                            .onSuccess(HttpValueFunctions.jsonContents("bytesSent", Long.class))
                            .enabled(retrieveUsageMetrics))
                    .build();
            
            enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS)
                    .from(MANAGEMENT_URL_UP)
                    .computing(Functionals.ifNotEquals(true).value("Management URL not reachable") )
                    .build());
        }
        
        connectServiceUpIsRunning();
    }