prometheus

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxConnections     = 20
	DefaultInitConnections    = 5
	DefaultMaxIdleConnections = 10
	DefaultMaxIdleTime        = 1800 // seconds
	DefaultKeepAliveInterval  = 300  // seconds
	DefaultKeepAliveChunkSize = 5
	DefaultSleepTime          = 1 // seconds
)

Variables

View Source
var DefaultRoundTripper http.RoundTripper = &http.Transport{
	Proxy:               http.ProxyFromEnvironment,
	DialContext:         (&net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}).DialContext,
	TLSHandshakeTimeout: 10 * time.Second,
}

DefaultRoundTripper is used if no RoundTripper is set in Config,

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, keepAliveInterval int) error

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

func InitGlobalPoolWithConfig

func InitGlobalPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, 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

func (*Conn) Execute

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

Execute executes given command with arguments and return a result, note that args should must be either time.Time or apiv1.Range of prometheus golang client package

func (*Conn) ExecuteContext

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

ExecuteContext executes given command with arguments and return a result, note that args should must be either time.Time or apiv1.Range of prometheus golang client package

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, keepAliveInterval int) (*Pool, error)

NewPool returns a new *Pool

func NewPoolWithConfig

func NewPoolWithConfig(config Config, maxConnections, initConnections, maxIdleConnections, maxIdleTime, 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 simply returns *PoolConn, because it had implemented Transaction interface

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
	KeepAliveInterval  int
}

func NewPoolConfig

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

NewPoolConfig returns a new PoolConfig

func NewPoolConfigWithConfig

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

NewPoolConfigWithConfig returns a new PoolConfig

func (*PoolConfig) Validate

func (cfg *PoolConfig) Validate() (bool, 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 map[string]interface{}

func NewRawData

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

func (RawData) GetValue

func (rd RawData) GetValue() model.Value

func (RawData) GetWarnings

func (rd RawData) GetWarnings() apiv1.Warnings

type Result

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

func NewEmptyResult

func NewEmptyResult() *Result

func NewResult

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

Jump to

Keyboard shortcuts

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