Skip to content

Commit 43beabf

Browse files
committed
Improve metrics section; add prometheus page
1 parent 5d94e55 commit 43beabf

File tree

6 files changed

+96
-48
lines changed

6 files changed

+96
-48
lines changed

_posts/2015-04-07-ganglia.md

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

_posts/2015-04-07-graphite.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ Add the following dependency to your application `pom.xml`.
1919

2020
Add the following settings to your `application.properties`.
2121

22-
metrics.graphite.enabled = true
23-
metrics.graphite.address = graphite.example.com
24-
metrics.graphite.port = 2003
25-
metrics.graphite.pickled = false
26-
metrics.graphite.period = 60 seconds
22+
```properties
23+
metrics.graphite.enabled = true
24+
metrics.graphite.address = graphite.example.com
25+
metrics.graphite.port = 2003
26+
metrics.graphite.pickled = false
27+
metrics.graphite.period = 60 seconds
28+
```

_posts/2015-04-07-influxdb.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ Add the following dependency to your application `pom.xml`.
1919

2020
Add the following settings to your `application.properties`.
2121

22-
metrics.influxdb.enabled = true
23-
metrics.influxdb.address = localhost
24-
metrics.influxdb.port = 8086
25-
metrics.influxdb.database = mydb
26-
metrics.influxdb.username = root
27-
metrics.influxdb.password = root
28-
metrics.influxdb.period = 60 seconds
22+
```properties
23+
metrics.influxdb.enabled = true
24+
metrics.influxdb.address = localhost
25+
metrics.influxdb.port = 8086
26+
metrics.influxdb.database = mydb
27+
metrics.influxdb.username = root
28+
metrics.influxdb.password = root
29+
metrics.influxdb.period = 60 seconds
30+
```

_posts/2015-04-07-librato.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Add the following dependency to your application `pom.xml`.
1919

2020
Add the following settings to your `application.properties`.
2121

22-
metrics.librato.enabled = true
23-
metrics.librato.username = person@example.com
24-
metrics.librato.apikey = 12345cafebabe
25-
metrics.librato.period = 60 seconds
22+
```properties
23+
metrics.librato.enabled = true
24+
metrics.librato.username = person@example.com
25+
metrics.librato.apikey = 12345cafebabe
26+
metrics.librato.period = 60 seconds
27+
```

_posts/2015-04-07-metrics.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ Pippo provides optional integration with [Metrics](http://metrics.dropwizard.io/
1010

1111
Pippo comes (out of the box) with some reporting backends:
1212

13-
- [Ganglia](/mod/metrics/ganglia.html) `pippo-metrics-ganglia`
1413
- [Graphite](/mod/metrics/graphite.html) `pippo-metrics-graphite`
1514
- [InfluxDB](/mod/metrics/influxdb.html) `pippo-metrics-influxdb`
1615
- [Librato](/mod/metrics/librato.html) `pippo-metrics-librato`
16+
- [Prometheus](/mod/metrics/prometheus.html) `pippo-metrics-prometheus`
1717

1818
#### Add the Pippo Metrics dependency
1919

@@ -31,7 +31,6 @@ Now you are ready to start annotating your route handler methods or controller m
3131

3232
You have several choices in the collection of metrics:
3333

34-
- *Do nothing*
3534
- [Counted]({{ site.codeurl }}/pippo-metrics-parent/pippo-metrics/src/main/java/ro/pippo/metrics/Counted.java)
3635
A counter increments (and optionally decrements) when a method is executed.
3736
- [Metered]({{ site.codeurl }}/pippo-metrics-parent/pippo-metrics/src/main/java/ro/pippo/metrics/Metered.java)
@@ -43,6 +42,8 @@ A timer measures both the rate that a particular piece of code is called and the
4342
2. Start up VisualVM (and install the MBeans plugin) or JConsole.
4443
3. Browse your app and refresh the collected metrics.
4544

45+
See below how to add a metric (meter) on a route handler
46+
4647
```java
4748
GET("/", new RouteHandler() {
4849

@@ -55,7 +56,42 @@ GET("/", new RouteHandler() {
5556
});
5657
```
5758

58-
Or a controller example:
59+
Other possible variants
60+
61+
```java
62+
// metered route
63+
GET("/metered", new MeteredHandler("HelloWorld", routeContext -> routeContext.send("Metered !!!")));
64+
```
65+
66+
```java
67+
GET("/", new RouteHandler() {
68+
69+
@Metered
70+
@Override
71+
public void handle(RouteContext routeContext) {
72+
routeContext.send("Hello World");
73+
}
74+
75+
}).named("HelloWorld"); // <<< create a route with a name
76+
77+
```
78+
in this case the metric name is the route name ("HelloWorld") because we have a named route and the metric name is missing for `@Metered` annotation.
79+
80+
```java
81+
GET("/", new MyHandler());
82+
83+
public class MyHandler implements RouteHandler {
84+
85+
@Metered
86+
public void handle(RouteContext routeContext) {
87+
routeContext.render("hello"); // render "hello" template
88+
}
89+
90+
}
91+
```
92+
in this case the metric name is "MyHandler.handle" (route handler class name and "handle" - method name)
93+
94+
See below how to add a metric (time) in a controller
5995

6096
```java
6197
public class ContactsController extends Controller {
@@ -74,12 +110,16 @@ public class ContactsController extends Controller {
74110

75111
You may optionally enable JVM-level details reporting by setting *metrics.jvm.enabled=true* in your `application.properties` file.
76112

77-
metrics.jvm.enabled = true
113+
```properties
114+
metrics.jvm.enabled = true
115+
```
78116

79117
#### Reporting Metrics via MBeans for VisualVM, JConsole, or JMX
80118

81-
If you want to expose your metrics to VisualVM, JConsole, or JMX you must enable the MBeans reporter in your `application.properties` file.
119+
If you want to expose your metrics to `VisualVM`, `JConsole`, or `JMX` you must enable the MBeans reporter in your `application.properties` file.
82120

83-
metrics.mbeans.enabled = true
121+
```properties
122+
metrics.mbeans.enabled = true
123+
```
84124

85-
You can view the collected metrics using VisualVM (with the MBeans plugin installed) or using JConsole.
125+
You can view the collected metrics using `VisualVM` (with the MBeans plugin installed) or using `JConsole`.

_posts/2018-06-29-prometheus.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
layout: page
3+
title: "Prometheus"
4+
permalink: /mod/metrics/prometheus.html
5+
date: 2018-06-29 13:43:29
6+
---
7+
8+
[Prometheus](https://prometheus.io) is a monitoring system and a time series database.
9+
10+
Add the following dependency to your application `pom.xml`.
11+
12+
```xml
13+
<dependency>
14+
<groupId>ro.pippo</groupId>
15+
<artifactId>pippo-metrics-prometheus</artifactId>
16+
<version>${pippo.version}</version>
17+
</dependency>
18+
```
19+
20+
Add the following settings to your `application.properties`.
21+
22+
```properties
23+
metrics.prometheus.enabled = true
24+
metrics.prometheus.address = prometheus.example.com // default 'localhost'
25+
metrics.prometheus.port = 9091
26+
metrics.prometheus.period = 60 seconds
27+
```

0 commit comments

Comments
 (0)