Giter VIP home page Giter VIP logo

go-http_metrics's Introduction

go-http_metrics

Instrument http request.

go-http_metrics wraps http.Handle or HandleFunc to instrument each http request.

Usage

import (
  "net/http"
  "github.com/sonots/go-http_metrics"
)

func main() {
  // http.HandleFunc("/", rootHandleFunc)
  http.HandleFunc("/", http_metrics.WrapHandlerFunc("rootHandleFunc", rootHandleFunc))
  // http.Handle("/static/", staticHandle)
  http.Handle("/static/", http_metrics.WrapHandler("staticHandle", staticHandle))

  http_metrics.Print(1) // print metrics on each 1 second
  // http_metrics.Verbose = true // if you want to print on each request
  // http_metrics.Enable = false // if you want to turn off instrumentation
  http.ListenAndServe("0.0.0.0:5050", nil)
}

Output Example (LTSV format):

time:2014-09-08 03:27:50.346193673 +0900 JST  handler:rootHandleFunc count:1 max:0.001626    mean:0.001626   min:0.001626    percentile95:0.001626    duration:1

Verbose Output Example (LTSV format):

time:2014-09-08 03:27:50.346193673 +0900 JST  handler:rootHandleFunc method:GET      path:/    params:foo=bar   elapsed:0.001626

API

Print

Print summarized metrics on each specified second:

http_metrics.Print(60) # 60 seconds

Verbose

Print metrics on each request:

http_metrics.Verbose = true

Enable

Diable instrumentation:

http_metrics.Enable = false

OnResponse

Set an arbitrary callback called on each response as:

http_metrics.OnResponse = func() {
  sql_metrics.Flush()
  template_metrics.Flush()
}

This example flushes sql_metrics and template_metrics on each request.

ToDo

  • write tests

Contribution

Copyright

go-http_metrics's People

Contributors

sonots avatar

Stargazers

 avatar  avatar KUBOTA Shota avatar

Watchers

Yosuke Furukawa avatar Spring_MT avatar nikushi avatar  avatar

Forkers

ieee0824

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.