Git Product home page Git Product logo

laravelprometheusexporter's Introduction

LaravelPrometheusExporter

Software license Travis Coveralls CodeCov Scrutinizer Code Quality Latest stable Monthly installs Total Downloads Average time to resolve an issue Percentage of issues still open

A laravel and lumen service provider to export metrics for prometheus.

Supported laravel versions

Laravel 5.6 Laravel 5.7 Laravel 5.8 Laravel 6.0

Supported lumen versions

Lumen 5.6 Lumen 5.7 Lumen 5.8 Lumen 6.0

Main features

  • Metrics with APC
  • Metrics with Redis
  • Metrics with InMemory
  • Metrics with the push gateway
  • Request per route middleware (total and duration metrics)

Installation

Composer

composer require triadev/laravel-prometheus-exporter

Application

The package is registered through the package discovery of laravel and Composer.

https://laravel.com/docs/5.8/packages

Once installed you can now publish your config file and set your correct configuration for using the package.

php artisan vendor:publish --provider="Triadev\PrometheusExporter\Provider\PrometheusExporterServiceProvider" --tag="config"

This will create a file config/prometheus-exporter.php.

Configuration

Key Env Value Description Default
adapter PROMETHEUS_ADAPTER STRING apc, redis, inmemory or push apc
namespace --- STRING default: app app
namespace_http --- STRING namespace for "RequestPerRoute-Middleware metrics" http
redis.host PROMETHEUS_REDIS_HOST, REDIS_HOST STRING redis host 127.0.0.1
redis.port PROMETHEUS_REDIS_PORT, REDIS_PORT INTEGER redis port 6379
redis.password PROMETHEUS_REDIS_PASSWORD, REDIS_PASSWORD STRING redis password null
redis.timeout --- FLOAT redis timeout 0.1
redis.read_timeout --- INTEGER redis read timeout 10
push_gateway.address PROMETHEUS_PUSH_GATEWAY_ADDRESS STRING push gateway address localhost:9091
buckets_per_route --- STRING histogram buckets for "RequestPerRoute-Middleware" ---

buckets_per_route

'buckets_per_route' => [
    ROUTE-NAME => [10,20,50,100,200],
    ...
]

Usage

Get metrics

Laravel

When you are using laravel you can use the default http endpoint:

triadev/pe/metrics

Of course you can also register your own route. Here is an example:

Route::get(
    ROUTE,
    \Triadev\PrometheusExporter\Controller\LaravelController::class . '@metrics'
);

Lumen

When you are using lumen you must register the route on your own. Here is an example:

Route::get(
    ROUTE,
    \Triadev\PrometheusExporter\Controller\LumenController::class . '@metrics'
);

Middleware

RequestPerRoute

A middleware to build metrics for "request_total" and "requests_latency_milliseconds" per route.

Alias

lpe.requestPerRoute

Metrics
  1. requests_total (inc)
  2. requests_latency_milliseconds (histogram)
Example
$router->get('/test/route', function () {
    return 'valid';
})->middleware('lpe.requestPerRoute');

app_requests_latency_milliseconds_bucket{route="/test/route",method="GET",status_code="200",le="0.005"} 0 ... app_requests_latency_milliseconds_count{route="/test/route",method="GET",status_code="200"} 1 app_requests_latency_milliseconds_sum{route="/test/route",method="GET",status_code="200"} 6 app_requests_total{route="/test/route",method="GET",status_code="200"} 1

Roadmap

  • histogram buckets per route (RequestPerRoute)

Reporting Issues

If you do find an issue, please feel free to report it with GitHub's bug tracker for this project.

Alternatively, fork the project and make a pull request. :)

Testing

  1. docker-compose up
  2. docker exec fpm ./vendor/phpunit/phpunit/phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

Other

Project related links

Author

License

The code for LaravelPrometheusExporter is distributed under the terms of the MIT license (see LICENSE).

laravelprometheusexporter's People

Contributors

martianoff avatar myigel avatar nazarbiloys avatar triadev 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.