monitor

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2015 License: MIT Imports: 5 Imported by: 6

README

go-monitor Build Status GoDoc GitHub release

The main goal of go-monitor is provide a simple and extensible way to build monitorizable long term execution processes or daemons via HTTP.

Thanks to the defaults aspects you can monitorize parameters as runtime, memory, etc. for any Go processes and daemons. As well you can create your custom aspects for monitorize custom parameters from your applications.

Installation

The recommended way to install go-monitor

go get gopkg.in/mcuadros/go-monitor.v1

Examples

Default Monitor

Import the package:

import "gopkg.in/mcuadros/go-monitor.v1"

Start the monitor just before of the bootstrap of your code:

m := monitor.NewMonitor(":9000")
m.Start()

Now just try curl http://localhost:9000/

{
  "MemStats": {
    "Alloc": 7716521256,
    "TotalAlloc": 1935822232552,
    "Sys": 46882078488,
    ...
  },
  "Runtime": {
    "GoVersion": "go1.3.3",
    "GoOs": "linux",
    "GoArch": "amd64",
    "CpuNum": 24,
    "GoroutineNum": 21196,
    "Gomaxprocs": 24,
    "CgoCallNum": 111584
  }
}

At the / you can find all the aspects that are loaded by default, you can request other aspects through the URL /<aspect-name>,<aspect-name>

Custom Monitor

Define your custom aspect, in this case just a simple one that count the number of hits on it.

type CustomAspect struct {
  Count int
}

func (a *CustomAspect) GetStats() interface{} {
  a.Count++
  return a.Count
}

func (a *CustomAspect) Name() string {
  return "Custom"
}

func (a *CustomAspect) InRoot() bool {
  return false
}

Now just add the CustomAspect to the monitor and run it.

m := monitor.NewMonitor(":9000")
m.AddAspect(&CustomAspect{})
m.Start()

Hit http://localhost:9000/Custom and obtain:

{
  "Custom": 5
}

License

MIT, see LICENSE

Documentation

Overview

The main goal of `go-monitor` is provide a simple and extensible way to build monitorizable long term execution processes or daemons via HTTP.

Thanks to the defaults `aspects` you can monitorize parameters as runtime, memory, etc. for any Go processes and daemons. As well you can create your custom `aspects` for monitorize custom parameters from your applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	Addr    string
	Aspects map[string]aspects.Aspect

	sync.Mutex
	// contains filtered or unexported fields
}

func NewMonitor

func NewMonitor(addr string) *Monitor

NewMonitor returns a new Monitor, with the standard Aspects (time, runtime and memory)

func NewPlainMonitor

func NewPlainMonitor(addr string) *Monitor

NewPlainMonitor returns a new Monitor, without aspects

func (*Monitor) AddAspect

func (m *Monitor) AddAspect(a aspects.Aspect)

AddAspect adds a new `aspects.Aspect` to the Monitor

func (*Monitor) ServeHTTP

func (m *Monitor) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Monitor) Start

func (m *Monitor) Start() error

Start launch the HTTP server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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