stats

package module
v0.0.0-...-535f6d9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2017 License: MIT Imports: 3 Imported by: 0

README

go-server-stats

Go Report Card Build Status Coverage Status license

The Go-Server-Stats package can be used to count statistics for a web service written in Go.

┌─┐┌─┐   ┌─┐┌─┐┬─┐┬  ┬┌─┐┬─┐   ┌─┐┌┬┐┌─┐┌┬┐┌─┐
│ ┬│ │───└─┐├┤ ├┬┘└┐┌┘├┤ ├┬┘───└─┐ │ ├─┤ │ └─┐
└─┘└─┘   └─┘└─┘┴└─ └┘ └─┘┴└─   └─┘ ┴ ┴ ┴ ┴ └─┘
Installation

To install the package, use the go command

> go get github.com/andrewlader/go-server-stats
Requirements

Requires Go >= v1.2

Usage

Add stats.Stats to the web service. For example:

// the HTTP handler instance
type httpServer struct {
	stats   *stats.Stats
	mux     map[string]apiHandler
}

Then when an API is called, use the Update() method to increment the counters:

server.stats.Update(wasSuccessful, uint64(request.ContentLength), numberOfBytesWritten)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Output

type Output struct {
	UpTime                      string
	NumberOfCalls               uint64
	NumberOfFailures            uint64
	NumberOfBytesReceived       uint64
	NumberOfBytesWritten        uint64
	AvgResponseTimeMilliseconds uint64
}

Output is what is returned when a stats inquiry is made of the server

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats maintains a set of status values for the service

func New

func New() *Stats

New returns a pointer to a new instance of Stats

func (*Stats) Bytes

func (stats *Stats) Bytes() []byte

Bytes returns the stats in the form of a JSON series of bytes

func (*Stats) GetOutput

func (stats *Stats) GetOutput() *Output

GetOutput returns the stats in the form of Output

func (*Stats) Update

func (stats *Stats) Update(WasSuccessful bool, numberOfBytesReceived uint64, numberOfBytesWritten uint64, responseTimeMilliseconds uint64)

Update takes the provide values and increments the stats values using atomic calls

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL