chpoolprometheus

package module
v0.0.0-...-0fd7e46 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package chpoolprometheus defines the prometheus Collector for chpool.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector is implements prometheus.Collector interface that collect metrics produced by chpool.

Example
package main

import (
	"context"
	"log"
	"net/http"

	"github.com/ClickHouse/ch-go/chpool"
	"github.com/dengaleev/chpoolprometheus"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
	ctx := context.Background()

	pool, err := chpool.Dial(ctx, chpool.Options{})
	if err != nil {
		log.Fatalf("can't init Clickhouse pool: %v", err)
	}
	defer pool.Close()

	if err := pool.Ping(ctx); err != nil {
		log.Fatalf("can't ping: %v", err)
	}

	reg := prometheus.NewRegistry()
	cllctr := chpoolprometheus.NewCollector(pool, map[string]string{})
	reg.MustRegister(cllctr)

	http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
	err = http.ListenAndServe(":4815", nil)
	if err != nil {
		log.Fatalf("can't start server: %v", err)
	}
}
Output:

func NewCollector

func NewCollector(pool *chpool.Pool, labels prometheus.Labels) *Collector

NewCollector creates a new Collector for the pool.

func (*Collector) Collect

func (c *Collector) Collect(metrics chan<- prometheus.Metric)

Collect implements the prometheus.Collector.Collect method.

func (*Collector) Describe

func (c *Collector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector.Describe method.

type Stat

type Stat interface {
	AcquireCount() int64
	AcquireDuration() time.Duration
	AcquiredResources() int32
	CanceledAcquireCount() int64
	ConstructingResources() int32
	EmptyAcquireCount() int64
	IdleResources() int32
	MaxResources() int32
	TotalResources() int32
}

Stat defines the chpool.Stat interface.

Jump to

Keyboard shortcuts

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