/
metrics.go
94 lines (80 loc) · 2.73 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 THL A29 Limited, a Tencent company.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License,
// A copy of the Apache 2.0 License is included in this file.
//
//
package prometheus
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"trpc.group/trpc-go/trpc-go"
)
var (
// opentelemetrySDKPanicTotal metric sdk panic
opentelemetrySDKPanicTotal = promauto.NewCounter(prometheus.CounterOpts{
Subsystem: "opentelemetry_sdk",
Name: "panic_total",
Help: "opentelemetry sdk panic total",
})
exportSpansBytes = promauto.NewHistogram(prometheus.HistogramOpts{
Subsystem: "opentelemetry_sdk",
Name: "export_spans_bytes",
Help: "Export Spans Bytes",
Buckets: []float64{128, 256, 1024, 10240, 102400, 1024_000, 10240_000, 102400_000, 1024_000_000},
})
exportLogsBytes = promauto.NewHistogram(prometheus.HistogramOpts{
Subsystem: "opentelemetry_sdk",
Name: "export_logs_bytes",
Help: "Export Logs Bytes",
Buckets: []float64{128, 256, 1024, 10240, 102400, 1024_000, 10240_000, 102400_000, 1024_000_000},
})
requestBodyBytes = promauto.NewHistogram(prometheus.HistogramOpts{
Subsystem: "rpc",
Name: "request_body_bytes",
Help: "Request Body Bytes",
Buckets: []float64{1024, 10240, 102400, 1024_000, 10240_000},
})
requestMetaDataBodyBytes = promauto.NewHistogram(prometheus.HistogramOpts{
Subsystem: "rpc",
Name: "request_metadata_bytes",
Help: "Request Metadata Bytes",
Buckets: []float64{1024, 10240, 102400, 1024_000, 10240_000},
})
trpcSDKMetadata = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "opentelemetry_trpc_metadata",
Help: "opentelemetry trpc metadata version",
}, []string{
"trpc_version",
})
)
// IncrSDKPanicTotal report sdk panic
func IncrSDKPanicTotal() {
opentelemetrySDKPanicTotal.Inc()
}
// ObserveExportSpansBytes observe span bytes
func ObserveExportSpansBytes(s int) {
exportSpansBytes.Observe(float64(s))
}
// ObserveExportLogsBytes observe log bytes
func ObserveExportLogsBytes(s int) {
exportLogsBytes.Observe(float64(s))
}
// ObserveRequestBodyBytes observe request body bytes
func ObserveRequestBodyBytes(s int) {
requestBodyBytes.Observe(float64(s))
}
// ObserveRequestMetaDataBytes observe request metadata bytes
func ObserveRequestMetaDataBytes(s int) {
requestMetaDataBodyBytes.Observe(float64(s))
}
// MonitorTRPCSDKMeta monitor trpc sdk meta
func MonitorTRPCSDKMeta() {
trpcSDKMetadata.WithLabelValues(trpc.Version()).Set(1)
}