daemon

package
v0.0.0-...-9b34e06 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxAttempts specifies the max allowed requests
	MaxAttempts int = 3
	// Attempts is the retried times
	Attempts int = iota
	// Retry saves the retry time
	Retry
)
View Source
const DaemonPort = "10590"

DaemonPort is the default port that the daemon will be listening at

Variables

This section is empty.

Functions

func Install

func Install()

Install adds the server into the background service

func IsBackendAlive

func IsBackendAlive(u *url.URL) bool

IsBackendAlive checks if the given url is alive

func NewMetric

func NewMetric(m *Metric, subsystem string) prometheus.Collector

NewMetric associates prometheus.Collector based on Metric.Type

func RunServer

func RunServer(port string, sslcert string, sslkey string)

RunServer starts the http(s) service

func Uninstall

func Uninstall()

Uninstall removes the background daemon service

Types

type Backend

type Backend struct {
	URL   *url.URL
	Alive bool

	ReverseProxy *httputil.ReverseProxy
	// contains filtered or unexported fields
}

Backend defines the struct for remote nodes

func (*Backend) IsAlive

func (b *Backend) IsAlive() (alive bool)

IsAlive returns if the node is alive or not

func (*Backend) SetAlive

func (b *Backend) SetAlive(alive bool)

SetAlive tells the server that a certain node is alive or not

type Metric

type Metric struct {
	MetricCollector prometheus.Collector
	ID              string
	Name            string
	Description     string
	Type            string
	Args            []string
}

Metric is a definition for the name, description, type, ID, and prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric

type Prometheus

type Prometheus struct {
	Ppg PrometheusPushGateway

	MetricsList []*Metric
	MetricsPath string

	ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn

	// gin.Context string to use as a prometheus URL label
	URLLabelFromContext string
	// contains filtered or unexported fields
}

Prometheus contains the metrics gathered by the instance and its path

func NewPrometheus

func NewPrometheus(subsystem string, customMetricsList ...[]*Metric) *Prometheus

NewPrometheus generates a new set of metrics with a certain subsystem name

func (*Prometheus) HandlerFunc

func (p *Prometheus) HandlerFunc() gin.HandlerFunc

HandlerFunc defines handler function for middleware

func (*Prometheus) SetListenAddress

func (p *Prometheus) SetListenAddress(address string)

SetListenAddress for exposing metrics on address. If not set, it will be exposed at the same address of the gin engine that is being used

func (*Prometheus) SetListenAddressWithRouter

func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)

SetListenAddressWithRouter for using a separate router to expose metrics. (this keeps things like GET /metrics out of your content's access log).

func (*Prometheus) SetMetricsPath

func (p *Prometheus) SetMetricsPath(e *gin.Engine)

SetMetricsPath set metrics paths

func (*Prometheus) SetMetricsPathWithAuth

func (p *Prometheus) SetMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts)

SetMetricsPathWithAuth set metrics paths with authentication

func (*Prometheus) SetPushGateway

func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushIntervalSeconds time.Duration)

SetPushGateway sends metrics to a remote pushgateway exposed on pushGatewayURL every pushIntervalSeconds. Metrics are fetched from metricsURL

func (*Prometheus) SetPushGatewayJob

func (p *Prometheus) SetPushGatewayJob(j string)

SetPushGatewayJob job name, defaults to "gin"

func (*Prometheus) Use

func (p *Prometheus) Use(e *gin.Engine)

Use adds the middleware to a gin engine.

func (*Prometheus) UseWithAuth

func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts)

UseWithAuth adds the middleware to a gin engine with BasicAuth.

type PrometheusPushGateway

type PrometheusPushGateway struct {

	// Push interval in seconds
	PushIntervalSeconds time.Duration

	// Push Gateway URL in format http://domain:port
	// where JOBNAME can be any string of your choice
	PushGatewayURL string

	// Local metrics URL where metrics are fetched from, this could be ommited in the future
	// if implemented using prometheus common/expfmt instead
	MetricsURL string

	// pushgateway job name, defaults to "gin"
	Job string
}

PrometheusPushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)

type RequestCounterURLLabelMappingFn

type RequestCounterURLLabelMappingFn func(c *gin.Context) string

RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:

func(c *gin.Context) string {
	url := c.Request.URL.Path
	for _, p := range c.Params {
		if p.Key == "name" {
			url = strings.Replace(url, p.Value, ":name", 1)
			break
		}
	}
	return url
}

which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".

type ServerPool

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

ServerPool saves all backends and current backend

func (*ServerPool) AddBackend

func (s *ServerPool) AddBackend(backend *Backend)

AddBackend adds a new node into the serverpool

func (*ServerPool) GetNextNode

func (s *ServerPool) GetNextNode() *Backend

GetNextNode returns next active node to connect

func (*ServerPool) HealthCheck

func (s *ServerPool) HealthCheck()

HealthCheck pings the remote node and update the status of the node

func (*ServerPool) NextIndex

func (s *ServerPool) NextIndex() int

NextIndex atomically increase the count and return an index

func (*ServerPool) SetBackendStatus

func (s *ServerPool) SetBackendStatus(backendURL *url.URL, alive bool)

SetBackendStatus changes the status of a certain backend

Jump to

Keyboard shortcuts

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