FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

add log4j and logback appenders to recording logging metrics · marcelomata/client_java@252e905 · GitHub

Repository navigation

Commit 252e905

Browse files
committed
add log4j and logback appenders to recording logging metrics
1 parent 800f7b8 commit 252e905

14 files changed

Lines changed: 482 additions & 106 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
target/
1212
simpleclient_pushgateway/mockserver.log
1313
simpleclient_pushgateway/mockserver_request.log
14+
nb-configuration.xml
15+

‎benchmark/pom.xml‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
</license>
2525
</licenses>
2626

27-
<properties>
28-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29-
</properties>
30-
3127
<dependencies>
3228
<dependency>
3329
<groupId>org.openjdk.jmh</groupId>
@@ -43,12 +39,12 @@
4339
<dependency>
4440
<groupId>io.prometheus</groupId>
4541
<artifactId>client</artifactId>
46-
<version>0.0.9-SNAPSHOT</version>
42+
<version>${project.version}</version>
4743
</dependency>
4844
<dependency>
4945
<groupId>io.prometheus</groupId>
5046
<artifactId>simpleclient</artifactId>
51-
<version>0.0.9-SNAPSHOT</version>
47+
<version>${project.version}</version>
5248
</dependency>
5349
<dependency>
5450
<groupId>com.codahale.metrics</groupId>
@@ -59,14 +55,6 @@
5955
<build>
6056
<plugins>
6157
<plugin>
62-
<artifactId>maven-compiler-plugin</artifactId>
63-
<version>3.1</version>
64-
<configuration>
65-
<source>1.6</source>
66-
<target>1.6</target>
67-
</configuration>
68-
</plugin>
69-
<plugin>
7058
<groupId>org.apache.maven.plugins</groupId>
7159
<artifactId>maven-shade-plugin</artifactId>
7260
<version>2.2</version>

‎pom.xml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,21 @@
5050
<module>simpleclient_common</module>
5151
<module>simpleclient_hotspot</module>
5252
<module>simpleclient_servlet</module>
53+
<module>simpleclient_log4j</module>
54+
<module>simpleclient_logback</module>
5355
<module>simpleclient_pushgateway</module>
5456
<module>benchmark</module>
5557
</modules>
58+
59+
<properties>
60+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
61+
62+
<maven.compiler.source>1.6</maven.compiler.source>
63+
<maven.compiler.target>1.6</maven.compiler.target>
64+
65+
<junit.version>4.11</junit.version>
66+
<mockito.version>1.9.5</mockito.version>
67+
</properties>
5668

5769
<build>
5870
<plugins>
@@ -72,6 +84,11 @@
7284
<version>2.4.0</version>
7385
<extensions>true</extensions>
7486
</plugin>
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-surefire-plugin</artifactId>
90+
<version>2.15</version>
91+
</plugin>
7592
</plugins>
7693
</build>
7794

‎simpleclient/pom.xml‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
</developer>
3434
</developers>
3535

36-
<properties>
37-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38-
</properties>
3936

4037
<dependencies>
4138
<!-- The simpleclient has no dependencies by design, so that
@@ -45,20 +42,8 @@
4542
<dependency>
4643
<groupId>junit</groupId>
4744
<artifactId>junit</artifactId>
48-
<version>4.11</version>
45+
<version>${junit.version}</version>
4946
<scope>test</scope>
5047
</dependency>
5148
</dependencies>
52-
<build>
53-
<plugins>
54-
<plugin>
55-
<artifactId>maven-compiler-plugin</artifactId>
56-
<version>3.1</version>
57-
<configuration>
58-
<source>1.6</source>
59-
<target>1.6</target>
60-
</configuration>
61-
</plugin>
62-
</plugins>
63-
</build>
6449
</project>

‎simpleclient_common/pom.xml‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,18 @@
3333
</developer>
3434
</developers>
3535

36-
<properties>
37-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38-
</properties>
39-
4036
<dependencies>
4137
<dependency>
4238
<groupId>io.prometheus</groupId>
4339
<artifactId>simpleclient</artifactId>
44-
<version>0.0.9-SNAPSHOT</version>
40+
<version>${project.version}</version>
4541
</dependency>
4642
<!-- Test Dependencies Follow -->
4743
<dependency>
4844
<groupId>junit</groupId>
4945
<artifactId>junit</artifactId>
50-
<version>4.11</version>
46+
<version>${junit.version}</version>
5147
<scope>test</scope>
5248
</dependency>
5349
</dependencies>
54-
<build>
55-
<plugins>
56-
<plugin>
57-
<artifactId>maven-compiler-plugin</artifactId>
58-
<version>3.1</version>
59-
<configuration>
60-
<source>1.6</source>
61-
<target>1.6</target>
62-
</configuration>
63-
</plugin>
64-
</plugins>
65-
</build>
6650
</project>

‎simpleclient_hotspot/pom.xml‎

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,37 @@
3333
</developer>
3434
</developers>
3535

36-
<properties>
37-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38-
</properties>
39-
4036
<dependencies>
4137
<dependency>
4238
<groupId>io.prometheus</groupId>
4339
<artifactId>simpleclient</artifactId>
44-
<version>0.0.9-SNAPSHOT</version>
40+
<version>${project.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>io.prometheus</groupId>
44+
<artifactId>simpleclient_servlet</artifactId>
45+
<version>${project.version}</version>
4546
</dependency>
47+
4648
<!-- Test Dependencies Follow -->
4749
<dependency>
4850
<groupId>junit</groupId>
4951
<artifactId>junit</artifactId>
50-
<version>4.11</version>
52+
<version>${junit.version}</version>
5153
<scope>test</scope>
5254
</dependency>
5355
<dependency>
5456
<groupId>org.mockito</groupId>
55-
<artifactId>mockito-all</artifactId>
56-
<version>1.8.4</version>
57+
<artifactId>mockito-core</artifactId>
58+
<version>${mockito.version}</version>
5759
<scope>test</scope>
5860
</dependency>
59-
<dependency>
60-
<groupId>io.prometheus</groupId>
61-
<artifactId>simpleclient_servlet</artifactId>
62-
<version>0.0.9-SNAPSHOT</version>
63-
</dependency>
61+
6462
<dependency>
6563
<groupId>org.eclipse.jetty</groupId>
6664
<artifactId>jetty-servlet</artifactId>
6765
<version>8.1.7.v20120910</version>
6866
<scope>test</scope>
6967
</dependency>
7068
</dependencies>
71-
<build>
72-
<plugins>
73-
<plugin>
74-
<artifactId>maven-compiler-plugin</artifactId>
75-
<version>3.1</version>
76-
<configuration>
77-
<source>1.6</source>
78-
<target>1.6</target>
79-
</configuration>
80-
</plugin>
81-
</plugins>
82-
</build>
8369
</project>

‎simpleclient_log4j/pom.xml‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>io.prometheus</groupId>
7+
<artifactId>parent</artifactId>
8+
<version>0.0.9-SNAPSHOT</version>
9+
</parent>
10+
11+
<groupId>io.prometheus</groupId>
12+
<artifactId>simpleclient_log4j</artifactId>
13+
<packaging>bundle</packaging>
14+
15+
<name>Prometheus Java Simpleclient log4j</name>
16+
<description>
17+
Metrics collector for log4j appender logging
18+
</description>
19+
20+
<licenses>
21+
<license>
22+
<name>The Apache Software License, Version 2.0</name>
23+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
24+
<distribution>repo</distribution>
25+
</license>
26+
</licenses>
27+
28+
<developers>
29+
<developer>
30+
<id>willfleury</id>
31+
<name>Will Fleury</name>
32+
<email>will.fleury@boxever.com</email>
33+
</developer>
34+
</developers>
35+
36+
<properties>
37+
<log4j.version>1.2.17</log4j.version>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>io.prometheus</groupId>
43+
<artifactId>simpleclient</artifactId>
44+
<version>${project.version}</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>log4j</groupId>
48+
<artifactId>log4j</artifactId>
49+
<version>${log4j.version}</version>
50+
</dependency>
51+
52+
53+
<dependency>
54+
<groupId>junit</groupId>
55+
<artifactId>junit</artifactId>
56+
<version>${junit.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.mockito</groupId>
62+
<artifactId>mockito-core</artifactId>
63+
<version>${mockito.version}</version>
64+
<scope>test</scope>
65+
</dependency>
66+
</dependencies>
67+
</project>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.prometheus.client.log4j;
2+
3+
import io.prometheus.client.Counter;
4+
import org.apache.log4j.AppenderSkeleton;
5+
import org.apache.log4j.Level;
6+
import org.apache.log4j.spi.LoggingEvent;
7+
8+
public class InstrumentedAppender extends AppenderSkeleton {
9+
10+
public static final String COUNTER_NAME = "log4j_appender_total";
11+
12+
private static final Counter COUNTER;
13+
private static final Counter.Child TRACE_LABEL;
14+
private static final Counter.Child DEBUG_LABEL;
15+
private static final Counter.Child INFO_LABEL;
16+
private static final Counter.Child WARN_LABEL;
17+
private static final Counter.Child ERROR_LABEL;
18+
private static final Counter.Child FATAL_LABEL;
19+
20+
static {
21+
COUNTER = Counter.build().name(COUNTER_NAME)
22+
.help("Log4j log statements at various log levels")
23+
.labelNames("level")
24+
.register();
25+
26+
TRACE_LABEL = COUNTER.labels("trace");
27+
DEBUG_LABEL = COUNTER.labels("debug");
28+
INFO_LABEL = COUNTER.labels("info");
29+
WARN_LABEL = COUNTER.labels("warn");
30+
ERROR_LABEL = COUNTER.labels("error");
31+
FATAL_LABEL = COUNTER.labels("fatal");
32+
}
33+
34+
/**
35+
* Create a new instrumented appender using the default registry.
36+
*/
37+
public InstrumentedAppender() {
38+
}
39+
40+
41+
@Override
42+
public void activateOptions() {
43+
}
44+
45+
@Override
46+
protected void append(LoggingEvent event) {
47+
switch (event.getLevel().toInt()) {
48+
case Level.TRACE_INT:
49+
TRACE_LABEL.inc();
50+
break;
51+
case Level.DEBUG_INT:
52+
DEBUG_LABEL.inc();
53+
break;
54+
case Level.INFO_INT:
55+
INFO_LABEL.inc();
56+
break;
57+
case Level.WARN_INT:
58+
WARN_LABEL.inc();
59+
break;
60+
case Level.ERROR_INT:
61+
ERROR_LABEL.inc();
62+
break;
63+
case Level.FATAL_INT:
64+
FATAL_LABEL.inc();
65+
break;
66+
default:
67+
break;
68+
}
69+
}
70+
71+
@Override
72+
public void close() {
73+
// nothing doing
74+
}
75+
76+
@Override
77+
public boolean requiresLayout() {
78+
return false;
79+
}
80+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL