obsmetrics

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package obsmetrics는 client_golang 의존성 없이 Prometheus 평문 텍스트 exposition을 직접 생성하는 메트릭 키트입니다.

패키지 개요

이 패키지는 iris webhook 핸들러 관측 포인트(iris-client-go webhook.Metrics)를 prefix 네임스페이스 단위로 구현한 WebhookMetrics를 제공합니다. prefix가 "chat_bot"이면 chat_bot_webhook_* 계열을, "twentyq"면 twentyq_webhook_* 계열을 노출하므로, iris webhook을 소비하는 여러 서비스가 동일 구현을 공유하면서도 각자의 메트릭 이름을 보존할 수 있습니다.

도메인 메트릭은 서비스마다 다르므로 이 패키지가 직접 정의하지 않고, 같은 평문 포맷으로 노출할 수 있도록 Histogram 타입, 라벨 벡터(CounterVec/GaugeVec/HistogramVec), exposition 헬퍼(WriteCounter/WriteGauge/WriteHistogram), 그리고 런타임 메트릭 writer (WriteRuntimeMetrics)를 제공합니다. 각 서비스는 자신의 /metrics 핸들러에서 WebhookMetrics.Expose, 도메인 메트릭 직렬화, WriteRuntimeMetrics를 순서대로 조립합니다.

WebhookMetrics는 iris-client-go를 import하지 않습니다. Go의 구조적 타이핑으로 메서드 시그니처만 일치시키므로, 호출측에서 iris.WithMetrics에 그대로 주입할 수 있고 이 패키지에는 불필요한 의존성이 생기지 않습니다.

Index

Constants

This section is empty.

Variables

View Source
var WebhookLatencyBuckets = []float64{
	0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 120,
}

WebhookLatencyBuckets는 ms~분 범위를 덮는 초 단위 히스토그램 경계입니다.

Functions

func SanitizeHelp

func SanitizeHelp(help string) string

SanitizeHelp는 HELP 텍스트의 개행을 제거해 exposition 포맷이 깨지지 않게 합니다.

func WriteCounter

func WriteCounter(w io.Writer, name, help string, value uint64) bool

WriteCounter는 단일 counter 메트릭을 Prometheus 텍스트 포맷으로 씁니다.

func WriteCounterWithLabels

func WriteCounterWithLabels(w io.Writer, name, help string, labels Labels, value uint64) bool

WriteCounterWithLabels는 라벨이 있는 counter 메트릭을 Prometheus 텍스트 포맷으로 씁니다.

func WriteGauge

func WriteGauge(w io.Writer, name, help, value string) bool

WriteGauge는 단일 gauge 메트릭을 씁니다. value는 호출측이 직렬화한 문자열입니다(정수/실수 모두 수용).

func WriteGaugeWithLabels

func WriteGaugeWithLabels(w io.Writer, name, help string, labels Labels, value string) bool

WriteGaugeWithLabels는 라벨이 있는 gauge 메트릭을 씁니다. value는 호출측이 직렬화한 문자열입니다.

func WriteHistogram

func WriteHistogram(w io.Writer, name, help string, snap HistogramSnapshot) bool

WriteHistogram은 HistogramSnapshot을 Prometheus 텍스트 포맷(bucket/sum/count)으로 씁니다.

func WriteHistogramWithLabels

func WriteHistogramWithLabels(w io.Writer, name, help string, labels Labels, snap HistogramSnapshot) bool

WriteHistogramWithLabels는 라벨이 있는 HistogramSnapshot을 Prometheus 텍스트 포맷(bucket/sum/count)으로 씁니다.

func WriteRuntimeMetrics

func WriteRuntimeMetrics(w io.Writer) bool

WriteRuntimeMetrics는 Go 런타임/프로세스 메트릭(go_*, process_*)을 텍스트 포맷으로 씁니다.

Types

type Counter

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

Counter는 원자적으로 증가하는 단일 counter series입니다.

func (*Counter) Add

func (c *Counter) Add(delta uint64)

func (*Counter) Inc

func (c *Counter) Inc()

func (*Counter) Value

func (c *Counter) Value() uint64

type CounterVec

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

CounterVec는 동일 metric name/help를 공유하는 label-set별 counter 집합입니다.

func NewCounterVec

func NewCounterVec(name, help string) *CounterVec

func (*CounterVec) Add

func (v *CounterVec) Add(labels Labels, delta uint64)

func (*CounterVec) Inc

func (v *CounterVec) Inc(labels Labels)

func (*CounterVec) With

func (v *CounterVec) With(labels Labels) *Counter

func (*CounterVec) WriteExposition

func (v *CounterVec) WriteExposition(w io.Writer) bool

type Gauge

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

Gauge는 원자적으로 설정되는 단일 gauge series입니다.

func (*Gauge) Set

func (g *Gauge) Set(value float64)

func (*Gauge) Value

func (g *Gauge) Value() float64

type GaugeVec

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

GaugeVec는 동일 metric name/help를 공유하는 label-set별 float64 gauge 집합입니다.

func NewGaugeVec

func NewGaugeVec(name, help string) *GaugeVec

func (*GaugeVec) Set

func (v *GaugeVec) Set(labels Labels, value float64)

func (*GaugeVec) With

func (v *GaugeVec) With(labels Labels) *Gauge

func (*GaugeVec) WriteExposition

func (v *GaugeVec) WriteExposition(w io.Writer) bool

type Histogram

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

Histogram은 고정 버킷 경계를 가진 thread-safe 비누적 히스토그램입니다. Observe는 관측값이 속한 landing bucket 하나만 증가시키며, 누적 bucket은 Snapshot에서 계산합니다.

func NewHistogram

func NewHistogram(buckets []float64) *Histogram

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

func (*Histogram) Snapshot

func (h *Histogram) Snapshot() HistogramSnapshot

type HistogramSnapshot

type HistogramSnapshot struct {
	UpperBounds []float64
	Cumulative  []uint64
	Sum         float64
	Total       uint64
}

type HistogramVec

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

HistogramVec는 동일 metric name/help/bucket을 공유하는 label-set별 histogram 집합입니다.

func NewHistogramVec

func NewHistogramVec(name, help string, buckets []float64) *HistogramVec

func (*HistogramVec) Observe

func (v *HistogramVec) Observe(labels Labels, value float64)

func (*HistogramVec) With

func (v *HistogramVec) With(labels Labels) *Histogram

func (*HistogramVec) WriteExposition

func (v *HistogramVec) WriteExposition(w io.Writer) bool

type Labels

type Labels map[string]string

Labels는 Prometheus label name/value 집합입니다. 렌더링 시 label name 기준으로 정렬됩니다.

type WebhookDiagnostics

type WebhookDiagnostics struct {
	WorkersConfigured int
	QueueSize         int
	Pending           int
	InFlight          int
	EnqueueRejected   uint64
	QueueFullCount    uint64
	HandlerTimeouts   uint64
}

WebhookDiagnostics는 webhook 워커/큐 진단 스냅샷을 메트릭으로 노출하기 위한 운영 값입니다.

type WebhookMetrics

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

WebhookMetrics는 iris-client-go webhook.Metrics 관측 포인트를 prefix 네임스페이스 단위로 구현한 공통 구현체입니다. 메서드 집합이 webhook.Metrics와 구조적으로 일치하므로 iris-client-go를 import하지 않고도 iris.WithMetrics에 주입할 수 있습니다.

func NewWebhookMetrics

func NewWebhookMetrics(prefix string) *WebhookMetrics

NewWebhookMetrics는 prefix 네임스페이스(예: "chat_bot", "twentyq")로 webhook 메트릭을 만듭니다.

func (*WebhookMetrics) Expose

func (m *WebhookMetrics) Expose(w io.Writer) bool

Expose는 <prefix>_webhook_* 메트릭을 Prometheus 텍스트 포맷으로 직렬화합니다.

func (*WebhookMetrics) ObserveAccepted

func (m *WebhookMetrics) ObserveAccepted()

func (*WebhookMetrics) ObserveBadRequest

func (m *WebhookMetrics) ObserveBadRequest()

func (*WebhookMetrics) ObserveDecodeLatency

func (m *WebhookMetrics) ObserveDecodeLatency(d time.Duration)

func (*WebhookMetrics) ObserveDedupLatency

func (m *WebhookMetrics) ObserveDedupLatency(d time.Duration)

func (*WebhookMetrics) ObserveDuplicate

func (m *WebhookMetrics) ObserveDuplicate()

func (*WebhookMetrics) ObserveEnqueueFailure

func (m *WebhookMetrics) ObserveEnqueueFailure()

func (*WebhookMetrics) ObserveEnqueueWait

func (m *WebhookMetrics) ObserveEnqueueWait(d time.Duration)

func (*WebhookMetrics) ObserveHandlerDuration

func (m *WebhookMetrics) ObserveHandlerDuration(d time.Duration)

func (*WebhookMetrics) ObserveQueueDepth

func (m *WebhookMetrics) ObserveQueueDepth(depth int)

func (*WebhookMetrics) ObserveRequest

func (m *WebhookMetrics) ObserveRequest()

func (*WebhookMetrics) ObserveUnauthorized

func (m *WebhookMetrics) ObserveUnauthorized()

func (*WebhookMetrics) SetDiagnosticsSource

func (m *WebhookMetrics) SetDiagnosticsSource(source func() WebhookDiagnostics)

SetDiagnosticsSource는 워커/큐 진단 스냅샷을 노출 시점에 읽어올 콜백을 등록합니다. nil이면 진단 게이지를 생략합니다.

Jump to

Keyboard shortcuts

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