client

package
v0.13.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2016 License: MIT Imports: 12 Imported by: 0

README

Kapacitor HTTP API Go client

This package provides an official Go client package for the Kapacitor HTTP API.

API stability

NOTE: This package will not be considered stable until the 1.0 release of Kapacitor.

This is version 1 of the client, after the 1.0 release no breaking changes will be made to this package. Future versions may be added as necessary.

Docs

Documentation

Overview

Kapacitor HTTP API client written in Go

Index

Constants

View Source
const DefaultUserAgent = "KapacitorClient"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Basic HTTP client

func New

func New(conf Config) (*Client, error)

Create a new client.

func (*Client) CreateReplay

func (c *Client) CreateReplay(opt CreateReplayOptions) (Replay, error)

Replay a recording for a task.

func (*Client) CreateTask

func (c *Client) CreateTask(opt CreateTaskOptions) (Task, error)

Create a new task. Errors if the task already exists.

func (*Client) DeleteRecording

func (c *Client) DeleteRecording(link Link) error

Delete a recording.

func (*Client) DeleteReplay

func (c *Client) DeleteReplay(link Link) error

Delete a replay. This will cancel a running replay.

func (*Client) DeleteTask

func (c *Client) DeleteTask(link Link) error

Delete a task.

func (*Client) ListRecordings

func (c *Client) ListRecordings(opt *ListRecordingsOptions) ([]Recording, error)

Get information about recordings. If rids is empty than all recordings are returned.

func (*Client) ListReplays

func (c *Client) ListReplays(opt *ListReplaysOptions) ([]Replay, error)

Get information about replays. If rids is empty than all replays are returned.

func (*Client) ListTasks

func (c *Client) ListTasks(opt *ListTasksOptions) ([]Task, error)

Get tasks.

func (*Client) LogLevel

func (c *Client) LogLevel(level string) error

Set the logging level. Level must be one of DEBUG, INFO, WARN, ERROR, or OFF

func (*Client) Ping

func (c *Client) Ping() (time.Duration, string, error)

Ping the server for a response. Ping returns how long the request took, the version of the server it connected to, and an error if one occurred.

func (*Client) RecordBatch

func (c *Client) RecordBatch(opt RecordBatchOptions) (Recording, error)

Record the batch queries for a task. Returns once the recording is started.

func (*Client) RecordQuery

func (c *Client) RecordQuery(opt RecordQueryOptions) (Recording, error)

Record the results of a query. The recordingType must be one of "stream", or "batch". Returns once the recording is started.

func (*Client) RecordStream

func (c *Client) RecordStream(opt RecordStreamOptions) (Recording, error)

Record the stream for a task. Returns once the recording is started.

func (*Client) Recording

func (c *Client) Recording(link Link) (Recording, error)

Get information about a recording.

func (c *Client) RecordingLink(id string) Link

func (*Client) Replay

func (c *Client) Replay(link Link) (Replay, error)

Return the replay information

func (c *Client) ReplayLink(id string) Link

func (*Client) Task

func (c *Client) Task(link Link, opt *TaskOptions) (Task, error)

Get information about a task. Options can be nil and the default options will be used. By default the DOT content will use attributes for stats. Use DotView="labels" to generate a purley labels based DOT content, which can accurately be rendered but is less readable. By default the TICKscript contents are formatted, use ScriptFormat="raw" to return the TICKscript unmodified.

func (c *Client) TaskLink(id string) Link

func (*Client) TaskOutput

func (c *Client) TaskOutput(link Link, name string) (*influxql.Result, error)

func (*Client) UpdateTask

func (c *Client) UpdateTask(link Link, opt UpdateTaskOptions) error

Update an existing task. Only fields that are not their default value will be updated.

type Clock

type Clock int
const (
	Fast Clock = iota
	Real
)

func (Clock) MarshalText

func (c Clock) MarshalText() ([]byte, error)

func (Clock) String

func (c Clock) String() string

func (*Clock) UnmarshalText

func (c *Clock) UnmarshalText(text []byte) error

type Config

type Config struct {
	// The URL of the Kapacitor server.
	URL string

	// Timeout for API requests, defaults to no timeout.
	Timeout time.Duration

	// UserAgent is the http User Agent, defaults to "KapacitorClient".
	UserAgent string

	// InsecureSkipVerify gets passed to the http client, if true, it will
	// skip https certificate verification. Defaults to false.
	InsecureSkipVerify bool

	// TLSConfig allows the user to set their own TLS config for the HTTP
	// Client. If set, this option overrides InsecureSkipVerify.
	TLSConfig *tls.Config
}

HTTP configuration for connecting to Kapacitor

type CreateReplayOptions

type CreateReplayOptions struct {
	ID            string `json:"id"`
	Recording     string `json:"recording"`
	Task          string `json:"task"`
	RecordingTime bool   `json:"recording-time"`
	Clock         Clock  `json:"clock"`
}

func (*CreateReplayOptions) Default

func (o *CreateReplayOptions) Default()

type CreateTaskOptions

type CreateTaskOptions struct {
	ID         string     `json:"id,omitempty"`
	Type       TaskType   `json:"type,omitempty"`
	DBRPs      []DBRP     `json:"dbrps,omitempty"`
	TICKscript string     `json:"script,omitempty"`
	Status     TaskStatus `json:"status,omitempty"`
}

type DBRP

type DBRP struct {
	Database        string `json:"db"`
	RetentionPolicy string `json:"rp"`
}

func (DBRP) String

func (d DBRP) String() string

type ExecutionStats

type ExecutionStats struct {
	// Summary stats about the entire task
	TaskStats map[string]interface{} `json:"task-stats"`
	// Stats for each node in the task
	NodeStats map[string]map[string]interface{} `json:"node-stats"`
}

Statistics about the execution of a task.

type Link struct {
	Relation Relation `json:"rel"`
	Href     string   `json:"href"`
}

type ListRecordingsOptions

type ListRecordingsOptions struct {
	Pattern string
	Fields  []string
	Offset  int
	Limit   int
}

func (*ListRecordingsOptions) Default

func (o *ListRecordingsOptions) Default()

func (*ListRecordingsOptions) Values

func (o *ListRecordingsOptions) Values() *url.Values

type ListReplaysOptions

type ListReplaysOptions struct {
	Pattern string
	Fields  []string
	Offset  int
	Limit   int
}

func (*ListReplaysOptions) Default

func (o *ListReplaysOptions) Default()

func (*ListReplaysOptions) Values

func (o *ListReplaysOptions) Values() *url.Values

type ListTasksOptions

type ListTasksOptions struct {
	TaskOptions
	Pattern string
	Fields  []string
	Offset  int
	Limit   int
}

func (*ListTasksOptions) Default

func (o *ListTasksOptions) Default()

func (*ListTasksOptions) Values

func (o *ListTasksOptions) Values() *url.Values

type LogLevelOptions

type LogLevelOptions struct {
	Level string `json:"level"`
}

type RecordBatchOptions

type RecordBatchOptions struct {
	ID      string    `json:"id,omitempty"`
	Task    string    `json:"task"`
	Start   time.Time `json:"start"`
	Stop    time.Time `json:"stop"`
	Cluster string    `json:"cluster,omitempty"`
}

type RecordQueryOptions

type RecordQueryOptions struct {
	ID      string   `json:"id,omitempty"`
	Query   string   `json:"query"`
	Type    TaskType `json:"type"`
	Cluster string   `json:"cluster,omitempty"`
}

type RecordStreamOptions

type RecordStreamOptions struct {
	ID   string    `json:"id,omitempty"`
	Task string    `json:"task"`
	Stop time.Time `json:"stop"`
}

type Recording

type Recording struct {
	Link     Link      `json:"link"`
	ID       string    `json:"id"`
	Type     TaskType  `json:"type"`
	Size     int64     `json:"size"`
	Date     time.Time `json:"date"`
	Error    string    `json:"error"`
	Status   Status    `json:"status"`
	Progress float64   `json:"progress"`
}

Information about a recording.

type Relation

type Relation int
const (
	Self Relation = iota
	Next
	Previous
)

func (Relation) MarshalText

func (r Relation) MarshalText() ([]byte, error)

func (Relation) String

func (r Relation) String() string

func (*Relation) UnmarshalText

func (r *Relation) UnmarshalText(text []byte) error

type Replay

type Replay struct {
	Link          Link      `json:"link"`
	ID            string    `json:"id"`
	Task          string    `json:"task"`
	Recording     string    `json:"recording"`
	RecordingTime bool      `json:"recording-time"`
	Clock         Clock     `json:"clock"`
	Date          time.Time `json:"date"`
	Error         string    `json:"error"`
	Status        Status    `json:"status"`
	Progress      float64   `json:"progress"`
}

Information about a replay.

type Status

type Status int
const (
	Failed Status = iota
	Running
	Finished
)

func (Status) MarshalText

func (s Status) MarshalText() ([]byte, error)

func (Status) String

func (s Status) String() string

func (*Status) UnmarshalText

func (s *Status) UnmarshalText(text []byte) error

type Task

type Task struct {
	Link           Link           `json:"link"`
	ID             string         `json:"id"`
	Type           TaskType       `json:"type"`
	DBRPs          []DBRP         `json:"dbrps"`
	TICKscript     string         `json:"script"`
	Dot            string         `json:"dot"`
	Status         TaskStatus     `json:"status"`
	Executing      bool           `json:"executing"`
	Error          string         `json:"error"`
	ExecutionStats ExecutionStats `json:"stats"`
	Created        time.Time      `json:"created"`
	Modified       time.Time      `json:"modified"`
	LastEnabled    time.Time      `json:"last-enabled,omitempty"`
}

A Task plus its read-only attributes.

type TaskOptions

type TaskOptions struct {
	DotView      string
	ScriptFormat string
}

func (*TaskOptions) Default

func (o *TaskOptions) Default()

func (*TaskOptions) Values

func (o *TaskOptions) Values() *url.Values

type TaskStatus

type TaskStatus int
const (
	Disabled TaskStatus = 1
	Enabled  TaskStatus = 2
)

func (TaskStatus) MarshalText

func (ts TaskStatus) MarshalText() ([]byte, error)

func (TaskStatus) String

func (ts TaskStatus) String() string

func (*TaskStatus) UnmarshalText

func (ts *TaskStatus) UnmarshalText(text []byte) error

type TaskType

type TaskType int
const (
	StreamTask TaskType = 1
	BatchTask  TaskType = 2
)

func (TaskType) MarshalText

func (tt TaskType) MarshalText() ([]byte, error)

func (TaskType) String

func (tt TaskType) String() string

func (*TaskType) UnmarshalText

func (tt *TaskType) UnmarshalText(text []byte) error

type UpdateTaskOptions

type UpdateTaskOptions struct {
	Type       TaskType   `json:"type,omitempty"`
	DBRPs      []DBRP     `json:"dbrps,omitempty"`
	TICKscript string     `json:"script,omitempty"`
	Status     TaskStatus `json:"status,omitempty"`
}

Jump to

Keyboard shortcuts

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