Git Product home page Git Product logo

javalin-metrics-plugin's Introduction

Javalin Simple Metrics Plugin

Build Status

This is a plugin for Javalin to track some basic HTTP request/response metrics. It is written using a mix of Java and Kotlin.

Currently the following metrics are being recorded:

  • Request time
  • Response size

A unique request ID is also generated for each request, which is set in the Request-Id header of the HTTP response.

The plugin also registers several routes related to metrics:

  • /metrics displays a simple Thymeleaf page for viewing aggregated metrics (min, max and avg values for time and size). There is also a form for viewing stats for a single request ID.
  • /metrics/:request-id will return the duration and sizeInBytes for an individual request in json format. This is used by the form on the /metrics page.

Usage

The plugin can be built as a jar using ./gradlew assemble and added to your project.

Simply register the plugin during creation of your Javalin application:

public class App {
    public static void main(String[] args) {
        Javalin app = Javalin.create()
          .register(new MetricsPlugin())
          .start(7000);
        app.get("/", ctx -> ctx.result("Hello World"));
    }
}

Check out ExampleApp.kt for an example application.

Shortcomings/Areas for Improvement

  • Path matching in the used version of Javalin (2.8.0) doesn't seem to work well with more complex regular expressions, so I was unable to exclude calls to the /metrics endpoint itself from metrics collection.
  • There is no bounding on the map holding the recorded statistics so memory consumption could be an issue for long running applications. It would be advisable to evaluate using a ring buffer for storage in order to automatically age out the oldest entries.
  • The metrics page is extremely basic and could use some polish.
  • The plugin isn't currently being published to a Maven repo so bringing this into your own project isn't the smoothest experience.

javalin-metrics-plugin's People

Contributors

erikthered avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.