deferstats

package
v0.0.0-...-2a1e5ed Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: MIT Imports: 20 Imported by: 1

Documentation

Overview

Package deferlog implements deferpanic error logging.

Package deferstats implements deferpanic stats

Index

Constants

This section is empty.

Variables

View Source
var (
	// Querylist is the list of db_queries that will be sent to
	// deferpanic
	Querylist deferDBList
)

FIXME

View Source
var (
	// Token is your deferpanic token available in settings
	Token string
)

being DEPRECATED please use deferstats.NewClient(token)

View Source
var WritePanicResponse = func(w http.ResponseWriter, r *http.Request, errMsg string) {
	w.WriteHeader(http.StatusInternalServerError)
	w.Write([]byte(errMsg))
}

WritePanicResponse is an overridable function that, by default, writes the contents of the panic error message with a 500 Internal Server Error.

Functions

func BackTrace

func BackTrace() (body string)

Backtrace grabs the backtrace

func GetSpanId

func GetSpanId(r http.ResponseWriter) int64

GetSpanId returns the span id for this http request

func GetSpanIdString

func GetSpanIdString(r http.ResponseWriter) string

GetSpanIdString is a convenience method to get the string equivalent of a span id

func ResetHTTPStats

func ResetHTTPStats()

ResetHTTPStats clears the current list of HTTP statistics

func WrapHTTPError

func WrapHTTPError(spanId int64, err error)

WrapHTTPError wraps an error that occurs w/in a http request and sends the error to deferpanic w/the spanId

Types

type Client

type Client struct {

	// GrabGC determines if we should grab gc stats
	GrabGC bool

	// GrabMem determines if we should grab mem stats
	GrabMem bool

	// GrabGR determines if we should grab go routine stats
	GrabGR bool

	// GrabCgo determines if we should grab cgo count
	GrabCgo bool

	// GrabFd determines if we should grab fd count
	GrabFd bool

	// GrabHTTP determines if we should grab http requests
	GrabHTTP bool

	// GrabExpvar determines if we should grab expvar
	GrabExpvar bool

	// LastGC keeps track of the last GC run
	LastGC int64

	// Token is your deferpanic token available in settings
	Token string

	// Verbose logs any stats output - for testing/dev
	Verbose bool

	// GetExpvar captures expvar using Do method
	GetExpvar func() (string, error)

	// BaseClient is the base deferpanic client that all http requests use
	BaseClient *deferclient.DeferPanicClient
	// contains filtered or unexported fields
}

Client is the client for making metrics requests to the defer panic api

func NewClient

func NewClient(token string, mux *bone.Mux) *Client

NewClient instantiates and returns a new client

func (*Client) AfterRequest

func (c *Client) AfterRequest(startTime time.Time, tracer *ResponseTracer, r *http.Request,
	headers map[string]string, status_code int, isproblem bool)

AfterRequest is called after request processing in handler

func (*Client) BeforeRequest

func (c *Client) BeforeRequest(w http.ResponseWriter, r *http.Request) (
	startTime time.Time, tracer *ResponseTracer, headers map[string]string)

BeforeRequest is called before request processing in handler

func (*Client) CaptureStats

func (c *Client) CaptureStats()

CaptureStats POSTs DeferStats every statsFrequency

func (*Client) ContextAfterRequest

func (c *Client) ContextAfterRequest(startTime time.Time, tracer *ContextTracer, r *http.Request,
	headers map[string]string, status_code int, isproblem bool)

ContextAfterRequest is called after request processing in context handler

func (*Client) ContextBeforeRequest

func (c *Client) ContextBeforeRequest(w http.ResponseWriter, r *http.Request) (
	startTime time.Time, ext *ResponseWriterExt, tracer *ContextTracer, headers map[string]string)

ContextBeforeRequest is called before request processing in context handler

func (*Client) GetStatsURL

func (c *Client) GetStatsURL() (statsurl string)

GetStatsURL returns statistics submitting URL

func (*Client) HTTPHandler

func (c *Client) HTTPHandler(f http.Handler) http.Handler

HTTPHandler wraps a http handler and captures the latency of each request this currently happens in a global list :( - TBFS

func (*Client) HTTPHandlerFunc

func (c *Client) HTTPHandlerFunc(f http.HandlerFunc) http.HandlerFunc

HTTPHandlerFunc wraps a http handler func and captures the latency of each request this currently happens in a global list :( - TBFS

func (*Client) Persist

func (c *Client) Persist()

Persists ensures any panics will post to deferpanic website for tracking typically used in non http go-routines

func (*Client) PersistRepanic

func (c *Client) PersistRepanic()

PersistRepanic ensures any panics will post to deferpanic website for tracking, it also reissues the panic afterwards. typically used in non http go-routines

func (*Client) SetHttpProxy

func (c *Client) SetHttpProxy(urlString string) error

SetHttpProxy overrides the default httpclient with a proxy client with user given address

func (*Client) SetStatsURL

func (c *Client) SetStatsURL(statsurl string)

SetStatsURL sets statistics submitting URL

func (*Client) SetappGroup

func (c *Client) SetappGroup(appGroup string)

SetappGroup sets the app group default is 'default'

func (*Client) Setenvironment

func (c *Client) Setenvironment(environment string)

Setenvironment sets the environment default is 'production'

func (*Client) SetnoPost

func (c *Client) SetnoPost(noPost bool)

Setnopost disables reporting to deferpanic default is false

func (*Client) Wrap

func (c *Client) Wrap(err error)

Wrap wraps an error and ships the backtrace to deferpanic

type ContextTracer

type ContextTracer struct {
	SpanId       int64
	ParentSpanId int64
}

ContextTracer passes spanId/parentSpanId parameters using context

type DB

type DB struct {
	Other *sql.DB
}

DB wraps sql.DB to provide latency timing against various db operations

func NewDB

func NewDB(db *sql.DB) *DB

NewDB is a constructor for wrapped database

func (*DB) Begin

func (db *DB) Begin() (*Tx, error)

Begin is a method for beginning transaction

func (*DB) Exec

func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec is method for executing query

func (*DB) Prepare

func (db *DB) Prepare(query string) (*Stmt, error)

Prepare is a method for preparing query

func (*DB) Query

func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query is a method for returning query results

func (*DB) QueryRow

func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow is a method for returning query row

type DeferDB

type DeferDB struct {
	Query string `json:"Query"`
	Time  int    `json:"Time"`
}

DeferDB holds the query and latency for each sql query whose threshold was overran

type DeferHTTP

type DeferHTTP struct {
	Path         string            `json:"Path"`
	Method       string            `json:"Method"`
	StatusCode   int               `json:"StatusCode"`
	Time         int               `json:"Time"`
	SpanId       int64             `json:"SpanId"`
	ParentSpanId int64             `json:"ParentSpanId"`
	IsProblem    bool              `json:"IsProblem"`
	Headers      map[string]string `json:"Headers"`
}

DeferHTTP holds a single instance of a http query

func GetHTTPStats

func GetHTTPStats() (deferhttps []DeferHTTP)

GetHTTPStats returns the current list of HTTP statistics

type DeferHTTPs

type DeferHTTPs []DeferHTTP

func (DeferHTTPs) Len

func (slice DeferHTTPs) Len() int

func (DeferHTTPs) Less

func (slice DeferHTTPs) Less(i, j int) bool

func (DeferHTTPs) Swap

func (slice DeferHTTPs) Swap(i, j int)

type DeferStats

type DeferStats struct {
	Mem        string           `json:"Mem"`
	GC         string           `json:"GC"`
	LastGC     string           `json:"LastGC"`
	LastPause  string           `json:"LastPause"`
	GoRoutines string           `json:"GoRoutines"`
	Cgos       string           `json:"Cgos"`
	Fds        string           `json:"Fds"`
	Expvars    string           `json:"Expvars"`
	HTTPs      []HTTPPercentile `json:"HTTPs,omitempty"`
	DBs        []DeferDB        `json:"DBs,omitempty"`
	Rpms       Rpm              `json:"RPMs,omitempty"`
}

DeferStats captures {mem, gc, goroutines and http calls}

type HTTPPercentile

type HTTPPercentile struct {
	Sample DeferHTTP `json:"Sample"`
	P50    float64   `json:"P50"`
	P75    float64   `json:"P75"`
	P90    float64   `json:"P90"`
	P95    float64   `json:"P95"`
	P99    float64   `json:"P99"`
	Min    int64     `json:"Min"`
	Max    int64     `json:"Max"`
	Mean   float64   `json:"Mean"`
	StdDev float64   `json:"StdDev"`
	Count  int64     `json:"Count"`
}

HTTPPercentile is a single instance of the set of a http query percentiles

type ResponseTracer

type ResponseTracer struct {
	SpanId       int64
	ParentSpanId int64
	// contains filtered or unexported fields
}

ResponseTracer implements a responsewriter with SpanId/ParentSpanId

func (*ResponseTracer) Header

func (l *ResponseTracer) Header() http.Header

Header is implementaion of standard http ResponseWriter Header method

func (*ResponseTracer) Size

func (l *ResponseTracer) Size() int

Size returns the HTTP size

func (*ResponseTracer) Status

func (l *ResponseTracer) Status() int

Status returns the HTTP status code

func (*ResponseTracer) Write

func (l *ResponseTracer) Write(b []byte) (int, error)

Write is implementaion of standard http ResponseWriter Header method and setting the size and status

func (*ResponseTracer) WriteHeader

func (l *ResponseTracer) WriteHeader(s int)

WriteHeader sets the header

type ResponseWriterExt

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

ResponseWriterExt implements http.ResponseWriter with extended methods

func (*ResponseWriterExt) Header

func (e *ResponseWriterExt) Header() http.Header

Header is implementaion of standard http ResponseWriter Header method

func (*ResponseWriterExt) Size

func (e *ResponseWriterExt) Size() int

Size returns the HTTP size

func (*ResponseWriterExt) Status

func (e *ResponseWriterExt) Status() int

Status returns the HTTP status code

func (*ResponseWriterExt) Write

func (e *ResponseWriterExt) Write(b []byte) (int, error)

Write is implementaion of standard http ResponseWriter Header method and setting the size and status

func (*ResponseWriterExt) WriteHeader

func (e *ResponseWriterExt) WriteHeader(s int)

WriteHeader is implementaion of standard http ResponseWriter WriteHeader method and setting the status

type Rpm

type Rpm struct {
	StatusOk int `json:"200,omitempty"`

	StatusMovedPermanently int `json:"301,omitempty"`
	StatusFound            int `json:"302,omitempty"`

	StatusBadRequest   int `json:"400,omitempty"`
	StatusUnauthorized int `json:"401,omitempty"`
	StatusForbidden    int `json:"403,omitempty"`
	StatusNotFound     int `json:"404,omitempty"`

	StatusInternalServerError int `json:"500,omitempty"`
	StatusServiceUnavailable  int `json:"503,omitempty"`
}

HTTPRpm holds the count of each HTTP status code during a stats collection interval

type Stmt

type Stmt struct {
	Db       *DB
	QueryStr string
	Other    *sql.Stmt
}

Stmt wraps sql.Stmt to provide latency timing against various db operations

func NewStmt

func NewStmt(db *DB, querystr string, stmt *sql.Stmt) *Stmt

NewStmt is a constructor for wrapped statement

func (*Stmt) Exec

func (stmt *Stmt) Exec(args ...interface{}) (sql.Result, error)

Exec is method for executing query

func (*Stmt) Query

func (stmt *Stmt) Query(args ...interface{}) (*sql.Rows, error)

Query is a method for returning query results

func (*Stmt) QueryRow

func (stmt *Stmt) QueryRow(args ...interface{}) *sql.Row

QueryRow is a method for returning query row

type Tx

type Tx struct {
	Db    *DB
	Other *sql.Tx
}

Tx wraps sql.Tx to provide latency timing against various db operations

func NewTx

func NewTx(db *DB, tx *sql.Tx) *Tx

NewTx is a constructor for wrapped transaction

func (*Tx) Commit

func (tx *Tx) Commit() error

Commit is a method for committing transaction

func (*Tx) Exec

func (tx *Tx) Exec(query string, args ...interface{}) (sql.Result, error)

Exec is method for executing query

func (*Tx) Prepare

func (tx *Tx) Prepare(query string) (*Stmt, error)

Prepare is a method for preparing query

func (*Tx) Query

func (tx *Tx) Query(query string, args ...interface{}) (*sql.Rows, error)

Query is a method for returning query results

func (*Tx) QueryRow

func (tx *Tx) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow is a method for returning query row

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback is a method for rollbacking transaction

Jump to

Keyboard shortcuts

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