agent

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

README

Prometheus 远程写入代理

该代理用于将指标写入远程 Prometheus 服务器.

核心组件

  • input 接口:实现该接口的类将被用于接收指标数据
  • reader 接口:读取 input 接口的数据,并将其转换为指标数据,一个 input 对应一个 reader,写入 output 接口
  • output 接口:转换 reader 接口的数据为 Prometheus 协议数据 ,并将其写入远程 Prometheus 服务器
  • remote write 接口:实现 Prometheus Remote Write 协议,用于将指标写入远程 Prometheus 服务器

配置

使用

示例

后续计划

  • [] 增加 Prometheus metrics 接口注册和注销功能

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent interface {
	// Start starts the agent
	Start() error
	// Flush flushes the metrics
	Flush() error
	// Stop stops the agent
	Stop() error
}

func New

func New(endpoint string, opts ...Option) (Agent, error)

New creates a new Agent

type Input

type Input interface {
	// Init initializes the input.
	Init() error
	// Gather gathers the data.
	Gather() ([]*types.Sample, error)
	// GetInterval returns the interval of the input.
	GetInterval() time.Duration
	// Prefix returns the prefix of the input.
	Prefix() string
	// String returns the name of the input.
	String() string
	// Close closes the input.
	Close() error
}

type Option

type Option func(o *Options)

func WithInput

func WithInput(inputs ...Input) Option

WithInput sets an input to use.

func WithOutput

func WithOutput(output Output) Option

WithOutput sets an output to use.

func WithOutputDebug

func WithOutputDebug(v bool) Option

WithOutputDebug sets a debug mode for the output.

func WithReaderBatchSize

func WithReaderBatchSize(batchSize int) Option

WithReaderBatchSize sets a batch size for the reader.

func WithReaderInterval

func WithReaderInterval(interval time.Duration) Option

WithReaderInterval sets an interval for the reader.

func WithReaderOutputInterval

func WithReaderOutputInterval(interval time.Duration) Option

WithReaderOutputInterval sets an interval for the output.

func WithReaderQueueSize

func WithReaderQueueSize(queueSize int) Option

WithReaderQueueSize sets a queue size for the reader.

func WithReaderTags

func WithReaderTags(tags map[string]string) Option

WithReaderTags sets tags to use for the reader.

type Options

type Options struct {
	Debug         bool          // debug mode
	Inputs        []Input       // inputs to use
	Output        Output        // output to use
	ReaderOptions ReaderOptions // reader options
}

type Output

type Output interface {
	Write(ctx context.Context, items []*types.Sample) error
}

Output interface wraps the Write method.

func NewOutput

func NewOutput(remote RemoteWriter, opts ...OutputOption) Output

NewOutput returns a new Output.

type OutputOption

type OutputOption func(o *OutputOptions)

func WithDebug

func WithDebug(v bool) OutputOption

WithDebug sets a debug mode for the output.

func WithTimeout

func WithTimeout(timeout time.Duration) OutputOption

WithTimeout sets a timeout for the output.

type OutputOptions

type OutputOptions struct {
	Debug        bool          // debug mode
	Timeout      time.Duration // timeout for the output
	RemoteWriter RemoteWriter  // Prometheus Protocol remote writer to use
}

type Reader

type Reader interface {
	Init(input Input, output Output) error
	Start() error
	Stop() error
	Flush() error
	String() string
}

func NewReader

func NewReader(opts ...ReaderOption) Reader

NewReader returns a new Reader.

type ReaderOption

type ReaderOption func(o *ReaderOptions)

func WithBatchSize

func WithBatchSize(batchSize int) ReaderOption

WithBatchSize sets a batch size for the reader.

func WithInterval

func WithInterval(interval time.Duration) ReaderOption

WithInterval sets an interval for the reader.

func WithOutputInterval

func WithOutputInterval(interval time.Duration) ReaderOption

WithOutputInterval sets an interval for the output.

func WithQueueSize

func WithQueueSize(queueSize int) ReaderOption

WithQueueSize sets a queue size for the reader.

func WithTags

func WithTags(tags map[string]string) ReaderOption

WithTags sets tags to use for the reader.

type ReaderOptions

type ReaderOptions struct {
	Tags           map[string]string // tags to use
	QueueSize      int               // queue size for the reader
	Interval       time.Duration     // interval for the reader
	BatchSize      int               // batch size for the reader
	OutputInterval time.Duration     // interval for the output
}

type RemoteWriter

type RemoteWriter interface {
	Write(ctx context.Context, items []prompb.TimeSeries) error
}

RemoteWriter interface wraps the Write method.

func NewRemoteWriter

func NewRemoteWriter(endpoint string, opts ...RemoteWriterOption) (RemoteWriter, error)

NewRemoteWriter returns a RemoteWriter.

type RemoteWriterOption

type RemoteWriterOption func(o *RemoteWriterOptions)

func WithBasicPassword

func WithBasicPassword(basicPassword string) RemoteWriterOption

WithBasicPassword sets a basic auth password to use.

func WithBasicUsername

func WithBasicUsername(username string) RemoteWriterOption

WithBasicUsername sets a basic auth username to use.

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) RemoteWriterOption

WithDialTimeout sets a timeout for the dial.

func WithMaxIdleConnsPerHost

func WithMaxIdleConnsPerHost(v int) RemoteWriterOption

WithMaxIdleConnsPerHost sets a max idle conns per host to use.

func WithResponseHeaderTimeout

func WithResponseHeaderTimeout(timeout time.Duration) RemoteWriterOption

WithResponseHeaderTimeout sets a timeout for the response header.

type RemoteWriterOptions

type RemoteWriterOptions struct {
	Endpoint              string        // endpoint of the remote writer
	BasicUsername         string        // basic auth username
	BasicPassword         string        // basic auth password
	DialTimeout           time.Duration // timeout for the dial
	ResponseHeaderTimeout time.Duration // timeout for the response header
	MaxIdleConnsPerHost   int           // max idle conns per host
}

Directories

Path Synopsis
inputs
pkg

Jump to

Keyboard shortcuts

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