Pedestal offers metrics logging capabilities starting with Pedestal-0.5.0.
The default metrics recorder publishes to JMX, but you can override that
behavior by setting the JVM Property
or the environment variable
The value of the setting should be a namespaced symbol
that resolves to a 0-arity function or nil.
That function should return something that satisfies the MetricRecorder protocol.
Using this capability, you can publish all metrics to your desired recorder (JMX, StatsD, CloudWatch, SLF4J, etc.)
This sample demonstrates the basic use of metrics. Within the app, there is a dedicated page to illustrate the default metric recorder and another page that logs metrics only to statsd. The Statsd metrics are visible with the nc (netcat) command.
JVisualVM with MBeans plugin
If you have the JDK installed, you should already have JVisualVM. You'll need the MBeans plugin though:
- Open up JVisualVM with the
- Tools -> Plugins -> Available Plugins
- Select VisualVM-MBeans and install
Alternatively, you may use jconsole which should have MBeans feature out of the box.
JMX Metrics Reporting
- Start the application:
- Open VisualVM and attach to the running server JVM process
- Go to localhost:8080 to see:
- Metrics will show up on jvisualvm's MBeans tab.
- Reload the web page multiple times and click "Refresh" within the JVisualVM pane (bottom right).
- Learn more! See the Links section below.
Statsd Metrics Reporting
In a dedicated terminal, start nc (netcat) command to listen UDP on port 8125 (StatsD default port)
$ nc -kul 8125
If necessary, start the application:
Go to localhost:8080/statsd and reload the page multiple times
ncterminal, you'll see a stream of statsd messages like below:
You can see how many times the page has been requested.
Learn more! See the Links section below.
To configure logging see config/logback.xml. By default, the app logs to stdout and logs/. To learn more about configuring Logback, read its documentation.