monibot

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 9 Imported by: 1

README

monibot-go

GoDoc Reference Build Status

Golang SDK for https://monibot.io - Website-, Server- and Application Monitoring.

This module provides a SDK to interact with the Monibot REST API. Monibot is a service that monitors your web apps, servers and application metrics, and notifies you if something goes wrong.

Usage

go get github.com/cvilsmeier/monibot-go
import "github.com/cvilsmeier/monibot-go"

func main() {
	// api access requires an apiKey
	apiKey := os.Getenv("MONIBOT_API_KEY")
	// create new api
	api := monibot.NewApi(apiKey)
	// send a watchdog heartbeat
	api.PostWatchdogHeartbeat("a749ff35891ecb36")
	// increment a counter metric by 42
	api.PostMetricInc("ffe31498bc7193a4", 42)
}

Changelog

v0.3.0
  • add DiskSamples and NetSamples to MachineSample
v0.2.0
  • replace MachineSample DiskReads/Writes (number of sectors) with DiskRead/Write (number of bytes)
v0.1.1
  • add histogram values functions
v0.1.0
  • add histogram metric values
v0.0.9
  • add machine text
v0.0.8
  • fix disk/net usage samples
v0.0.7
  • added netRecv and netSend to machine sample
v0.0.6
  • added diskReads and diskWrites to machine sample
v0.0.5
v0.0.4
  • first version

License

MIT License, see LICENSE

Documentation

Overview

Package monibot provides a SDK to interact with the Monibot REST API, see https://monibot.io for details.

import "github.com/cvilsmeier/monibot-go"

func main() {
	// api access requires an apiKey
	apiKey := os.Getenv("MONIBOT_API_KEY")
	// create new api
	api := monibot.NewApi(apiKey)
	// send a watchdog heartbeat
	api.PostWatchdogHeartbeat("a749ff35891ecb36")
	// increment a counter metric by 42
	api.PostMetricInc("ffe31498bc7193a4", 42)
}

Index

Constants

View Source
const (
	MetricTypeCounter   int = 0
	MetricTypeGauge     int = 1
	MetricTypeHistogram int = 2
)
View Source
const Version = "0.3.0"

Version is monibot-go sdk version.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

Api provides access to the Monibot REST API. See https://monibot.io/docs/rest-api for authorization, rate-limits and usage.

func NewApi

func NewApi(apiKey string) *Api

NewApi creates an Api that sends data to https://monibot.io and retries 12 times every 5s if an error occurs, and logs nothing.

func NewApiWithOptions added in v0.0.7

func NewApiWithOptions(apiKey string, options ApiOptions) *Api

NewApiWithOptions creates an Api with custom options.

func (*Api) GetMachine

func (a *Api) GetMachine(machineId string) (Machine, error)

GetMachine is like GetMachineWithContext using context.Background.

func (*Api) GetMachineWithContext

func (a *Api) GetMachineWithContext(ctx context.Context, machineId string) (Machine, error)

GetMachineWithContext fetches a machine by id.

func (*Api) GetMachines

func (a *Api) GetMachines() ([]Machine, error)

GetMachines is like GetMachinesWithContext using context.Background.

func (*Api) GetMachinesWithContext

func (a *Api) GetMachinesWithContext(ctx context.Context) ([]Machine, error)

GetMachinesWithContext fetches the list of machines.

func (*Api) GetMetric

func (a *Api) GetMetric(metricId string) (Metric, error)

GetMetric is like GetMetricWithContext using context.Background.

func (*Api) GetMetricWithContext

func (a *Api) GetMetricWithContext(ctx context.Context, metricId string) (Metric, error)

GetMetricWithContext fetches a metric by id.

func (*Api) GetMetrics

func (a *Api) GetMetrics() ([]Metric, error)

GetMetrics is like GetMetricsWithContext using context.Background.

func (*Api) GetMetricsWithContext

func (a *Api) GetMetricsWithContext(ctx context.Context) ([]Metric, error)

GetMetricsWithContext fetches the list of metrics.

func (*Api) GetPing

func (a *Api) GetPing() error

GetPing is like GetPingWithContext using context.Background.

func (*Api) GetPingWithContext

func (a *Api) GetPingWithContext(ctx context.Context) error

GetPingWithContext pings the API. It is used to ensure everything is set up correctly and the API is reachable. It returns nil on success or a non-nil error if something goes wrong.

func (*Api) GetWatchdog

func (a *Api) GetWatchdog(watchdogId string) (Watchdog, error)

GetWatchdog is like GetWatchdogWithContext using context.Background.

func (*Api) GetWatchdogWithContext

func (a *Api) GetWatchdogWithContext(ctx context.Context, watchdogId string) (Watchdog, error)

GetWatchdogWithContext fetches a watchdog by id.

func (*Api) GetWatchdogs

func (a *Api) GetWatchdogs() ([]Watchdog, error)

GetWatchdogs is like GetWatchdogsWithContext using context.Background.

func (*Api) GetWatchdogsWithContext

func (a *Api) GetWatchdogsWithContext(ctx context.Context) ([]Watchdog, error)

GetWatchdogsWithContext fetches the list of watchdogs.

func (*Api) PostMachineSample

func (a *Api) PostMachineSample(machineId string, sample MachineSample) error

PostMachineSample is like PostMachineSampleWithContext using context.Background.

func (*Api) PostMachineSampleWithContext

func (a *Api) PostMachineSampleWithContext(ctx context.Context, machineId string, sample MachineSample) error

PostMachineSampleWithContext uploads a machine sample to the API.

func (*Api) PostMachineText added in v0.0.9

func (a *Api) PostMachineText(machineId string, text string) error

PostMachineText is like PostMachineTextWithContext using context.Background.

func (*Api) PostMachineTextWithContext added in v0.0.9

func (a *Api) PostMachineTextWithContext(ctx context.Context, machineId string, text string) error

PostMachineTextWithContext uploads a machine text to the API.

func (*Api) PostMetricInc

func (a *Api) PostMetricInc(metricId string, value int64) error

PostMetricInc is like PostMetricIncWithContext using context.Background.

func (*Api) PostMetricIncWithContext

func (a *Api) PostMetricIncWithContext(ctx context.Context, metricId string, value int64) error

PostMetricIncWithContext uploads a counter metric increment value to the API. It is used to increment a counter metric. It is an error to try to increment a non-counter metric. The value is a non-negative int64 number.

func (*Api) PostMetricSet

func (a *Api) PostMetricSet(metricId string, value int64) error

PostMetricSet is like PostMetricSetWithContext using context.Background.

func (*Api) PostMetricSetWithContext

func (a *Api) PostMetricSetWithContext(ctx context.Context, metricId string, value int64) error

PostMetricSetWithContext uploads a gauge metric value to the API. It is used to set a gauge metric. It is an error to try to set a non-gauge metric. The value is a non-negative int64 number.

func (*Api) PostMetricValues added in v0.1.0

func (a *Api) PostMetricValues(metricId string, values []int64) error

PostMetricValues is like PostMetricValuesWithContext using context.Background.

func (*Api) PostMetricValuesWithContext added in v0.1.0

func (a *Api) PostMetricValuesWithContext(ctx context.Context, metricId string, values []int64) error

PostMetricValuesWithContext uploads histogram metric values to the API. It is used to set a histogram metric. It is an error to try to send values to a non-histogram metric. Each values must be a non-negative 64-bit integer value.

func (*Api) PostWatchdogHeartbeat

func (a *Api) PostWatchdogHeartbeat(watchdogId string) error

PostWatchdogHeartbeat is like PostWatchdogHeartbeatWithContext using context.Background.

func (*Api) PostWatchdogHeartbeatWithContext

func (a *Api) PostWatchdogHeartbeatWithContext(ctx context.Context, watchdogId string) error

PostWatchdogHeartbeatWithContext sends a watchdog heartbeat.

type ApiOptions added in v0.0.7

type ApiOptions struct {

	// Default is no logging. If you want debug logging: Bring your own logger.
	Logger Logger

	// MonibotUrl is the base url to send api calls to.
	// Default is "https://monibot.io".
	MonibotUrl string

	// If an endpoint is not reachable, the api will try again,
	// until it succeeds or the maximum number of trial is reached.
	// Default is 12 trials.
	Trials int

	// The time to wait between trials.
	// Default is 5s delay between trials.
	Delay time.Duration

	// The "User-Agent" header value. The placeholder $sdkVersion, if present,
	// is substituted by the monibot-go sdk version.
	// Default is "$sdkVersion".
	UserAgent string
	// contains filtered or unexported fields
}

ApiOptions holds optional parameters for a Api.

type DiskSample added in v0.3.0

type DiskSample struct {
	Device      string // Disk device, e.g. "/dev/sda1"
	Mountpoint  string // Mount point, e.g. "/mnt/HC_Volume_102242198"
	Total       int64  // Total size in bytes, 0..MAX_I64
	Used        int64  // Used size in bytes, 0..MAX_I64
	UsedPercent int    // Usage in percent, 0..100
	ReadBytes   int64  // Number of bytes read since last sample, 0..MAX_I64
	WriteBytes  int64  // Number of bytes written since last sample, 0..MAX_I64
}

A DiskSample is part of a MachineSample.

type Logger

type Logger interface {

	// Debug prints a debug message.
	Debug(format string, args ...any)
}

A Logger prints debug messages.

type Machine

type Machine struct {
	Id   string `json:"id"`
	Name string `json:"name"`
}

Machine holds data for a Machine.

type MachineSample

type MachineSample struct {
	Tstamp      int64        // Unix time millis since 1970-01-01T00:00:00Z, always UTC, never local time.
	Load1       float64      // Loadavg 1 minute.
	Load5       float64      // Loadavg 5 minutes.
	Load15      float64      // Loadavg 15 minutes.
	CpuPercent  int          // CPU usage percent 0..100 since last sample.
	MemPercent  int          // Memory usage percent 0..100.
	Disks       []DiskSample // Disk samples, one for each disk.
	DiskPercent int          // Disk usage percent 0..100.
	DiskRead    int64        // Number of disk bytes read since last sample.
	DiskWrite   int64        // Number of disk bytes written since last sample.
	Nets        []NetSample  // Network samples, one for each network device.
	NetRecv     int64        // Number of network bytes received since last sample.
	NetSend     int64        // Number of network bytes sent since last sample.
}

A MachineSample holds data for a machine resource usage sample.

type Metric

type Metric struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Type int    `json:"type"` // 0=Counter, 1=Gauge, 2=Histogram
}

Metric holds data for a Metric.

type NetSample added in v0.3.0

type NetSample struct {
	Device    string // Disk device, e.g. "/dev/sda1"
	RecvBytes int64  // Number of bytes received since last sample, 0..MAX_I64
	SendBytes int64  // Number of bytes sent since last sample, 0..MAX_I64
}

A NetSample is part of a MachineSample.

type Watchdog

type Watchdog struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	IntervalMillis int64  `json:"intervalMillis"`
}

Watchdog holds data for a Watchdog.

Directories

Path Synopsis
internal
assert
Package assert provides assertion functions for unit tests.
Package assert provides assertion functions for unit tests.
check command

Jump to

Keyboard shortcuts

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