Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.
/ go-monitor Public archive

a simple and extensible way to build monitorizable go process via HTTP.

License

Notifications You must be signed in to change notification settings

mcuadros/go-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

a simple and extensible way to build monitorizable go process via HTTP.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages