You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a collection of support libraries for Java applications running on Cloud Foundry that serve two main purposes: It provides (a) means to emit *structured application log messages* and (b) instrument parts of your application stack to *collect request metrics*.
6
+
This is a collection of support libraries for Java applications running on Cloud Foundry that serves three main purposes: It provides (a) means to emit *structured application log messages*, (b) instrument parts of your application stack to *collect request metrics* and (c) java clients for producing *custom metrics*.
7
7
8
-
When we say structured, we actually mean in JSON format. In that sense, it shares ideas with [logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) (and a first internal version was actually based on it), but takes a simpler approach as we want to ensure that these structured messages adhere to standardized formats. With such standardized formats in place, it becomes much easier to ingest, process and search such messages in log analysis stacks like, e.g.,[ELK](https://www.elastic.co/webinars/introduction-elk-stack).
8
+
When we say structured, we actually mean in JSON format. In that sense, it shares ideas with [logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) (and a first internal version was actually based on it), but takes a simpler approach as we want to ensure that these structured messages adhere to standardized formats. With such standardized formats in place, it becomes much easier to ingest, process and search such messages in log analysis stacks such as[ELK](https://www.elastic.co/webinars/introduction-elk-stack).
9
9
10
-
If you're interested in the specifications of these standardized formats, you may want to have closer look at the `fields.yml` files in the [beats folder](./cf-java-logging-support-core/beats).
10
+
If you're interested in the specifications of these standardized formats, you may want to have a closer look at the `fields.yml` files in the [beats folder](./cf-java-logging-support-core/beats).
11
11
12
-
While [logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) is tied to [logback](http://logback.qos.ch/), we've tried to stay implementation neutral and have implemented the core functionality on top of [slf4j](http://www.slf4j.org/), but provide implementations for both [logback](http://logback.qos.ch/) and [log4j2](http://logging.apache.org/log4j/2.x/) (and we're open to contributions that would support other implementations).
12
+
While [logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder) is tied to [logback](http://logback.qos.ch/), we've tried to keep implementation neutral and have implemented the core functionality on top of [slf4j](http://www.slf4j.org/), but provided implementations for both [logback](http://logback.qos.ch/) and [log4j2](http://logging.apache.org/log4j/2.x/) (and we're open to contributions that would support other implementations).
13
13
14
14
The instrumentation part is currently focusing on providing [request filters for Java Servlets](http://www.oracle.com/technetwork/java/filters-137243.html) and [client and server filters for Jersey](https://jersey.java.net/documentation/latest/filters-and-interceptors.html), but again, we're open to contributions for other APIs and frameworks.
15
15
16
-
Last, there are also two sibling projects on [node.js logging support](https://github.com/SAP/cf-nodejs-logging-support) and [python logging support](https://github.com/SAP/cf-python-logging-support).
16
+
The custom metrics clients part allows users to easily define and push custom metrics. The clients configure all necessary components and make it possible to define custom metrics with minimal code change.
17
+
18
+
Lastly, there are also two sibling projects on [node.js logging support](https://github.com/SAP/cf-nodejs-logging-support) and [python logging support](https://github.com/SAP/cf-python-logging-support).
17
19
18
20
## Features and dependencies
19
21
20
22
As you can see from the structure of this repository, we're not providing one *uber* JAR that contains everything, but provide each feature separately. We also try to stay away from wiring up too many dependencies by tagging almost all of them as *provided.* As a consequence, it's your task to get all runtime dependencies resolved in your application POM file.
21
23
22
24
All in all, you should do the following:
23
25
24
-
* make up your mind which features you actually need,
25
-
* adjust your Maven dependencies accordingly,
26
-
* pick your favorite logging implementation, and
27
-
* adjust your logging configuration accordingly.
26
+
1. Make up your mind which features you actually need.
27
+
2. Adjust your Maven dependencies accordingly.
28
+
3. Pick your favorite logging implementation.
29
+
And
30
+
4. Adjust your logging configuration accordingly.
28
31
29
32
30
-
Say, you want to make use of the *servlet filter* feature, then you need to add the following dependency to your POM with property `cf-logging-version` referring to the latest nexus version (currently `2.2.3`):
33
+
Let's say you want to make use of the *servlet filter* feature, then you need to add the following dependency to your POM with property `cf-logging-version` referring to the latest nexus version (currently `2.2.3`):
31
34
32
35
```xml
33
36
<properties>
@@ -48,9 +51,20 @@ Say, you want to make use of the *servlet filter* feature, then you need to add
48
51
49
52
This feature only depends on the servlet API which you have included in your POM anyhow. You can find more information about the *servlet filter* feature (like e.g. how to adjust the web.xml) in the [Wiki](https://github.com/SAP/cf-java-logging-support/wiki/Instrumenting-Servlets).
50
53
54
+
If you want to use the `custom metrics``spring-boot client`, just define the following dependency:
## Implementation variants and logging configurations
52
66
53
-
The *core* feature (on which all other features rely) is just using the `org.slf4j` API, but to actually get logs written, you need to pick an implementation feature. As stated above, we have two implementations
67
+
The *core* feature (on which all other features rely) is just using the `org.slf4j` API, but to actually get logs written, you need to pick an implementation feature. As stated above, we have two implementations:
54
68
55
69
*`cf-java-logging-support-logback` based on [logback](http://logback.qos.ch/), and
56
70
*`cf-java-logging-support-log4j2` based on [log4j2](http://logging.apache.org/log4j/2.x/).
@@ -93,9 +107,9 @@ Again, we don't include dependencies to those implementation backends ourselves,
93
107
</dependency>
94
108
```
95
109
96
-
As they have slightly different ways to do configuration, you again need to do that yourself. But we hope that we've found an easy way to accomplish that. The one thing you have to do is pick our *encoder* in your `logback.xml` if you're using `logback` or our `layout` in your `log4j2.xml`if you're using `log4j2`.
110
+
As they have slightly differ in configuration, you again will need to do that yourself. But we hope that we've found an easy way to accomplish that. The one thing you have to do is pick our *encoder* in your `logback.xml` if you're using `logback` or our `layout` in your `log4j2.xml`if you're using `log4j2`.
97
111
98
-
Here are sort of the minimal configurations you'd need:
112
+
Here are the minimal configurations you'd need:
99
113
100
114
*logback.xml*:
101
115
@@ -144,6 +158,92 @@ Here are sort of the minimal configurations you'd need:
144
158
</Configuration>
145
159
```
146
160
161
+
## Custom metrics client usage
162
+
163
+
With the custom metrics clients you can send metrics defined inside your code. If you choose not to use one of these clients, you can still directly push the metrics using the REST API. Once send the metrics can be consumed in Kibana.
164
+
To use the clients you'd need:
165
+
166
+
*Using spring-boot client in Spring Boot 2 application:*
The spring-boot client uses `Spring Boot Actuator` which allows to read predefined metrics and write custom metrics. The Actuator supports [Micrometer](https://github.com/micrometer-metrics/micrometer) and is part of Actuator's dependencies.
177
+
In your code you work directly with `Micrometer`. Define your custom metrics and iterate with them:
In the example above, three custom metrics are defined and used. The metrics are `Counter`, `LongTaskTimer` and `Gauge`.
226
+
227
+
## Custom metrics client configurations
228
+
229
+
This client library supports the following configurations regarding sending custom metrics:
230
+
*`interval`: the interval for sending metrics, in millis. **Default value: `60000`**
231
+
*`enabled`: enables or disables the sending of metrics. **Default value: `true`**
232
+
*`metrics`: array of whitelisted metric names. Only mentioned metrics would be processed and sent. If it is an empty array all metrics are being sent. **Default value: `[]`**
233
+
234
+
Configurations are read from environment variable named `CUSTOM_METRICS`. To change the default values, you should override the environment variable with your custom values. Example:
235
+
236
+
```
237
+
{
238
+
"interval": 30000,
239
+
"enabled": true,
240
+
"metrics": [
241
+
"my.whitelist.metric.1",
242
+
"my.whitelist.metric.2"
243
+
]
244
+
}
245
+
```
246
+
147
247
## Dynamic Log Levels
148
248
149
249
This library provides the possibility to change the log-level threshold for a
0 commit comments