Skip to content

Commit f1583f9

Browse files
author
s7nio
committed
Fix application metrics and update documentation
1 parent 9be2526 commit f1583f9

File tree

6 files changed

+68
-84
lines changed

6 files changed

+68
-84
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22

33
This is a simple [spring](https://spring.io) [boot](http://projects.spring.io/spring-boot/) showcase project, which based on [https://start.spring.io](https://start.spring.io).
44

5-
## Docker
5+
## Build application
66

7-
Start a monitoring setup with grafana, prometheus, cadvisor and this sample application.
7+
8+
```shell
9+
mvn clean package
10+
```
11+
12+
## Start infrastructure
13+
14+
Start docker monitoring setup with grafana, prometheus, cadvisor and the application.
815

916
```shell
1017
docker-compose up
11-
open http://localhost:8080
12-
# make some requests in the sample application
13-
open http://localhost:3000
14-
# grafana login with admin:admin
1518
docker-compose down
16-
```
19+
```
20+
21+
## Smart configuration
22+
23+
* Application: [http://localhost:8080/cat](http://localhost:8080/cat)
24+
* make some requests
25+
* Prometheus: [http://localhost:9090](http://localhost:9090)
26+
* Grafana: [http://localhost:3000](http://localhost:3000)
27+
* login with admin:admin
28+
* setup "prometheus" data source
29+
* import grafana-dashboard

grafana/grafana-dashboard.json

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"type": "grafana",
1515
"id": "grafana",
1616
"name": "Grafana",
17-
"version": "4.4.2"
17+
"version": "4.6.3"
1818
},
1919
{
2020
"type": "panel",
@@ -30,7 +30,17 @@
3030
}
3131
],
3232
"annotations": {
33-
"list": []
33+
"list": [
34+
{
35+
"builtIn": 1,
36+
"datasource": "-- Grafana --",
37+
"enable": true,
38+
"hide": true,
39+
"iconColor": "rgba(0, 211, 255, 1)",
40+
"name": "Annotations & Alerts",
41+
"type": "dashboard"
42+
}
43+
]
3444
},
3545
"description": "Docker Monitoring Template",
3646
"editable": true,
@@ -39,7 +49,7 @@
3949
"hideControls": false,
4050
"id": null,
4151
"links": [],
42-
"refresh": "10s",
52+
"refresh": "30s",
4353
"rows": [
4454
{
4555
"collapse": false,
@@ -51,7 +61,7 @@
5161
"dashLength": 10,
5262
"dashes": false,
5363
"datasource": "${DS_PROMETHEUS}",
54-
"fill": 1,
64+
"fill": 0,
5565
"id": 10,
5666
"legend": {
5767
"alignAsTable": true,
@@ -81,20 +91,30 @@
8191
"steppedLine": false,
8292
"targets": [
8393
{
84-
"expr": "rate(http_response_time_milliseconds_sum{job=\"vp-opti\"}[5m])/rate(http_response_time_milliseconds_count{job=\"vp-opti\"}[5m])",
94+
"expr": "delta(counter_status_200_cat[1m])",
8595
"format": "time_series",
86-
"intervalFactor": 2,
87-
"legendFormat": "{{ method }} {{ handler }} http {{ status }}",
96+
"instant": false,
97+
"interval": "",
98+
"intervalFactor": 1,
99+
"legendFormat": "/cat",
88100
"refId": "A",
89101
"step": 4
102+
},
103+
{
104+
"expr": "idelta(counter_status_200_prometheus[1m])",
105+
"format": "time_series",
106+
"interval": "",
107+
"intervalFactor": 2,
108+
"legendFormat": "/prometheus",
109+
"refId": "B"
90110
}
91111
],
92112
"thresholds": [],
93113
"timeFrom": null,
94114
"timeShift": null,
95-
"title": "Http handler response time",
115+
"title": "Http request count",
96116
"tooltip": {
97-
"shared": false,
117+
"shared": true,
98118
"sort": 0,
99119
"value_type": "individual"
100120
},
@@ -104,12 +124,11 @@
104124
"mode": "time",
105125
"name": null,
106126
"show": true,
107-
"values": [
108-
"total"
109-
]
127+
"values": []
110128
},
111129
"yaxes": [
112130
{
131+
"decimals": 0,
113132
"format": "short",
114133
"label": null,
115134
"logBase": 1,
@@ -123,7 +142,7 @@
123142
"logBase": 1,
124143
"max": null,
125144
"min": null,
126-
"show": true
145+
"show": false
127146
}
128147
]
129148
}
@@ -516,7 +535,7 @@
516535
"list": []
517536
},
518537
"time": {
519-
"from": "now-1h",
538+
"from": "now-30m",
520539
"to": "now"
521540
},
522541
"timepicker": {
@@ -545,6 +564,6 @@
545564
]
546565
},
547566
"timezone": "browser",
548-
"title": "Docker Dashboard",
549-
"version": 4
567+
"title": "Spring Boot Monitoring Sample Dashboard",
568+
"version": 1
550569
}

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1717
<java.version>1.8</java.version>
1818
<lombok.version>1.18.0</lombok.version>
19+
<prometheus.verison>0.4.0</prometheus.verison>
1920
</properties>
2021

2122
<parent>
2223
<groupId>org.springframework.boot</groupId>
2324
<artifactId>spring-boot-starter-parent</artifactId>
24-
<version>1.5.6.RELEASE</version>
25+
<version>1.5.14.RELEASE</version>
2526
<relativePath/> <!-- lookup parent from repository -->
2627
</parent>
2728

@@ -42,6 +43,12 @@
4243
<artifactId>spring-boot-actuator-docs</artifactId>
4344
</dependency>
4445

46+
<dependency>
47+
<groupId>io.prometheus</groupId>
48+
<artifactId>simpleclient_spring_boot</artifactId>
49+
<version>${prometheus.verison}</version>
50+
</dependency>
51+
4552
<dependency>
4653
<groupId>org.projectlombok</groupId>
4754
<artifactId>lombok</artifactId>

prometheus/prometheus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ scrape_configs:
2424
metrics_path: '/prometheus'
2525

2626
static_configs:
27-
- targets: ['vp-opti:8080']
27+
- targets: ['app:8080']
2828

2929
- job_name: 'cadvisor'
3030

src/main/java/de/codecentric/springboot/monitoring/Application.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package de.codecentric.springboot.monitoring;
22

3+
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
4+
import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57

68
@SpringBootApplication
9+
@EnablePrometheusEndpoint
10+
@EnableSpringBootMetricsCollector
711
public class Application {
812

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

src/test/java/de/codecentric/springboot/monitoring/EchoMessageJsonTest.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)