Swiftpack.co - Package - vapor-community/VaporMonitoring


Vapor 3 Swift 4.1

VaporMonitoring is a Vapor 3 package for monitoring and providing metrics for your Vapor application. Built on top op SwiftMetrics and SwiftPrometheus. Vapor Monitoring provides the default SwiftMetrics metrics along with request specific metrics. Metrics are exposed using Prometheus.


Vapor Monitoring can be installed using SPM

.package(url: "https://github.com/vapor-community/VaporMonitoring.git", from: "2.0.0")


Vapor Monitoring is easy to use, it requires only a few lines of code.

Vapor Monitoring requires a few things to work correclty, a MonitoredRouter and a MonitoredResponder are the most important ones.

To set up your monitoring, in your Configure.swift file, add the following:

let router = try VaporMonitoring.setupMonitoring(&config, &services)
services.register(router, as: Router.self)

What this does is load VaporMonitoring with the default configuration. This includes adding all required services to your apps services & setting some configuration prefferences to use the MonitoredResponder and MonitoredRouter.

By default, your prometheus metrics will be served at host:port/metrics and routes that don't have a routing closure, will be ignored to avoid exploding your prometheus logs. You can however customize this.

To customize your monitoring, add this to Configure.swift

let monitoringConfg = MonitoringConfig(prometheusRoute: "customRoute", onlyBuiltinRoutes: false)
let router = try VaporMonitoring.setupMonitoring(&config, &services, monitoringConfg)
services.register(router, as: Router.self)

In this case, you'd have your prometheus metrics at host:port/customRoute.


Stars: 25
Help us keep the lights on

Used By

Total: 1


2.1.0 - Dec 7, 2018

This release adds the ability to filter out non internal routes, avoiding explosion of your metrics endpoint.

By default this feature is not enabled, so if you update to 2.1.0 without changing your config, nothing will change in the way your metrics are served.

Example: If your routes.swift looks like this:

public func routes(_ router: Router) throws {
    // Basic "Hello, world!" example
    router.get("hello") { req in
        return "Hello, world!"

Requests to host:port/test will not be taken into account by the logging, but requests to host:port/hello will

2.0.1 - Nov 24, 2018

Small bugfixes and removing a whole bunch of unneeded files to optimize speed

2.0.0 - Nov 21, 2018

WARNING: Breaking release!

The dashboard was removed in this version, and the underlying prometheus tasks were migrated to use SwiftPrometheus

1.0.0 - Jun 20, 2018

Vapor Monitoring V1.0.0, the first full release!

Vapor Monitoring now longer blocks any other Vapor functionality so you can use it with any project!

0.1.0 - Jun 19, 2018

First stable release of VaporMonitoring! 🎉