goappmonitor

package module
v0.0.0-...-7fa0207 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2016 License: Apache-2.0 Imports: 22 Imported by: 0

README

goappmonitor

goappmonitor

Build Status codecov GoDoc Code Health Code Issues Go Report Card License

Golang application performance data monitoring.

GoAppMonitor is a library which provides a monitor on your golang applications. It contains system level based monitoring and business level monitoring(custom monitoring).Just add the repository into your apps and register what you want to monitoring.

Summary

Using GoAppMonitor to monitor the golang applications, in general as following:

In your golang application code, the user calls the statistics function provided by goappmonitor; when the statistics function is called, the appmonitor generates a statistical record, and is stored in memory.GoAppMonitor will automatically and regularly record these statistics push to the agent such as Open-Falcon agent.

Version

version support agent:

v0.0.1 - Open-Falcon (Open source monitoring system of Xiaomi)

todo....
  • support more type metrics,such as ewma and flow type.
  • remove third-part library.
  • support more agent frameworks,such as elasticsearch...

Install

go get github.com/wgliang/goappmonitor

Demo

demo

Usage

Below is an example which shows some common use cases for goappmonitor. Check example for more usage.

Detail API

package main

import (
	"math/rand"
	"time"

	appm "github.com/wgliang/goappmonitor"
)

// Base or system perfomance data,such as memeory,gc,network and so on.
func baseOrsystem() {
	for _ = range time.Tick(time.Second * time.Duration(10)) {
		// (commonly used) Meter, used to sum and calculate the rate of change. Use scenarios
		// such as the number of home visits statistics, CG etc..
		pv := int64(rand.Int() % 100)
		appm.Meter("appm.meter", pv)
		appm.Meter("appm.meter.2", pv-50)

		// (commonly used) Gauge, used to preserve the value of the instantaneous value of the
		// type of record. Use scenarios such as statistical queue length, statistics CPU usage,
		// and so on.
		queueSize := int64(rand.Int()%100 - 50)
		appm.Gauge("appm.gauge", queueSize)

		cpuUtil := float64(rand.Int()%10000) / float64(100)
		appm.GaugeFloat64("appm.gauge.float64", cpuUtil)
	}
}

// Custom or business perfomance data,such as qps,num of function be called, task queue and so on.
func customOrbusiness() {
	for _ = range time.Tick(time.Second) {
		// Histogram, using the exponential decay sampling method, the probability distribution of
		// the statistical object is calculated. Using scenarios such as the probability distribution
		// of the statistics home page to access the delay
		delay := int64(rand.Int() % 100)
		appm.Histogram("appm.histogram", delay)
	}
}

func main() {
	var ch chan int
	go baseOrsystem()
	go customOrbusiness()
	<-ch
}

Credits

Repository is base on goperfcounter of niean

Logo is desigend by xuri

Documentation

Index

Constants

View Source
const (
	GAUGE = "GAUGE" // Gauge const
)
View Source
const (
	VERSION = "0.0.1"
)

Variables

This section is empty.

Functions

func CollectDebugGCStats

func CollectDebugGCStats(r metrics.Collectry, d time.Duration)

Collect denug gc stats and it will run a goroutine.

func CollectRuntimeMemStats

func CollectRuntimeMemStats(r metrics.Collectry, d time.Duration)

Collect runtime memeory-data:CollectRuntimeMemStats.

func Counter

func Counter(name string, count int64)

Counter Actions

func Gauge

func Gauge(name string, value int64)

Gauge Actions

func GaugeFloat64

func GaugeFloat64(name string, value float64)

GaugeFloat64

func GetCounter

func GetCounter(name string) int64

GetCounter

func GetGauge

func GetGauge(name string) float64

GetGauge

func GetHistogram

func GetHistogram(name string) int64

GetHistogram

func GetHistogram50th

func GetHistogram50th(name string) float64

GetHistogram50th

func GetHistogram75th

func GetHistogram75th(name string) float64

GetHistogram75th

func GetHistogram95th

func GetHistogram95th(name string) float64

GetHistogram95th

func GetHistogram999th

func GetHistogram999th(name string) float64

GetHistogram999th

func GetHistogram99th

func GetHistogram99th(name string) float64

GetHistogram99th

func GetHistogramMax

func GetHistogramMax(name string) int64

GetHistogramMax

func GetHistogramMean

func GetHistogramMean(name string) float64

GetHistogramMean

func GetHistogramMin

func GetHistogramMin(name string) int64

GetHistogramMin

func GetHistogramStdDev

func GetHistogramStdDev(name string) float64

GetHistogramStdDev

func GetHistogramSum

func GetHistogramSum(name string) int64

GetHistogramSum

func GetMeter

func GetMeter(name string) int64

GetMeter

func GetMeterRate1

func GetMeterRate1(name string) float64

GetMeterRate1

func GetMeterRate15

func GetMeterRate15(name string) float64

GetMeterRate15

func GetMeterRate5

func GetMeterRate5(name string) float64

GetMeterRate5

func GetMeterRateMean

func GetMeterRateMean(name string) float64

GetMeterRateMean

func GetMeterRateStep

func GetMeterRateStep(name string) float64

GetMeterRateStep

func Histogram

func Histogram(name string, count int64)

Histogram Actions

func Meter

func Meter(name string, count int64)

Meter Actions

func RenderJson

func RenderJson(w http.ResponseWriter, data interface{})

Render json

func RenderString

func RenderString(w http.ResponseWriter, msg string)

Render string

func SetCounter

func SetCounter(name string, count int64)

SetCounter

func SetDefaultSetting

func SetDefaultSetting(setting BeegoHttpSettings)

Overwrite default settings

func SetGauge

func SetGauge(name string, value float64)

SetGauge

func SetHistogram

func SetHistogram(name string, count int64)

SetHistogram

func SetMeter

func SetMeter(name string, count int64)

SetMeter

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

Types

type BeegoHttpRequest

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

BeegoHttpRequest provides more useful methods for requesting one url than http.Request.

func Delete

func Delete(url string) *BeegoHttpRequest

Delete returns *BeegoHttpRequest DELETE method.

func Get

func Get(url string) *BeegoHttpRequest

Get returns *BeegoHttpRequest with GET method.

func Head(url string) *BeegoHttpRequest

Head returns *BeegoHttpRequest with HEAD method.

func Post

func Post(url string) *BeegoHttpRequest

Post returns *BeegoHttpRequest with POST method.

func Put

func Put(url string) *BeegoHttpRequest

Put returns *BeegoHttpRequest with PUT method.

func (*BeegoHttpRequest) Body

func (b *BeegoHttpRequest) Body(data interface{}) *BeegoHttpRequest

Body adds request raw body. it supports string and []byte.

func (*BeegoHttpRequest) Bytes

func (b *BeegoHttpRequest) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*BeegoHttpRequest) Debug

func (b *BeegoHttpRequest) Debug(isdebug bool) *BeegoHttpRequest

Debug sets show debug or not when executing request.

func (*BeegoHttpRequest) Header

func (b *BeegoHttpRequest) Header(key, value string) *BeegoHttpRequest

Header add header item string in request.

func (*BeegoHttpRequest) Param

func (b *BeegoHttpRequest) Param(key, value string) *BeegoHttpRequest

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*BeegoHttpRequest) PostFile

func (b *BeegoHttpRequest) PostFile(formname, filename string) *BeegoHttpRequest

func (*BeegoHttpRequest) Response

func (b *BeegoHttpRequest) Response() (*http.Response, error)

Response executes request client gets response mannually.

func (*BeegoHttpRequest) SetBasicAuth

func (b *BeegoHttpRequest) SetBasicAuth(username, password string) *BeegoHttpRequest

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*BeegoHttpRequest) SetCookie

func (b *BeegoHttpRequest) SetCookie(cookie *http.Cookie) *BeegoHttpRequest

SetCookie add cookie into request.

func (*BeegoHttpRequest) SetEnableCookie

func (b *BeegoHttpRequest) SetEnableCookie(enable bool) *BeegoHttpRequest

SetEnableCookie sets enable/disable cookiejar

func (*BeegoHttpRequest) SetProtocolVersion

func (b *BeegoHttpRequest) SetProtocolVersion(vers string) *BeegoHttpRequest

Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*BeegoHttpRequest) SetProxy

func (b *BeegoHttpRequest) SetProxy(proxy func(*http.Request) (*url.URL, error)) *BeegoHttpRequest

Set http proxy example:

func(req *http.Request) (*url.URL, error) {
    u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
    return u, nil
}

func (*BeegoHttpRequest) SetTLSClientConfig

func (b *BeegoHttpRequest) SetTLSClientConfig(config *tls.Config) *BeegoHttpRequest

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*BeegoHttpRequest) SetTimeout

func (b *BeegoHttpRequest) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *BeegoHttpRequest

SetTimeout sets connect time out and read-write time out for BeegoRequest.

func (*BeegoHttpRequest) SetTransport

func (b *BeegoHttpRequest) SetTransport(transport http.RoundTripper) *BeegoHttpRequest

Set transport to

func (*BeegoHttpRequest) SetUserAgent

func (b *BeegoHttpRequest) SetUserAgent(useragent string) *BeegoHttpRequest

SetUserAgent sets User-Agent header field

func (*BeegoHttpRequest) Setting

Change request settings

func (*BeegoHttpRequest) String

func (b *BeegoHttpRequest) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*BeegoHttpRequest) ToFile

func (b *BeegoHttpRequest) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*BeegoHttpRequest) ToJson

func (b *BeegoHttpRequest) ToJson(v interface{}) error

ToJson returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*BeegoHttpRequest) ToXml

func (b *BeegoHttpRequest) ToXml(v interface{}) error

ToXml returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type BeegoHttpSettings

type BeegoHttpSettings struct {
	ShowDebug        bool
	UserAgent        string
	ConnectTimeout   time.Duration
	ReadWriteTimeout time.Duration
	TlsClientConfig  *tls.Config
	Proxy            func(*http.Request) (*url.URL, error)
	Transport        http.RoundTripper
	EnableCookie     bool
}

BeegoHttpSettings

type DebugMetrics

type DebugMetrics struct {
	GCStats struct {
		LastGC     metrics.Gauge
		NumGC      metrics.Gauge
		Pause      metrics.Histogram
		PauseTotal metrics.Gauge
	}
	ReadGCStats metrics.Histogram
}

DebugMetrics,Monitoring index of application in debug environment.

type GlobalConfig

type GlobalConfig struct {
	Debug    bool        `json:"debug"`
	Hostname string      `json:"hostname"`
	Tags     string      `json:"tags"`
	Step     int64       `json:"step"`
	Bases    []string    `json:"bases"`
	Push     *PushConfig `json:"push"`
	Http     *HttpConfig `json:"http"`
}

Global config of goappmonitor, and you can config it in cfg.json.

type HttpConfig

type HttpConfig struct {
	Enabled bool   `json:"enabled"`
	Listen  string `json:"listen"`
}

Http config about whether open local server and server address.

type MetricValue

type MetricValue struct {
	Endpoint  string      `json:"endpoint"`
	Metric    string      `json:"metric"`
	Value     interface{} `json:"value"`
	Step      int64       `json:"step"`
	Type      string      `json:"counterType"`
	Tags      string      `json:"tags"`
	Timestamp int64       `json:"timestamp"`
}

Data MetricValue struct.

func (*MetricValue) String

func (mv *MetricValue) String() string

Transfer to string.

type PushConfig

type PushConfig struct {
	Enabled bool   `json:"enabled"`
	Api     string `json:"api"`
}

Push config of pushing address and switcher.

type Response

type Response struct {
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

common http Response

type RuntimeMetrics

type RuntimeMetrics struct {
	MemStats struct {
		Alloc         metrics.Gauge
		BuckHashSys   metrics.Gauge
		DebugGC       metrics.Gauge
		EnableGC      metrics.Gauge
		Frees         metrics.Gauge
		HeapAlloc     metrics.Gauge
		HeapIdle      metrics.Gauge
		HeapInuse     metrics.Gauge
		HeapObjects   metrics.Gauge
		HeapReleased  metrics.Gauge
		HeapSys       metrics.Gauge
		LastGC        metrics.Gauge
		Lookups       metrics.Gauge
		Mallocs       metrics.Gauge
		MCacheInuse   metrics.Gauge
		MCacheSys     metrics.Gauge
		MSpanInuse    metrics.Gauge
		MSpanSys      metrics.Gauge
		NextGC        metrics.Gauge
		NumGC         metrics.Gauge
		GCCPUFraction metrics.GaugeFloat64
		PauseNs       metrics.Histogram
		PauseTotalNs  metrics.Gauge
		StackInuse    metrics.Gauge
		StackSys      metrics.Gauge
		Sys           metrics.Gauge
		TotalAlloc    metrics.Gauge
	}
	NumCgoCall   metrics.Gauge
	NumGoroutine metrics.Gauge
	ReadMemStats metrics.Histogram
}

RuntimeMetrics,Monitoring index of application in production environment.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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