MCPcopy Create free account
hub / github.com/astercloud/aster / NewMetricsManager

Function NewMetricsManager

server/observability/metrics.go:29–124  ·  view source on GitHub ↗

NewMetricsManager 创建指标管理器

(namespace string)

Source from the content-addressed store, hash-verified

27
28// NewMetricsManager 创建指标管理器
29func NewMetricsManager(namespace string) *MetricsManager {
30 if namespace == "" {
31 namespace = "aster"
32 }
33
34 m := &MetricsManager{
35 registry: prometheus.NewRegistry(),
36 }
37
38 // HTTP 请求总数
39 m.requestsTotal = prometheus.NewCounterVec(
40 prometheus.CounterOpts{
41 Namespace: namespace,
42 Name: "http_requests_total",
43 Help: "Total number of HTTP requests",
44 },
45 []string{"method", "path", "status"},
46 )
47
48 // HTTP 请求延迟
49 m.requestDuration = prometheus.NewHistogramVec(
50 prometheus.HistogramOpts{
51 Namespace: namespace,
52 Name: "http_request_duration_seconds",
53 Help: "HTTP request duration in seconds",
54 Buckets: prometheus.DefBuckets,
55 },
56 []string{"method", "path"},
57 )
58
59 // 请求大小
60 m.requestSize = prometheus.NewHistogramVec(
61 prometheus.HistogramOpts{
62 Namespace: namespace,
63 Name: "http_request_size_bytes",
64 Help: "HTTP request size in bytes",
65 Buckets: prometheus.ExponentialBuckets(100, 10, 8),
66 },
67 []string{"method", "path"},
68 )
69
70 // 响应大小
71 m.responseSize = prometheus.NewHistogramVec(
72 prometheus.HistogramOpts{
73 Namespace: namespace,
74 Name: "http_response_size_bytes",
75 Help: "HTTP response size in bytes",
76 Buckets: prometheus.ExponentialBuckets(100, 10, 8),
77 },
78 []string{"method", "path"},
79 )
80
81 // Agents 总数
82 m.agentsTotal = prometheus.NewGauge(
83 prometheus.GaugeOpts{
84 Namespace: namespace,
85 Name: "agents_total",
86 Help: "Total number of agents",

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected