prometheus

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStep = time.Minute

	DefaultDialTimeout         = 30 * time.Second
	DefaultKeepAlive           = 30 * time.Second
	DefaultTLSHandshakeTimeout = 10 * time.Second
)
View Source
const (
	DefaultMaxConnections     = 20
	DefaultInitConnections    = 5
	DefaultMaxIdleConnections = 10
	DefaultMaxIdleTime        = 1800 // seconds
	DefaultMaxWaitTime        = 1    // seconds
	DefaultMaxRetryCount      = -1
	DefaultKeepAliveInterval  = 300 // seconds
	DefaultKeepAliveChunkSize = 5
	DefaultSleepTime          = 1 // seconds

	DefaultUnlimitedWaitTime   = -1 // seconds
	DefaultUnlimitedRetryCount = -1
	DefaultDelayTime           = 5 // milliseconds
)

Variables

View Source
var (
	DefaultDialer = &net.Dialer{
		Timeout:   DefaultDialTimeout,
		KeepAlive: DefaultKeepAlive,
	}

	// DefaultRoundTripper is used if no RoundTripper is set in Config,
	DefaultRoundTripper http.RoundTripper = &http.Transport{
		Proxy:               http.ProxyFromEnvironment,
		DialContext:         DefaultDialer.DialContext,
		TLSHandshakeTimeout: DefaultTLSHandshakeTimeout,
	}
)

Functions

func Close

func Close() error

Close closes global pool, it sets global pool to nil pointer

func Execute

func Execute(command string, args ...interface{}) (middleware.Result, error)

Execute execute given sql statement

func ExecuteContext

func ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)

ExecuteContext executes given command with context

func InitGlobalPool

func InitGlobalPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) error

InitGlobalPool returns a new *Pool and replaces it as global pool

func InitGlobalPoolWithConfig

func InitGlobalPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) error

InitGlobalPoolWithConfig returns a new *Pool with a Config object and replaces it as global pool

func InitGlobalPoolWithDefault

func InitGlobalPoolWithDefault(addr string) error

InitGlobalPoolWithDefault returns a new *Pool with default configuration and replaces it as global pool

func InitGlobalPoolWithPoolConfig

func InitGlobalPoolWithPoolConfig(config PoolConfig) error

InitGlobalPoolWithPoolConfig returns a new *Pool with a PoolConfig object and replaces it as global pool

func IsClosed

func IsClosed() bool

IsClosed returns if global pool had been closed

func Release

func Release(num int) error

Release releases given number of connections of global pool, each connection will disconnect with database

func ReplaceGlobalPool

func ReplaceGlobalPool(pool *Pool) error

ReplaceGlobalPool replaces given pool as global pool

func Supply

func Supply(num int) error

Supply creates given number of connections and add them to free connection channel of global pool

Types

type Config

type Config struct {
	client.Config
}

func NewConfig

func NewConfig(addr string, rt http.RoundTripper) Config

NewConfig returns a new client.Config with given address and round tripper

func NewConfigWithBasicAuth

func NewConfigWithBasicAuth(addr, user, pass string) Config

NewConfigWithBasicAuth returns a new client.Config with given address, user and password

func NewConfigWithDefaultRoundTripper

func NewConfigWithDefaultRoundTripper(addr string) Config

NewConfigWithDefaultRoundTripper returns a new client.Config with given address and default round tripper

type Conn

type Conn struct {
	apiv1.API
}

func NewConn

func NewConn(addr string, rt http.RoundTripper) (*Conn, error)

NewConn returns a new *Conn with given address and round tripper

func NewConnWithConfig

func NewConnWithConfig(config Config) (*Conn, error)

NewConnWithConfig returns a new *Conn with given config

func (*Conn) CheckInstanceStatus

func (conn *Conn) CheckInstanceStatus() bool

CheckInstanceStatus checks prometheus instance status

func (*Conn) Execute

func (conn *Conn) Execute(command string, args ...interface{}) (*Result, error)

Execute executes given command with arguments and returns a result

func (*Conn) ExecuteContext

func (conn *Conn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (*Result, error)

ExecuteContext executes given command with arguments and returns a result

type Pool

type Pool struct {
	sync.Mutex
	PoolConfig
	// contains filtered or unexported fields
}

func NewPool

func NewPool(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) (*Pool, error)

NewPool returns a new *Pool

func NewPoolWithConfig

func NewPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) (*Pool, error)

NewPoolWithConfig returns a new *Pool with a Config object

func NewPoolWithDefault

func NewPoolWithDefault(addr string) (*Pool, error)

NewPoolWithDefault returns a new *Pool with default configuration

func NewPoolWithPoolConfig

func NewPoolWithPoolConfig(config PoolConfig) (*Pool, error)

NewPoolWithPoolConfig returns a new *Pool with a PoolConfig object

func (*Pool) Close

func (p *Pool) Close() error

Close releases each connection in the pool

func (*Pool) Get

func (p *Pool) Get() (middleware.PoolConn, error)

Get is an exported alias of get() function with routine safe

func (*Pool) IsClosed

func (p *Pool) IsClosed() bool

IsClosed returns if pool had been closed

func (*Pool) Release

func (p *Pool) Release(num int) error

Release is an exported alias of release() function

func (*Pool) Supply

func (p *Pool) Supply(num int) error

Supply is an exported alias of supply() function with routine safe

func (*Pool) Transaction

func (p *Pool) Transaction() (middleware.Transaction, error)

Transaction is used to implement the interface, but it is not supported in prometheus, never call this function

func (*Pool) UsedConnections

func (p *Pool) UsedConnections() int

UsedConnections returns used connection number

type PoolConfig

type PoolConfig struct {
	Config
	MaxConnections     int
	InitConnections    int
	MaxIdleConnections int
	MaxIdleTime        int
	MaxWaitTime        int
	MaxRetryCount      int
	KeepAliveInterval  int
}

func NewPoolConfig

func NewPoolConfig(addr string, rt http.RoundTripper, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) PoolConfig

NewPoolConfig returns a new PoolConfig

func NewPoolConfigWithConfig

func NewPoolConfigWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime,
	maxWaitTime, maxRetryCount, keepAliveInterval int) PoolConfig

NewPoolConfigWithConfig returns a new PoolConfig

func (*PoolConfig) Validate

func (cfg *PoolConfig) Validate() error

Validate validates pool config

type PoolConn

type PoolConn struct {
	*Conn
	Pool *Pool
}

func Get

func Get() (*PoolConn, error)

Get get gets a connection from pool and validate it, if there is no valid connection in the pool, it will create a new connection

func NewPoolConn

func NewPoolConn(addr string, rt http.RoundTripper) (*PoolConn, error)

NewPoolConn returns a new *PoolConn

func NewPoolConnWithPool

func NewPoolConnWithPool(pool *Pool, addr string, rt http.RoundTripper) (*PoolConn, error)

NewPoolConnWithPool returns a new *PoolConn

func (*PoolConn) Close

func (pc *PoolConn) Close() error

Close returns connection back to the pool

func (*PoolConn) Disconnect

func (pc *PoolConn) Disconnect() error

Disconnect disconnects from mysql, normally when using connection pool, there is no need to disconnect manually, consider to use Close() instead.

func (*PoolConn) Execute

func (pc *PoolConn) Execute(command string, args ...interface{}) (middleware.Result, error)

Execute executes given sql and placeholders on the mysql server

func (*PoolConn) ExecuteContext

func (pc *PoolConn) ExecuteContext(ctx context.Context, command string, args ...interface{}) (middleware.Result, error)

ExecuteContext executes given sql and placeholders on the mysql server

func (*PoolConn) IsValid

func (pc *PoolConn) IsValid() bool

IsValid validates if connection is valid

func (*PoolConn) Prepare

func (pc *PoolConn) Prepare(command string) (middleware.Statement, error)

Prepare prepares a statement and returns a *Statement

func (*PoolConn) PrepareContext

func (pc *PoolConn) PrepareContext(ctx context.Context, command string) (middleware.Statement, error)

PrepareContext prepares a statement with context and returns a *Statement

type RawData

type RawData struct {
	Value    model.Value
	Warnings apiv1.Warnings
}

func NewRawData

func NewRawData(value model.Value, warnings apiv1.Warnings) *RawData

NewRawData returns a new RawData

func (*RawData) GetMatrix added in v0.3.11

func (rd *RawData) GetMatrix() (model.Matrix, error)

func (*RawData) GetScalar added in v0.3.11

func (rd *RawData) GetScalar() (*model.Scalar, error)

func (*RawData) GetString added in v0.3.11

func (rd *RawData) GetString() (*model.String, error)

func (*RawData) GetValue

func (rd *RawData) GetValue() model.Value

GetValue returns value

func (*RawData) GetVector added in v0.3.11

func (rd *RawData) GetVector() (model.Vector, error)

func (*RawData) GetWarnings

func (rd *RawData) GetWarnings() apiv1.Warnings

GetWarnings returns warnings

type Result

type Result struct {
	Raw *RawData
	*result.Rows
	result.Metadata
	result.Map
}

func NewEmptyResult

func NewEmptyResult() *Result

NewEmptyResult returns a new empty *Result

func NewResult

func NewResult(value model.Value, warnings apiv1.Warnings) *Result

NewResult returns a new *Result with given value and warnings note that if return value is matrix type, only the first matrix will be processed, all others will be discarded, if a query returns more than one matrix, use GetRaw() function to get the raw data which is returned by prometheus go client package

func (*Result) GetRaw added in v0.3.3

func (r *Result) GetRaw() interface{}

GetRaw returns the raw data of the result

type TimeRange added in v0.3.1

type TimeRange struct {
	apiv1.Range
}

func NewTimeRange added in v0.3.1

func NewTimeRange(start, end time.Time, step time.Duration) TimeRange

NewTimeRange returns a new TimeRange

func NewTimeRangeWithRange added in v0.3.2

func NewTimeRangeWithRange(r apiv1.Range) TimeRange

NewTimeRangeWithRange returns a new TimeRange with given apiv1.Range

func (TimeRange) GetRange added in v0.3.1

func (tr TimeRange) GetRange() apiv1.Range

GetRange returns apiv1.Range

Jump to

Keyboard shortcuts

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