-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What changes are proposed in this pull request? Add metric of log. pr-link: #13839 change-id: cid-4275e40e7b1e126d3375c74abd0294740cf1bbfd
- Loading branch information
1 parent
d6c6733
commit 0fba8bb
Showing
4 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
core/common/src/main/java/alluxio/metrics/EventCounter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.metrics; | ||
|
||
import org.apache.log4j.AppenderSkeleton; | ||
import org.apache.log4j.Level; | ||
import org.apache.log4j.spi.LoggingEvent; | ||
|
||
/** | ||
* A log4J Appender that simply counts logging events in four levels: | ||
* FATAL, ERROR WARN and INFO. The class name is used in log4j.properties | ||
*/ | ||
public class EventCounter extends AppenderSkeleton { | ||
private static final int FATAL = 0; | ||
private static final int ERROR = 1; | ||
private static final int WARN = 2; | ||
private static final int INFO = 3; | ||
private static EventCounter.EventCounts sCount = new EventCounter.EventCounts(); | ||
|
||
/** | ||
* The constructor of EventCounter. | ||
*/ | ||
public EventCounter() { | ||
} | ||
|
||
/** | ||
* Gets the number of fatal log. | ||
* | ||
* @return the number of fatal log | ||
*/ | ||
public static long getFatal() { | ||
return sCount.get(FATAL); | ||
} | ||
|
||
/** | ||
* Gets the number of error log. | ||
* | ||
* @return the number of error log | ||
*/ | ||
public static long getError() { | ||
return sCount.get(ERROR); | ||
} | ||
|
||
/** | ||
* Gets the number of warn log. | ||
* | ||
* @return the number of warn log | ||
*/ | ||
public static long getWarn() { | ||
return sCount.get(WARN); | ||
} | ||
|
||
/** | ||
* Gets the number of info log. | ||
* | ||
* @return the number of info log | ||
*/ | ||
public static long getInfo() { | ||
return sCount.get(INFO); | ||
} | ||
|
||
/** | ||
* Add the number of corresponding level log. | ||
* | ||
* @param event event of generating log | ||
*/ | ||
public void append(LoggingEvent event) { | ||
Level level = event.getLevel(); | ||
if (level.equals(Level.INFO)) { | ||
sCount.incr(INFO); | ||
} else if (level.equals(Level.WARN)) { | ||
sCount.incr(WARN); | ||
} else if (level.equals(Level.ERROR)) { | ||
sCount.incr(ERROR); | ||
} else if (level.equals(Level.FATAL)) { | ||
sCount.incr(FATAL); | ||
} | ||
} | ||
|
||
/** | ||
* Release any resources allocated within the appender such as file | ||
* handles, network connections, etc. | ||
*/ | ||
public void close() { | ||
} | ||
|
||
/** | ||
* Configurators call this method to determine if the appender | ||
* requires a layout. | ||
* | ||
* @return if the appender requires a layout | ||
*/ | ||
public boolean requiresLayout() { | ||
return false; | ||
} | ||
|
||
private static class EventCounts { | ||
private final long[] mCounts; | ||
|
||
private EventCounts() { | ||
mCounts = new long[]{0L, 0L, 0L, 0L}; | ||
} | ||
|
||
private synchronized void incr(int i) { | ||
mCounts[i]++; | ||
} | ||
|
||
private synchronized long get(int i) { | ||
return mCounts[i]; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
core/common/src/main/java/alluxio/metrics/LogStateCounterSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* The Alluxio Open Foundation licenses this work under the Apache License, version 2.0 | ||
* (the "License"). You may not use this work except in compliance with the License, which is | ||
* available at www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied, as more fully set forth in the License. | ||
* | ||
* See the NOTICE file distributed with this work for information regarding copyright ownership. | ||
*/ | ||
|
||
package alluxio.metrics; | ||
|
||
import com.codahale.metrics.Gauge; | ||
import com.codahale.metrics.Metric; | ||
import com.codahale.metrics.MetricSet; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* A set of counters for the log metric. | ||
*/ | ||
public class LogStateCounterSet implements MetricSet { | ||
@Override | ||
public Map<String, Metric> getMetrics() { | ||
final Map<String, Metric> gauges = new HashMap<>(); | ||
gauges.put("log.info.count", (Gauge<Long>) EventCounter::getInfo); | ||
gauges.put("log.warn.count", (Gauge<Long>) EventCounter::getWarn); | ||
gauges.put("log.error.count", (Gauge<Long>) EventCounter::getError); | ||
gauges.put("log.fatal.count", (Gauge<Long>) EventCounter::getFatal); | ||
return gauges; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters