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
- type Api
- func (a *Api) GetMachine(machineId string) (Machine, error)
- func (a *Api) GetMachineWithContext(ctx context.Context, machineId string) (Machine, error)
- func (a *Api) GetMachines() ([]Machine, error)
- func (a *Api) GetMachinesWithContext(ctx context.Context) ([]Machine, error)
- func (a *Api) GetMetric(metricId string) (Metric, error)
- func (a *Api) GetMetricWithContext(ctx context.Context, metricId string) (Metric, error)
- func (a *Api) GetMetrics() ([]Metric, error)
- func (a *Api) GetMetricsWithContext(ctx context.Context) ([]Metric, error)
- func (a *Api) GetPing() error
- func (a *Api) GetPingWithContext(ctx context.Context) error
- func (a *Api) GetWatchdog(watchdogId string) (Watchdog, error)
- func (a *Api) GetWatchdogWithContext(ctx context.Context, watchdogId string) (Watchdog, error)
- func (a *Api) GetWatchdogs() ([]Watchdog, error)
- func (a *Api) GetWatchdogsWithContext(ctx context.Context) ([]Watchdog, error)
- func (a *Api) PostMachineSample(machineId string, sample MachineSample) error
- func (a *Api) PostMachineSampleWithContext(ctx context.Context, machineId string, sample MachineSample) error
- func (a *Api) PostMachineText(machineId string, text string) error
- func (a *Api) PostMachineTextWithContext(ctx context.Context, machineId string, text string) error
- func (a *Api) PostMetricInc(metricId string, value int64) error
- func (a *Api) PostMetricIncWithContext(ctx context.Context, metricId string, value int64) error
- func (a *Api) PostMetricSet(metricId string, value int64) error
- func (a *Api) PostMetricSetWithContext(ctx context.Context, metricId string, value int64) error
- func (a *Api) PostMetricValues(metricId string, values []int64) error
- func (a *Api) PostMetricValuesWithContext(ctx context.Context, metricId string, values []int64) error
- func (a *Api) PostWatchdogHeartbeat(watchdogId string) error
- func (a *Api) PostWatchdogHeartbeatWithContext(ctx context.Context, watchdogId string) error
- type ApiOptions
- type DiskSample
- type Logger
- type Machine
- type MachineSample
- type Metric
- type NetSample
- type Watchdog
Constants ¶
const ( MetricTypeCounter int = 0 MetricTypeGauge int = 1 MetricTypeHistogram int = 2 )
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 ¶
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 ¶
GetMachine is like GetMachineWithContext using context.Background.
func (*Api) GetMachineWithContext ¶
GetMachineWithContext fetches a machine by id.
func (*Api) GetMachines ¶
GetMachines is like GetMachinesWithContext using context.Background.
func (*Api) GetMachinesWithContext ¶
GetMachinesWithContext fetches the list of machines.
func (*Api) GetMetricWithContext ¶
GetMetricWithContext fetches a metric by id.
func (*Api) GetMetrics ¶
GetMetrics is like GetMetricsWithContext using context.Background.
func (*Api) GetMetricsWithContext ¶
GetMetricsWithContext fetches the list of metrics.
func (*Api) GetPingWithContext ¶
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 ¶
GetWatchdog is like GetWatchdogWithContext using context.Background.
func (*Api) GetWatchdogWithContext ¶
GetWatchdogWithContext fetches a watchdog by id.
func (*Api) GetWatchdogs ¶
GetWatchdogs is like GetWatchdogsWithContext using context.Background.
func (*Api) GetWatchdogsWithContext ¶
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
PostMachineText is like PostMachineTextWithContext using context.Background.
func (*Api) PostMachineTextWithContext ¶ added in v0.0.9
PostMachineTextWithContext uploads a machine text to the API.
func (*Api) PostMetricInc ¶
PostMetricInc is like PostMetricIncWithContext using context.Background.
func (*Api) PostMetricIncWithContext ¶
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 ¶
PostMetricSet is like PostMetricSetWithContext using context.Background.
func (*Api) PostMetricSetWithContext ¶
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
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 ¶
PostWatchdogHeartbeat is like PostWatchdogHeartbeatWithContext using context.Background.
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 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.