Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Latest commit

 

History

History
72 lines (49 loc) · 2.32 KB

README.md

File metadata and controls

72 lines (49 loc) · 2.32 KB

negroni-server-status

A negroni middleware to monitor HTTP request stats like Plack::Middleware::ServerStatus::Lite

deprecation notice

Currently I don't use this middleware anymore. It may still work, but may not anymore.

Current Limitations

Comparing to original Plack::Middleware::ServerStatus::Lite, this middleware has following limitations.

  • IdleWorker value is always empty
    • net/http server does not limit total numbers of workers, so this field is meaningless
  • Always returns response in JSON formats
  • Response does not contain individual processing requests (stats field)
  • Access Restriction is not implemented

The lattar three are not implemented because I don't need them currently, but patches are welcome.

Usage

See example/main.go.

package main

import (
	"fmt"
	"net/http"

	nss "github.com/astj/negroni-server-status"
	"github.com/urfave/negroni"
)

func main() {
	mux := http.NewServeMux()

	mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
		fmt.Fprint(w, "This is from internal")
	})

	n := negroni.New()

	n.Use(nss.NewMiddleware("/server-status"))

	n.UseHandler(mux)

	n.Run(":3000")
}

In this case, a response from http://localhost:3000/server-status is somewhat like this:

{"Uptime":"60","TotalAccesses":"67","TotalKbytes":"1","BusyWorkers":"1","IdleWorkers":"","stats":[]}
key type of value meaning
Uptime string Elapsed seconds from this server starts
TotalAccess string Number of requests processed by this server
TotalKbytes string Sum of response body size processed by this server, in KB units
BusyWorkers string Number of currently processing requests
IdleWorkers string Just empty. Available for compatibility with original Plack middleware
stats [] Should be information about current connections (not implemented)

License

MIT

Author

@astj (Asato Wakisaka)