Skip to content

Commit 1dd3958

Browse files
committed
add prometheus interface and other updates
1 parent 507969d commit 1dd3958

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ The testdata for the company site is Airbus Finkenwerder for the year 2020. The
2929
## Kubernetes setup
3030
In the helm directory is a kubernetes setup to run the angularandspringwithmaps project with minikube. The Helm chart deployes the postgres database and the angularandspringwithmaps with the needed parameters to run.
3131

32+
## Monitoring
33+
The Spring Actuator interface with Prometheus interface can be used as it is described in this article:
34+
35+
[Monitoring Spring Boot with Prometheus and Grafana](https://ordina-jworks.github.io/monitoring/2020/11/16/monitoring-spring-prometheus-grafana.html)
36+
37+
To test the setup the application has to be started and the Docker Images for Prometheus and Grafana have to be started and configured. The scripts 'runGraphana.sh' and 'runPrometheus.sh' can be used as a starting point.
38+
3239
## Setup
3340
Java 11 or newer.
3441

Diff for: build.gradle

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
limitations under the License.
1212
*/
1313
plugins {
14-
id 'org.springframework.boot' version '2.5.1'
14+
id 'org.springframework.boot' version '2.5.5'
1515
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
1616
id 'java'
1717
}
@@ -30,9 +30,10 @@ dependencies {
3030
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
3131
implementation 'org.springframework.boot:spring-boot-starter-security'
3232
implementation 'org.springframework.boot:spring-boot-starter-web'
33+
implementation 'io.micrometer:micrometer-registry-prometheus'
3334
implementation 'org.liquibase:liquibase-core'
34-
implementation 'io.springfox:springfox-swagger2:2.9.2'
35-
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
35+
implementation 'org.springdoc:springdoc-openapi-ui:1.5.11'
36+
implementation 'org.springdoc:springdoc-openapi-data-rest:1.5.11'
3637
implementation 'commons-net:commons-net:3.6'
3738
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3839
testImplementation 'org.springframework.security:spring-security-test'

Diff for: prometheus-local.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
global:
2+
scrape_interval: 15s
3+
4+
scrape_configs:
5+
- job_name: 'prometheus'
6+
scrape_interval: 5s
7+
8+
static_configs:
9+
- targets: ['localhost:9090']
10+
11+
- job_name: 'spring-actuator'
12+
metrics_path: '/actuator/prometheus'
13+
scrape_interval: 5s
14+
static_configs:
15+
- targets: ['localhost:8080']

Diff for: runGrafana.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
#docker pull grafana/grafana
3+
MYID=`id -u`
4+
#data will be stored in ~/tmp/data
5+
#mkdir ~/tmp/data
6+
MYDATA=echo ~/tmp/data
7+
docker run --user "$MYID" --volume "$MYID:$MYDATA" --network "host" grafana/grafana

Diff for: runPrometheus.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
#docker pull prom/prometheus
3+
LOCALDIR=pwd
4+
docker run --network "host" -v "$LOCALDIR/prometheus-local.yml:/etc/prometheus/prometheus.yml" prom/prometheus

Diff for: src/main/java/ch/xxx/maps/MapsApplication.java

+4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
import org.springframework.boot.SpringApplication;
1919
import org.springframework.boot.autoconfigure.SpringBootApplication;
2020

21+
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
22+
import io.swagger.v3.oas.annotations.info.Info;
23+
2124
@SpringBootApplication
25+
@OpenAPIDefinition(info = @Info(title = "MapsApplication API", version = "1.0", description = "MapsApplication Api Information"))
2226
public class MapsApplication {
2327

2428
public static void main(String[] args) {

Diff for: src/main/java/ch/xxx/maps/adapter/config/ForwardServletFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public class ForwardServletFilter implements Filter {
4040
private static final Logger LOG = LoggerFactory.getLogger(ForwardServletFilter.class);
4141
public static final List<Locale> SUPPORTED_LOCALES = List.of(Locale.ENGLISH, Locale.GERMAN);
42-
public static final List<String> REST_PATHS = List.of("/rest", "/actuator", "/h2-console");
42+
public static final List<String> REST_PATHS = List.of("/rest", "/actuator", "/h2-console", "/swagger-ui.html", "/swagger-ui", "/v3");
4343
public static final List<String> LANGUAGE_PATHS = SUPPORTED_LOCALES.stream()
4444
.map(myLocale -> String.format("/%s/", myLocale.getLanguage())).collect(Collectors.toList());
4545

Diff for: src/main/resources/application.properties

+28-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
server.compression.enabled=true
22
server.http2.enabled=true
3+
server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
4+
server.compression.min-response-size=2KB
35

46
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
57
spring.datasource.driver-class-name=org.h2.Driver
@@ -19,12 +21,34 @@ spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
1921

2022
server.servlet.session.timeout=30s
2123

24+
bing.maps-key=${BINGMAPKEY:xxx}
25+
2226
management.health.livenessstate.enabled=true
2327
management.health.readinessstate.enabled=true
2428
management.health.mongo.enabled=true
2529
management.health.enabled=true
2630
management.endpoint.health.show-details=always
27-
management.endpoints.web.exposure.include=health
28-
management.endpoints.jmx.exposure.include=health
29-
30-
bing.maps-key=${BINGMAPKEY:xxx}
31+
management.endpoints.web.exposure.include=health,prometheus,metrics
32+
management.endpoints.jmx.exposure.include=health,prometheus,metrics
33+
management.metrics.export.simple.enabled=true
34+
management.metrics.export.prometheus.enabled=true
35+
management.endpoint.prometheus.cache.time-to-live=100ms
36+
management.endpoint.health.cache.time-to-live=100ms
37+
management.metrics.export.simple.step=100ms
38+
management.metrics.enabled=true
39+
management.metrics.distribution.percentiles.http.server.requests=0.5,0.95,0.99
40+
management.metrics.distribution.percentiles.http.client.requests=0.5,0.95,0.99
41+
management.metrics.distribution.percentiles-histogram.http.server.requests=true
42+
management.metrics.distribution.slo.http.server.requests=500ms
43+
management.metrics.distribution.minimum-expected-value.http.server.requests=1ms
44+
management.metrics.distribution.maximum-expected-value.http.server.requests=5s
45+
management.metrics.enable.jvm=false
46+
management.metrics.enable.spring.data=false
47+
management.metrics.enable.hikaricp=false
48+
management.metrics.enable.jdbc=false
49+
management.metrics.enable.logback=false
50+
management.metrics.enable.process=false
51+
management.metrics.enable.system=false
52+
management.metrics.enable.jvm.gc.pause=true
53+
management.metrics.enable.create=true
54+
management.metrics.enable.http=true

0 commit comments

Comments
 (0)