metrics

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OpenConnections                = "_open_connections"
	IdleConnections                = "_idle_connections_open"
	ConnectionsInUse               = "_connections_in_use"
	DatabaseConnectionWaitDuration = "_database_connection_wait_duration"
	DatabaseOperationLatency       = "_database_operation_latency"
)
View Source
const (
	NumberOfGoRoutines = "_number_of_go_routines"
)
View Source
const (
	RequestInfo = "_request_info"
)
View Source
const SUBSYSTEM string = "database"

Variables

View Source
var Enum = &CounterType{
	GaugeFunc:    "GAUGE_FUNC",
	CounterVec:   "COUNTER_VEC",
	GaugeVec:     "GAUGE_VEC",
	SummaryVec:   "SUMMARY_VEC",
	HistogramVec: "HISTOGRAM_VEC",
}
View Source
var REQUEST_SUBSYSTEM = "Request"
View Source
var RUNTIME_SUBSYSTEM = "Runtime"

Functions

func EnableRunTimeMetrics

func EnableRunTimeMetrics()

EnableRunTimeMetrics enable runtime metrics

func GenerateRandomString

func GenerateRandomString(n int) string

func GetSystemPrometheusRegistry

func GetSystemPrometheusRegistry() *prometheus.Registry

GetSystemPrometheusRegistry return prometheus registry which go chassis use

func Initialize

func Initialize(connSettings string) *gorm.DB

Initialize creates a singular connection to the backend database instance

func RegisterCommonDatabaseCounters

func RegisterCommonDatabaseCounters(serviceName string, db *gorm.DB, metricsExporter *MetricsExporter)

RegisterCommonDatabaseCounters generate common database specific counters of interest for a given service

func RegisterCommonRequestCounters

func RegisterCommonRequestCounters(serviceName string, metricsExporter *MetricsExporter)

RegisterCommonRuntimeCounters generate common runtime specific counters of interest for a given service

func RegisterCommonRuntimeCounters

func RegisterCommonRuntimeCounters(serviceName string, metricsExporter *MetricsExporter)

RegisterCommonRuntimeCounters generate common runtime specific counters of interest for a given service

func RegisterInfraMetrics

func RegisterInfraMetrics(options Options, metricsExporter *MetricsExporter)

func Setup

func Setup() *gorm.DB

Setup sets up database connection prior to testing

func SetupTests

func SetupTests() *gorm.DB

init initializes a connection to the database initially and performs package level cleanup handler initialization

Types

type CounterAlias

type CounterAlias string

type CounterMetadata

type CounterMetadata struct {
	CounterType       CounterAlias
	CounterName       string
	CounterNameSpace  func(string) string
	CounterSubSystem  string
	CounterHelpString string
	CounterLabels     []string
	CounterFunction   func(db *gorm.DB) func() float64
	CounterBuckets    []float64
}

type CounterOpts

type CounterOpts struct {
	Name      string
	Namespace string
	Subsystem string
	Help      string
	Labels    []string
}

CounterOpts is options to create a counter options

type CounterType

type CounterType struct {
	GaugeFunc    CounterAlias
	CounterVec   CounterAlias
	GaugeVec     CounterAlias
	SummaryVec   CounterAlias
	HistogramVec CounterAlias
}

type GaugeOpts

type GaugeOpts struct {
	Name      string
	Namespace string
	Subsystem string
	Help      string
	Labels    []string
}

GaugeOpts is options to create a gauge collector

type HistogramOpts

type HistogramOpts struct {
	Name      string
	Namespace string
	Subsystem string
	Help      string
	Labels    []string
	Buckets   []float64
}

HistogramOpts is options to create histogram collector

type MetricsExporter

type MetricsExporter struct {
	FlushInterval time.Duration

	ServiceName string
	// contains filtered or unexported fields
}

MetricsExporter is a prom exporter for go

func (*MetricsExporter) CounterAdd

func (c *MetricsExporter) CounterAdd(name string, val float64, labels map[string]string) error

CounterAdd adds a new counter and sets its initial start value

func (*MetricsExporter) CreateCounter

func (c *MetricsExporter) CreateCounter(opts CounterOpts) error

CreateCounter creates a metric of type counter

func (*MetricsExporter) CreateGauge

func (c *MetricsExporter) CreateGauge(opts GaugeOpts) error

CreateGauge creates a metric of type gauge

func (*MetricsExporter) CreateGaugeFunc

func (c *MetricsExporter) CreateGaugeFunc(opts GaugeOpts, f func() float64) error

func (*MetricsExporter) CreateHistogram

func (c *MetricsExporter) CreateHistogram(opts HistogramOpts) error

CreateHistogram creates a metric of type histogram

func (*MetricsExporter) CreateSummary

func (c *MetricsExporter) CreateSummary(opts SummaryOpts) error

CreateSummary creates a metric of type summary

func (*MetricsExporter) GaugeSet

func (c *MetricsExporter) GaugeSet(name string, val float64, labels map[string]string) error

GaugeSet adds a new counter (gauge) and sets initial value

func (*MetricsExporter) HistogramObserve

func (c *MetricsExporter) HistogramObserve(name string, val float64, labels map[string]string) error

HistogramObserve creates a histogram counter and initializes it to some start value

func (*MetricsExporter) Monitor

func (c *MetricsExporter) Monitor(next http.Handler) http.Handler

func (*MetricsExporter) ObtainGaugeFunc

func (c *MetricsExporter) ObtainGaugeFunc(name string) (*prometheus.GaugeFunc, error)

func (*MetricsExporter) SummaryObserve

func (c *MetricsExporter) SummaryObserve(name string, val float64, labels map[string]string) error

SummaryObserve creates a summary counter and initializes it to a start value

type NewRegistry

type NewRegistry func(opts Options) Registry

NewRegistry create a registry

type Options

type Options struct {
	FlushInterval          time.Duration
	EnableGoRuntimeMetrics bool
	DbConn                 *gorm.DB
	ServiceName            string
}

Options control config

type Registry

type Registry interface {
	// CreateGauge creates a gauge metric type
	CreateGauge(opts GaugeOpts) error
	// CreateCounter creates a counter metric type
	CreateCounter(opts CounterOpts) error
	// CreateSummary creates a summary metric type
	CreateSummary(opts SummaryOpts) error
	// CreateHistogram creates a histogram metric type
	CreateHistogram(opts HistogramOpts) error
	// CreateGaugeFunc create a gauge function metric type
	CreateGaugeFunc(opts GaugeOpts, f func() float64) error

	// GaugeSet sets a gauge counter type to a value specified by val
	GaugeSet(name string, val float64, labels map[string]string) error
	// CounterAdd sets a gauge counter to a value specified by val
	CounterAdd(name string, val float64, labels map[string]string) error
	// SummaryObserve specifies a counter of summary type
	SummaryObserve(name string, val float64, Labels map[string]string) error
	// HistogramObserve set/increments a histogram counter type
	HistogramObserve(name string, val float64, labels map[string]string) error
	// ObtainGaugeFunc attempts to obtain a gauge function by name
	ObtainGaugeFunc(name string) (*prometheus.GaugeFunc, error)
	// Monitor observes the request size and latency associated with a specific route and records it in a summary vector metric
	Monitor(next http.Handler) http.Handler
}

Registry holds all of metrics collectors name is a unique ID for different type of metrics

func NewMetricsExporter

func NewMetricsExporter(options Options) Registry

NewMetricsExporter create a prometheus exporter

type SummaryOpts

type SummaryOpts struct {
	Name       string
	Namespace  string
	Subsystem  string
	Help       string
	Labels     []string
	Objectives map[float64]float64
}

SummaryOpts is options to create summary collector

Jump to

Keyboard shortcuts

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