Giter VIP home page Giter VIP logo

vapormonitoring's Introduction

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.

Installation

Vapor Monitoring can be installed using SPM

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

Usage

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.

vapormonitoring's People

Contributors

mrlotu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

vapormonitoring's Issues

Crash on Linux

when I call

curl -vvv http://localhost:8080/metrics it crashes with

Fatal error: tried to decode as type SocketChannel but found SocketChannel with contents other(SocketChannel { selectable = BaseSocket { fd=17 } , localAddress = Optional([IPv4]127.0.0.1/127.0.0.1:8080), remoteAddress = Optional([IPv4]127.0.0.1/127.0.0.1:34768) }): file /home/ubuntu/SERVER/.build/checkouts/swift-nio/Sources/NIO/NIOAny.swift, line 197

if I start server on different port and host

/home/ubuntu/SERVER/.build/debug/Run serve --hostname=0.0.0.0 --port=9000

It crashes on launch

Fatal error: tried to decode as type SocketChannel but found SocketChannel with contents other(SocketChannel { selectable = BaseSocket { fd=17 } , localAddress = Optional([IPv4]172.31.45.139/172.31.45.139:9000), remoteAddress = Optional([IPv4]172.31.7.130/172.31.7.130:1868) }): file /home/ubuntu/SERVER/.build/checkouts/swift-nio/Sources/NIO/NIOAny.swift, line 197

Error

ubantu 16.04 : error while loading shared libraries: libmemplugin.so: cannot open shared object file: No such file or directory

error 404 for graphmetrics/

Getting 404 for graphmetrics when loading the dashboard metrics.

The implementation is as following

/// Register middleware var middlewares = MiddlewareConfig() middlewares.use(FileMiddleware.self) // Serves files fromPublic/ directory middlewares.use(SessionsMiddleware.self) middlewares.use(ErrorMiddleware.self) services.register(middlewares)

let monitoringConfig = MonitoringConfig(dashboard: true, prometheus: true, dashboardRoute: "metrics", prometheusRoute: "prometheus") let router = try VaporMonitoring.setupMonitoring(&config, &services, &middlewares, monitoringConfig) services.register(router, as: Router.self)

Reponse on prometheus...
http_requests_total{code="404", handler="/graphmetrics/js/httpRequestsChart.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/bootstrap-3.3.7-dist/css/bootstrap.min.css", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/memChart.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/jquery/jquery-3.1.1.min.js", method="get"} 2 http_requests_total{code="200", handler="/metrics", method="get"} 2 http_requests_total{code="404", handler="/prometheus-metrics", method="get"} 0 http_requests_total{code="404", handler="/graphmetrics/css/style2.css", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/i18n.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/httpThroughPutChart.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/bootstrap-3.3.7-dist/js/bootstrap.min.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/cpuChart.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/css/style.css", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/httpSummary.js", method="get"} 2 http_requests_total{code="404", handler="/register", method="get"} 0 http_requests_total{code="404", handler="/graphmetrics/js/top5.js", method="get"} 2 http_requests_total{code="404", handler="/favicon.ico", method="get"} 0 http_requests_total{code="404", handler="/graphmetrics/js/header.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/js/textTable.js", method="get"} 2 http_requests_total{code="404", handler="/graphmetrics/d3/d3.v3.min.js", method="get"} 2

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.