Package com.newrelic.org.json.simple

Examples of com.newrelic.org.json.simple.JSONObject


    long begin = System.currentTimeMillis();
    operations.getAndIncrement();
    try {
      if (debug)
        System.out.println(msg.toString());
      JSONObject json = (JSONObject)new JSONParser().parse(msg.toString());
             
      JSONObject timespent = (JSONObject) json.get("timespent");
      int calls = json.containsKey("calls") ? ((Long)json.get("calls")).intValue() : 1;
     
      if(timespent != null){
        String pathTmp = json.containsKey("path") ? (String)json.get("path") : "-";
        String path = !pathTmp.startsWith("/") ? "/"+pathTmp: pathTmp;
        String method = json.containsKey("httpMethod") ? (String)json.get("httpMethod") : "-";
        long status = json.containsKey("httpStatus") ? (Long)json.get("httpStatus") : 999;
        long totaltime = 0;
 
        for (Object key : timespent.keySet()) {
          Object timeObj = timespent.get(key);
          Long time = 0L;
         
          if (timeObj instanceof Double) {
            time = (long) (((Double) timeObj)*1000);         
          } else if (timeObj instanceof Long) {
            Long t = (Long)timeObj;
            //si el numero es muy grande, entonces asume que el time esta en epoch y es el tiempo de inicio del request.
            if (t > 1000000000) {
              time = begin - (t/1000);
            } else {
              time = t;
            }
          } else if (timeObj instanceof String) {
            try {
              synchronized (sdf) {
                Date requestTime = sdf.parse((String) timeObj);
                time = begin - requestTime.getTime();
              }
            } catch (ParseException e) {
              reportParserError(msg.toString(), e);
              return;
            }       
          }
         
          totaltime += time;
          for (int i = 0; i < calls; i++) {
            if ("WEB_TRANSACTION_EXTERNAL_ALL".equals(key) || "External/allWeb".equals(key)) {
              StatsEngine.getResponseTimeStats("External/allWeb").recordResponseTime(time);             
            } else if ("URI_WEB_TRANSACTION".equals(key) || "WebTransaction/Uri".equals(key)) {
              StatsEngine.getResponseTimeStats("WebTransaction/Uri"+ path).recordResponseTime(time);         
              StatsEngine.getApdexStats(MetricSpec.lookup(MetricNames.APDEX + "/Uri" + path)).recordApdexResponseTime(time);
            } else {
              StatsEngine.getResponseTimeStats((String)key).recordResponseTime(time);
            }
          }
        }
       
        for (int i = 0; i < calls; i++) {
          StatsEngine.getResponseTimeStats(MetricSpec.DISPATCHER).recordResponseTime(totaltime);
          StatsEngine.getApdexStats(MetricSpec.APDEX).recordApdexResponseTime(totaltime);
        }
         
        boolean failed = ((status < 200) || (status > 399));
        if (failed) {
          for (int i = 0; i < calls; i++) {
            reportAppError(json, status, path, msg.toString());
          }
        }
      }
       
        JSONArray customMetrics = (JSONArray) json.get("custom_metric");
      if (customMetrics != null) {
        for (Object key : customMetrics) {
          JSONObject metric = (JSONObject)key;
             
          String name = (String) metric.get("name");
          String type = (String) metric.get("type");
          Object value = metric.get("value");
          if (type.equals("counter")) {
            if (value instanceof Double) {
              StatsEngine.getStats("/Custom/"+name).incrementCallCount(((Double)value).intValue()*calls);         
            } else if (value instanceof Long) {
              StatsEngine.getStats("/Custom/"+name).incrementCallCount(((Long)value).intValue()*calls);
 
View Full Code Here

TOP

Related Classes of com.newrelic.org.json.simple.JSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.