cloudflare/pint

Public

mirrored from https://github.com/cloudflare/pintAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v0.28.5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

internal/promapi/metrics.go

78lines · modecode

1package promapi
2
3import (
4 "errors"
5 "fmt"
6 "net"
7
8 v1 "github.com/prometheus/client_golang/api/prometheus/v1"
9 "github.com/prometheus/client_golang/prometheus"
10)
11
12var (
13 prometheusQueriesRunning = prometheus.NewGaugeVec(
14 prometheus.GaugeOpts{
15 Name: "pint_prometheus_queries_running",
16 Help: "Total number of in-flight prometheus queries",
17 },
18 []string{"name", "endpoint"},
19 )
20 prometheusCacheSize = prometheus.NewGaugeVec(
21 prometheus.GaugeOpts{
22 Name: "pint_prometheus_cache_size",
23 Help: "Total number of entries currently stored in Prometheus query cache",
24 },
25 []string{"name"},
26 )
27 prometheusCacheHitsTotal = prometheus.NewCounterVec(
28 prometheus.CounterOpts{
29 Name: "pint_prometheus_cache_hits_total",
30 Help: "Total number of all prometheus queries served from a cache",
31 },
32 []string{"name", "endpoint"},
33 )
34 prometheusCacheMissTotal = prometheus.NewCounterVec(
35 prometheus.CounterOpts{
36 Name: "pint_prometheus_cache_miss_total",
37 Help: "Total number of all prometheus queries resulting in a cache miss",
38 },
39 []string{"name", "endpoint"},
40 )
41 prometheusQueriesTotal = prometheus.NewCounterVec(
42 prometheus.CounterOpts{
43 Name: "pint_prometheus_queries_total",
44 Help: "Total number of all prometheus queries",
45 },
46 []string{"name", "endpoint"},
47 )
48 prometheusQueryErrorsTotal = prometheus.NewCounterVec(
49 prometheus.CounterOpts{
50 Name: "pint_prometheus_query_errors_total",
51 Help: "Total number of failed prometheus queries",
52 },
53 []string{"name", "endpoint", "reason"},
54 )
55)
56
57func RegisterMetrics() {
58 prometheus.MustRegister(prometheusQueriesRunning)
59 prometheus.MustRegister(prometheusCacheSize)
60 prometheus.MustRegister(prometheusCacheHitsTotal)
61 prometheus.MustRegister(prometheusCacheMissTotal)
62 prometheus.MustRegister(prometheusQueriesTotal)
63 prometheus.MustRegister(prometheusQueryErrorsTotal)
64}
65
66func errReason(err error) string {
67 var neterr net.Error
68 if ok := errors.As(err, &neterr); ok && neterr.Timeout() {
69 return "connection/timeout"
70 }
71
72 var v1err *v1.Error
73 if ok := errors.As(err, &v1err); ok {
74 return fmt.Sprintf("api/%s", v1err.Type)
75 }
76
77 return "connection/error"
78}
79