private Map<String,Object> getHealthMetrics(AppdynamicsApplication application, String instanceUrl ) {
        // business health percent
        long numNodeViolations = 0;
        long numBusinessViolations = 0;
        long numNodes = 0;
        long numBusinessTransactions = 0;
        double nodeHealthPercent = 0.0;
        double businessHealthPercent = 0.0;

        Map<String,Object> healthMetrics = new HashMap<>();

        try {
            // GET NUMBER OF VIOLATIONS OF EACH TYPE
            String url = joinURL(instanceUrl, String.format(HEALTH_VIOLATIONS_PATH, application.getAppID()));
            ResponseEntity<String> responseEntity = makeRestCall(url);
            String returnJSON = responseEntity.getBody();
            JSONParser parser = new JSONParser();

            JSONArray array = (JSONArray) parser.parse(returnJSON);

            for (Object entry : array) {

                JSONObject jsonEntry = (JSONObject) entry;

                if (getString(jsonEntry, "incidentStatus").equals("RESOLVED"))
                    continue;

                JSONObject affEntityObj = (JSONObject) jsonEntry.get("affectedEntityDefinition");

                String entityType = getString(affEntityObj, "entityType");

                if (entityType.equals("APPLICATION_COMPONENT_NODE")) {
                    numNodeViolations++;

                } else if (entityType.equals(BUSINESS_TRANSACTION)) {
                    numBusinessViolations++;

                }
            }


            // GET NUMBER OF NODES
            url = joinURL(instanceUrl, String.format(NODE_LIST_PATH, application.getAppID()));
            responseEntity = makeRestCall(url);
            returnJSON = responseEntity.getBody();
            parser = new JSONParser();
            array = (JSONArray) parser.parse(returnJSON);

            numNodes = array.size();

            // GET NUMBER OF BUSINESS TRANSACTIONS
            url = joinURL(instanceUrl, String.format(BUSINESS_TRANSACTION_LIST_PATH, application.getAppID()));
            responseEntity = makeRestCall(url);
            returnJSON = responseEntity.getBody();
            parser = new JSONParser();
            array = (JSONArray) parser.parse(returnJSON);

            numBusinessTransactions = array.size();

        } catch (MalformedURLException e) {
            LOG.error("client exception loading applications", e);
        } catch (ParseException e) {
            LOG.error("client exception loading applications", e);
        }

        // Node health percent is just 1 - (num node violations / num nodes)
        if (numNodes != 0)
            nodeHealthPercent = Math.floor(100.0 * (1.0 - ((double) (numNodeViolations) / (double) (numNodes)))) / 100.0;

        // Right now the timeframe is hard-coded to 15 min. Change this if that changes.
        healthMetrics.put(NODE_HEALTH_PECENT,nodeHealthPercent);

        // Business health percent is just 1 - (num business transaction violations / num business transactions)
        if (numBusinessTransactions != 0)
            businessHealthPercent = Math.floor(100.0 * (1.0 - ((double) (numBusinessViolations) / (double) (numBusinessTransactions)))) / 100.0;
        healthMetrics.put(BUSINESS_TRANSACTION_HEALTH,businessHealthPercent);

        return healthMetrics;
    }
private Map < String , Object > getHealthMetrics ( AppdynamicsApplication application , String instanceUrl ) { long numNodeViolations = 0 ; long numBusinessViolations = 0 ; long numNodes = 0 ; long numBusinessTransactions = 0 ; double nodeHealthPercent = 0.0 ; double businessHealthPercent = 0.0 ; Map < String , Object > healthMetrics = new HashMap < > ( ) ; try { String url = joinURL ( instanceUrl , String . format ( HEALTH_VIOLATIONS_PATH , application . getAppID ( ) ) ) ; ResponseEntity < String > responseEntity = makeRestCall ( url ) ; String returnJSON = responseEntity . getBody ( ) ; JSONParser parser = new JSONParser ( ) ; JSONArray array = ( JSONArray ) parser . parse ( returnJSON ) ; for ( Object entry : array ) { JSONObject jsonEntry = ( JSONObject ) entry ; if ( getString ( jsonEntry , "incidentStatus" ) . equals ( "RESOLVED" ) ) continue ; JSONObject affEntityObj = ( JSONObject ) jsonEntry . get ( "affectedEntityDefinition" ) ; String entityType = getString ( affEntityObj , "entityType" ) ; if ( entityType . equals ( "APPLICATION_COMPONENT_NODE" ) ) { numNodeViolations ++ ; } else if ( entityType . equals ( BUSINESS_TRANSACTION ) ) { numBusinessViolations ++ ; } } url = joinURL ( instanceUrl , String . format ( NODE_LIST_PATH , application . getAppID ( ) ) ) ; responseEntity = makeRestCall ( url ) ; returnJSON = responseEntity . getBody ( ) ; parser = new JSONParser ( ) ; array = ( JSONArray ) parser . parse ( returnJSON ) ; numNodes = array . size ( ) ; url = joinURL ( instanceUrl , String . format ( BUSINESS_TRANSACTION_LIST_PATH , application . getAppID ( ) ) ) ; responseEntity = makeRestCall ( url ) ; returnJSON = responseEntity . getBody ( ) ; parser = new JSONParser ( ) ; array = ( JSONArray ) parser . parse ( returnJSON ) ; numBusinessTransactions = array . size ( ) ; } catch ( MalformedURLException e ) { LOG . error ( "client exception loading applications" , e ) ; } catch ( ParseException e ) { LOG . error ( "client exception loading applications" , e ) ; } if ( numNodes != 0 ) nodeHealthPercent = Math . floor ( 100.0 * ( 1.0 - ( ( double ) ( numNodeViolations ) / ( double ) ( numNodes ) ) ) ) / 100.0 ; healthMetrics . put ( NODE_HEALTH_PECENT , nodeHealthPercent ) ; if ( numBusinessTransactions != 0 ) businessHealthPercent = Math . floor ( 100.0 * ( 1.0 - ( ( double ) ( numBusinessViolations ) / ( double ) ( numBusinessTransactions ) ) ) ) / 100.0 ; healthMetrics . put ( BUSINESS_TRANSACTION_HEALTH , businessHealthPercent ) ; return healthMetrics ; }
Calculates the Node Health Percent and Business Health Percent values
@param application the current application. Used to provide access to appID/name
@return List of two PerformanceMetrics that contain info about the health percents