chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject svn commit: r1054355 - in /incubator/chukwa/trunk: CHANGES.txt src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
Date Sun, 02 Jan 2011 05:36:32 GMT
Author: eyang
Date: Sun Jan  2 05:36:32 2011
New Revision: 1054355

URL: http://svn.apache.org/viewvc?rev=1054355&view=rev
Log:
CHUKWA-574. Added locking for recording metrics through log4j. (Eric Yang)

Modified:
    incubator/chukwa/trunk/CHANGES.txt
    incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java

Modified: incubator/chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/CHANGES.txt?rev=1054355&r1=1054354&r2=1054355&view=diff
==============================================================================
--- incubator/chukwa/trunk/CHANGES.txt (original)
+++ incubator/chukwa/trunk/CHANGES.txt Sun Jan  2 05:36:32 2011
@@ -82,6 +82,8 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    CHUKWA-574. Added locking for recording metrics through log4j. (Eric Yang)
+
     CHUKWA-568.  Moved from json.jar library to JSON Simple library for SystemMetrics demux
parser and add tags column family. (Eric Yang)
 
     CHUKWA-231. Update default view to show graph explorer and remove deprecated widgets.
(Eric Yang)

Modified: incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
URL: http://svn.apache.org/viewvc/incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java?rev=1054355&r1=1054354&r2=1054355&view=diff
==============================================================================
--- incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
(original)
+++ incubator/chukwa/trunk/src/java/org/apache/hadoop/chukwa/inputtools/log4j/Log4JMetricsContext.java
Sun Jan  2 05:36:32 2011
@@ -84,41 +84,37 @@ public class Log4JMetricsContext extends
   @Override
   protected void emitRecord(String contextName, String recordName,
       OutputRecord outRec) throws IOException {
-    if (out == null) {
-      synchronized (lock) {
-        if (out == null) {
-          PatternLayout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n");
+    synchronized (lock) {
+      if (out == null) {
+        PatternLayout layout = new PatternLayout("%d{ISO8601} %p %c: %m%n");
           
-          org.apache.log4j.net.SocketAppender appender = new org.apache.log4j.net.SocketAppender(host,
port);
+        org.apache.log4j.net.SocketAppender appender = new org.apache.log4j.net.SocketAppender(host,
port);
           
-          appender.setName("chukwa.metrics." + contextName);
-          appender.setLayout(layout);
+        appender.setName("chukwa.metrics." + contextName);
+        appender.setLayout(layout);
           
-          Logger logger = Logger.getLogger("chukwa.metrics." + contextName);
-          logger.setAdditivity(false);
-          logger.addAppender(appender);
-          appender.activateOptions();
-          out = logger;
-        }
-      }
-    }
-
-    JSONObject json = new JSONObject();
-    try {
-      json.put("contextName", contextName);
-      json.put("recordName", recordName);
-      json.put("chukwa_timestamp", System.currentTimeMillis());
-      json.put("period", period);
-      for (String tagName : outRec.getTagNames()) {
-        json.put(tagName, outRec.getTag(tagName));
+        Logger logger = Logger.getLogger("chukwa.metrics." + contextName);
+        logger.setAdditivity(false);
+        logger.addAppender(appender);
+        appender.activateOptions();
+        out = logger;
       }
-      for (String metricName : outRec.getMetricNames()) {
-        json.put(metricName, outRec.getMetric(metricName));
+      JSONObject json = new JSONObject();
+      try {
+        json.put("contextName", contextName);
+        json.put("recordName", recordName);
+        json.put("chukwa_timestamp", System.currentTimeMillis());
+        json.put("period", period);
+        for (String tagName : outRec.getTagNames()) {
+          json.put(tagName, outRec.getTag(tagName));
+        }
+        for (String metricName : outRec.getMetricNames()) {
+          json.put(metricName, outRec.getMetric(metricName));
+        }
+      } catch (Exception e) {
+        log.warn("exception in Log4jMetricsContext:" , e);
       }
-    } catch (Exception e) {
-      log.warn("exception in Log4jMetricsContext:" , e);
+      out.info(json.toString());
     }
-    out.info(json.toString());
   }
-
 }



Mime
View raw message