Giter VIP home page Giter VIP logo

p5-plack-middleware-querycounter's Introduction

NAME

Plack::Middleware::QueryCounter::DBI - DBI query counter per request middleware

SYNOPSIS

Enable this middleware using Plack::Builder.

use MyApp;
use Plack::Builder;

my $app = MyApp->psgi_app;

builder {
    enable 'QueryCounter::DBI';
    $app;
};

You can specify HTTP header using prefix option.

builder {
    enable 'QueryCounter::DBI', prefix => 'X-MyQueryCounter';
    $app;
};

DESCRIPTION

Plack::Middleware::QueryCounter::DBI is a middleware to count SQL query per each HTTP request. Count result outputs on HTTP header.

The counted quieries classify read, write or other query.

You'll get following HTTP headers.

X-QueryCounter-DBI-Total: 20
X-QueryCounter-DBI-Read:  16
X-QueryCounter-DBI-Write:  4
X-QueryCounter-DBI-Other:  0

Then, you can write to access log using nginx.

log_format ltsv   'host:$remote_addr\t'
                  'user:$remote_user\t'
(snip)
                  'user_agent:$http_user_agent\t'
                  'query_total:$sent_http_x_querycounter_dbi_total\t'
                  'query_read:$sent_http_x_querycounter_dbi_read\t'
                  'query_write:$sent_http_x_querycounter_dbi_write\t'
                  'query_other:$sent_http_x_querycounter_dbi_other\t';

LTSV is Labeled Tab-separated Values, see http://ltsv.org/

Additionally, I recommend to remove these header for end-user response.

location / {
    proxy_hide_header 'X-QueryCounter-DBI-Total';
    proxy_hide_header 'X-QueryCounter-DBI-Read';
    proxy_hide_header 'X-QueryCounter-DBI-Write';
    proxy_hide_header 'X-QueryCounter-DBI-Other';

    proxy_pass http://backend;
}

SEE ALSO

Plack Plack::Builder

LICENSE

Copyright (C) Masatoshi Kawazoe (acidlemon).

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Masatoshi Kawazoe (acidlemon) [email protected]

p5-plack-middleware-querycounter's People

Contributors

acidlemon avatar

Watchers

 avatar

Forkers

jwrightecs

p5-plack-middleware-querycounter's Issues

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.