Documentation ¶
Index ¶
- func PrometheusMiddleware(ps *PrometheusService) gin.HandlerFunc
- func StreamServerPrometheusInterceptor(prometheus *PrometheusService) grpc.StreamServerInterceptor
- func UnaryServerPrometheusInterceptor(prometheus *PrometheusService) grpc.UnaryServerInterceptor
- type Batch
- type Labels
- type Metric
- type MetricType
- type PrometheusService
- func (ps *PrometheusService) AddMetric(metric Metric) error
- func (ps *PrometheusService) Collect(ctx context.Context) error
- func (ps *PrometheusService) Counter(metric string, labels Labels) error
- func (ps *PrometheusService) Duration(since time.Time, metric string, labels Labels) error
- func (ps *PrometheusService) DurationWithBuckets(since time.Time, metric string, labels Labels, buckets []float64) error
- func (ps *PrometheusService) ForceAddMetric(metric Metric) error
- func (ps *PrometheusService) ForceCounter(metric string, labels Labels) error
- func (ps *PrometheusService) ForceDuration(since time.Time, metric string, labels Labels) error
- func (ps *PrometheusService) ForceDurationWithBuckets(since time.Time, metric string, labels Labels, buckets []float64) error
- func (ps *PrometheusService) ForceSystemMetrics() error
- func (ps *PrometheusService) Init(ctx context.Context) error
- func (ps *PrometheusService) Shutdown() error
- func (ps *PrometheusService) SystemMetrics() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrometheusMiddleware ¶ added in v0.2.5
func PrometheusMiddleware(ps *PrometheusService) gin.HandlerFunc
Возвращает обработчик, собирающий метрики с каждого запроса. Типы метрик:
- http_request_duration - gauge - длительность выполнения запроса
- http_request_total - counter - кол-во запросов
func StreamServerPrometheusInterceptor ¶
func StreamServerPrometheusInterceptor(prometheus *PrometheusService) grpc.StreamServerInterceptor
Возвращает нового потокового перехватчика, который добавляет метрики о длительности выполнения процедуры.
func UnaryServerPrometheusInterceptor ¶
func UnaryServerPrometheusInterceptor(prometheus *PrometheusService) grpc.UnaryServerInterceptor
Возвращает нового унарного перехватчика, который добавляет метрики о длительности выполнения процедуры.
Types ¶
type Batch ¶ added in v0.2.0
type Batch struct { MaxSize int // максимальный размер пачки LastSendAt time.Time // дата и время последней отправки батча // contains filtered or unexported fields }
Батч с метриками.
func (*Batch) MarshalJSON ¶ added in v0.2.0
Сериализует список метрик в JSON.
type Metric ¶ added in v0.2.0
type Metric struct { Name string `json:"n"` // название метрики Value float64 `json:"v"` // значение Labels Labels `json:"l"` // лейблы Type MetricType `json:"t"` // тип метрики }
Общая структура статистической метрики. https://github.com/mailru/easyjson#run
func (Metric) MarshalEasyJSON ¶ added in v0.2.11
MarshalEasyJSON supports easyjson.Marshaler interface
type MetricType ¶ added in v0.2.0
type MetricType string
const ( CounterMetricType MetricType = "counter" GaugeMetricType MetricType = "gauge" )
type PrometheusService ¶
type PrometheusService struct { // Коллектор, запущенный в DRY режиме эмулирует сбор метрики, // но никуда их не отправляет. // Может быть использовано для dev режима, где нет необходимости в метриках. DRY bool DefaultLabels Labels // дефолтные лейблы, присваиваемые всем метрикам Prefix string // префикс, добавляемый к названию всех метрик Exchange string // обменник, через который пойдет сообщение Queue string // очередь с метриками MessageTTL int // время жизни сообщения в очереди Period time.Duration // период отправки сообщений в RabbitMQ BatchSize int // размер пакета с метриками BatchTTL time.Duration // время жизни одного батча // contains filtered or unexported fields }
Сервис для общения с Prometheus через RabbitMQ.
func NewPrometheusService ¶
func NewPrometheusService(ctx context.Context, connection *r.Connection) (*PrometheusService, error)
Инициализирует новый сервис для отправки метрик в Prometheus.
func (*PrometheusService) AddMetric ¶
func (ps *PrometheusService) AddMetric(metric Metric) error
Добавляет метрику в батч, который будет отправлен в очередь. Ничего не делает если коллектор запущен в DRY режиме.
func (*PrometheusService) Collect ¶
func (ps *PrometheusService) Collect(ctx context.Context) error
Запускает цикл по обработке метрик. Ничего не делает если коллектор запущен в DRY режиме.
func (*PrometheusService) Counter ¶
func (ps *PrometheusService) Counter(metric string, labels Labels) error
Добавляет counter-метрику в батч, который будет отправлен в Prometheus. Один вызов равняется +1 к метрике.
func (*PrometheusService) Duration ¶
Добавляет gauge-метрику в батч, который будет отправлен в Prometheus. Рассчитывает метрику длительности выполнения кода. Значение метрики вычисляется в микросекундах.
func (*PrometheusService) DurationWithBuckets ¶ added in v0.2.13
func (ps *PrometheusService) DurationWithBuckets(since time.Time, metric string, labels Labels, buckets []float64) error
Добавляет gauge-метрику в батч, который будет отправлен в Prometheus. Рассчитывает метрику длительности выполнения кода. Значение метрики вычисляется в микросекундах.
func (*PrometheusService) ForceAddMetric ¶
func (ps *PrometheusService) ForceAddMetric(metric Metric) error
Добавляет метрику напрямую в RabbitMQ, минуя механизм с батчами. Ничего не делает если коллектор запущен в DRY режиме.
func (*PrometheusService) ForceCounter ¶ added in v0.1.14
func (ps *PrometheusService) ForceCounter(metric string, labels Labels) error
Добавляет counter-метрику в Prometheus. Один вызов равняется +1 к метрике.
func (*PrometheusService) ForceDuration ¶ added in v0.1.14
Добавляет gauge-метрику в Prometheus. Рассчитывает метрику длительности выполнения кода. Значение метрики вычисляется в микросекундах.
func (*PrometheusService) ForceDurationWithBuckets ¶ added in v0.2.13
func (ps *PrometheusService) ForceDurationWithBuckets(since time.Time, metric string, labels Labels, buckets []float64) error
Добавляет gauge-метрику в батч, который будет отправлен в Prometheus. Рассчитывает метрику длительности выполнения кода. Значение метрики вычисляется в микросекундах.
func (*PrometheusService) ForceSystemMetrics ¶ added in v0.1.14
func (ps *PrometheusService) ForceSystemMetrics() error
Добавляет системные метрики в Prometheus. В системные метрики входят:
- CPU, %
- Memory usage, MB
- Number of running goroutines
func (*PrometheusService) Init ¶
func (ps *PrometheusService) Init(ctx context.Context) error
Инициализирует очередь, связанную с метриками для Prometheus.
func (*PrometheusService) Shutdown ¶
func (ps *PrometheusService) Shutdown() error
Завершает процесс по отправке метрик в RabbitMQ.
func (*PrometheusService) SystemMetrics ¶
func (ps *PrometheusService) SystemMetrics() error
Добавляет системные метрики батч, который будет отправлен в Prometheus. В системные метрики входят:
- CPU, %
- Memory usage, MB
- Number of running goroutines