Debian Codegraph @

prometheus.go

raw symbols SCIP
1 package mainscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/
2
3 import (
4 "log/slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/"
5 "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/"
6 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
7 "syncscip-go gomod github.com/golang/go/src go1.25.0 sync/"
8 "timescip-go gomod github.com/golang/go/src go1.25.0 time/"
9
10 "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/"
11 )
12
13 const (
14 exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace. = "varnish"
15 )
16
17 // prometheusExporter
18
19 type prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter# struct {
20 syncscip-go gomod github.com/golang/go/src go1.25.0 sync/.RWMutexscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#RWMutex.
21
22 upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up. prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Gaugescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Gauge#
23 versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version. prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Gaugescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Gauge#
24 }
25
26 func NewPrometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/NewPrometheusExporter().() *prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter# {
27 return &prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#{
28 upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up.: prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewGaugescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewGauge().(prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeOptsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeOpts#{
29 Namespacescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Namespace.: exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace.,
30 Namescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Name.: "up",
31 Helpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Help.: "Was the last scrape of varnish successful.",
32 }),
33 }
34 }
35
36 func (pe *prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#) Initializescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#Initialize().() error {
37 pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewGaugescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewGauge().(prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeOptsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeOpts#{
38 Namespacescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Namespace.: exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace.,
39 Namescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Name.: "version",
40 Helpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Help.: "Varnish version information",
41 ConstLabelsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#ConstLabels.: VarnishVersionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/VarnishVersion..Labelsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/varnishVersion#Labels().(),
42 })
43 pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version..Setscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Gauge#Set().(1)
44 return nil
45 }
46
47 // Implements prometheus.Collector
48 func (pe *prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#) Describescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#Describe().(ch chan<- *prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Desc#) {
49 start := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().()
50
51 ch <- pe.upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up..Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().()
52 if pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version. != nil {
53 ch <- pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version..Descscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#Desc().()
54 }
55
56 slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Debug().("prometheus.Collector.Describe", "duration", timescip-go gomod github.com/golang/go/src go1.25.0 time/.Sincescip-go gomod github.com/golang/go/src go1.25.0 time/Since().(start))
57 }
58
59 // Implements prometheus.Collector
60 func (pe *prometheusExporterscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#) Collectscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#Collect().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#) {
61 start := timescip-go gomod github.com/golang/go/src go1.25.0 time/.Nowscip-go gomod github.com/golang/go/src go1.25.0 time/Now().()
62
63 pe.Lockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Lock().()
64 defer pe.Unlockscip-go gomod github.com/golang/go/src go1.25.0 sync/RWMutex#Unlock().()
65
66 // Rare case of varnish not being installed in the system
67 // when we started, but installed while we are running.
68 if !VarnishVersionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/VarnishVersion..Validscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/varnishVersion#Valid().() {
69 if VarnishVersionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/VarnishVersion..Initializescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/varnishVersion#Initialize().() == nil {
70 pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version. = prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.NewGaugescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/NewGauge().(prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.GaugeOptsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/GaugeOpts#{
71 Namespacescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Namespace.: exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace.,
72 Namescip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Name.: "version",
73 Helpscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#Help.: "Varnish version information",
74 ConstLabelsscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/CounterOpts#ConstLabels.: VarnishVersionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/VarnishVersion..Labelsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/varnishVersion#Labels().(),
75 })
76 }
77 }
78
79 hadError := ExitHandlerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/ExitHandler..HasErrorscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exitHandler#HasError().()
80
81 _, err := ScrapeVarnishscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/ScrapeVarnish().(ch)
82 ExitHandlerscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/ExitHandler..Setscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exitHandler#Set().(err)
83
84 if err == nil {
85 if hadError {
86 slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Infoscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Info().("Successful scrape")
87 }
88 pe.upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up..Setscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Gauge#Set().(1)
89 } else {
90 pe.upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up..Setscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Gauge#Set().(0)
91 }
92
93 ch <- pe.upscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#up.
94 if pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version. != nil {
95 ch <- pe.versionscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusExporter#version.
96 }
97
98 if err != nil {
99 slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Errorscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Error().("prometheus.Collector.Collect scrape failed", "error", err)
100 }
101 slogscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/.Debugscip-go gomod github.com/golang/go/src go1.25.0 `log/slog`/Debug().("prometheus.Collector.Collect", "duration", timescip-go gomod github.com/golang/go/src go1.25.0 time/.Sincescip-go gomod github.com/golang/go/src go1.25.0 time/Since().(start))
102 }
103
104 // utils
105
106 type groupscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group# struct {
107 namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name. string
108 prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes. []string
109 }
110
111 var (
112 groupsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/groups. = []groupscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#{
113 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "backend", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
114 "vbe.",
115 }},
116 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "mempool", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
117 "mempool.",
118 }},
119 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "lck", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
120 "lck.",
121 }},
122 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "sma", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
123 "sma.",
124 }},
125 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "smf", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
126 "smf.",
127 }},
128 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "mgt", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
129 "mgt.",
130 }},
131 {namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.: "main", prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes.: []string{
132 "main.",
133 }},
134 }
135 )
136
137 type groupingscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping# struct {
138 newPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#newPrefix. string
139 prefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#prefix. string
140 totalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#total. string
141 descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc. string
142 labelKeyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#labelKey. string
143 }
144
145 var (
146 fqGroupPrefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqGroupPrefixes. = []*groupingscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#{
147 {
148 prefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#prefix.: "main_fetch",
149 totalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#total.: "main_s_fetch",
150 descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc.: "Number of fetches",
151 },
152 {
153 newPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#newPrefix.: "main_sessions",
154 prefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#prefix.: "main_sess",
155 totalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#total.: "main_s_sess",
156 descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc.: "Number of sessions",
157 },
158 {
159 newPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#newPrefix.: "main_worker_threads",
160 prefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#prefix.: "main_n_wrk",
161 totalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#total.: "main_n_wrk",
162 descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc.: "Number of worker threads",
163 },
164 }
165 fqNamesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqNames. = map[string]string{
166 "varnish_lck_colls": "varnish_lock_collisions",
167 "varnish_lck_creat": "varnish_lock_created",
168 "varnish_lck_destroy": "varnish_lock_destroyed",
169 "varnish_lck_locks": "varnish_lock_operations",
170 }
171 fqIdentifiersscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqIdentifiers. = map[string]string{
172 "varnish_lock_collisions": "target",
173 "varnish_lock_created": "target",
174 "varnish_lock_destroyed": "target",
175 "varnish_lock_operations": "target",
176 "varnish_sma_c_bytes": "type",
177 "varnish_sma_c_fail": "type",
178 "varnish_sma_c_freed": "type",
179 "varnish_sma_c_req": "type",
180 "varnish_sma_g_alloc": "type",
181 "varnish_sma_g_bytes": "type",
182 "varnish_sma_g_space": "type",
183 "varnish_smf_c_bytes": "type",
184 "varnish_smf_c_fail": "type",
185 "varnish_smf_c_freed": "type",
186 "varnish_smf_c_req": "type",
187 "varnish_smf_g_alloc": "type",
188 "varnish_smf_g_bytes": "type",
189 "varnish_smf_g_smf_frag": "type",
190 "varnish_smf_g_smf_large": "type",
191 "varnish_smf_g_smf": "type",
192 "varnish_smf_g_space": "type",
193 }
194 )
195
196 var (
197 // (prefix:)<uuid>.<name>
198 regexBackendUUIDscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/regexBackendUUID. = regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`([[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[89ABab][0-9A-Za-z]{3}-[0-9A-Za-z]{12})(.*)`)
199 // <name>(<ip>,(<something>),<port>)
200 regexBackendParenscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/regexBackendParen. = regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`(.*)\((.*)\)`)
201 )
202
203 func findLabelValuescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/findLabelValue().(name string, keys, values []string) string {
204 for i, key := range keys {
205 if key == name {
206 if i < len(values) {
207 return values[i]
208 }
209 return ""
210 }
211 }
212 return ""
213 }
214
215 func cleanBackendNamescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/cleanBackendName().(name string) string {
216 name = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Trimscip-go gomod github.com/golang/go/src go1.25.0 strings/Trim().(name, ".")
217 for _, prefix := range []string{"boot.", "root:"} {
218 if startsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWith().(name, prefix, caseInsensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseInsensitive.) {
219 name = name[len(prefix):]
220 }
221 }
222
223 // reload_2019-08-29T100458.<name> as by varnish_reload_vcl in 4.x
224 // reload_20191014_091124_78599.<name> as by varnishreload in 6+
225 if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(name, "reload_") {
226 dot := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Indexscip-go gomod github.com/golang/go/src go1.25.0 strings/Index().(name, ".")
227 if dot != -1 {
228 name = name[dot+1:]
229 }
230 }
231
232 return name
233 }
234
235 // https://prometheus.io/docs/practices/naming/
236 func computePrometheusInfoscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/computePrometheusInfo().(vName, vGroup, vIdentifier, vDescription string) (name, description string, labelKeys, labelValues []string) {
237 {
238 // Varnish >= 5.2 no longer has 'ident', parse from full vName
239 // as "<group>.<ident>.<name>"
240 if len(vIdentifier) == 0 && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Countscip-go gomod github.com/golang/go/src go1.25.0 strings/Count().(vName, ".") > 1 {
241 vIdentifier = prometheusTrimGroupPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusTrimGroupPrefix().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(vName))
242 vIdentifier = vIdentifier[0:stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.LastIndexscip-go gomod github.com/golang/go/src go1.25.0 strings/LastIndex().(vIdentifier, ".")]
243 }
244 }
245 // name and description
246 {
247 fq := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(vName)
248 // Remove unique identifiers from name to group similar metrics by labeling
249 if len(vIdentifier) > 0 {
250 fq = stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(fq, "."+stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(vIdentifier), "", -1)
251 }
252 // Make sure our group is prefixed only once
253 fq = prometheusTrimGroupPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusTrimGroupPrefix().(fq)
254 // Build fq name
255 name = exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace. + "_" + vGroup + "_" + stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(fq, ".", "_", -1)
256 if swapName := fqNamesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqNames.[name]; len(swapName) > 0 {
257 name = swapName
258 }
259 description = vDescription
260 }
261 // labels: can alter final name and description
262 {
263 if len(vIdentifier) > 0 {
264 if isVBE := startsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWith().(vName, "VBE.", caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive.); isVBE {
265 if hits := regexBackendUUIDscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/regexBackendUUID..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindAllStringSubmatch().(vIdentifier, -1); len(hits) > 0 && len(hits[0]) >= 3 {
266 labelKeys, labelValues = append(labelKeys, "backend"), append(labelValues, cleanBackendNamescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/cleanBackendName().(hits[0][2]))
267 labelKeys, labelValues = append(labelKeys, "server"), append(labelValues, hits[0][1])
268 } else if hits := regexBackendParenscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/regexBackendParen..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#FindAllStringSubmatch().(vIdentifier, -1); len(hits) > 0 && len(hits[0]) >= 3 {
269 labelKeys, labelValues = append(labelKeys, "backend"), append(labelValues, cleanBackendNamescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/cleanBackendName().(hits[0][1]))
270 labelKeys, labelValues = append(labelKeys, "server"), append(labelValues, stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Replacescip-go gomod github.com/golang/go/src go1.25.0 strings/Replace().(hits[0][2], ",,", ":", 1))
271 }
272 // We must be consistent with the number of labels and their names inside this scrape and between scrapes, or we will get this error:
273 // https://github.com/prometheus/client_golang/blob/3fb8ace93bc4ccddea55af62320c2fd109252880/prometheus/registry.go#L704-L707
274 if len(labelKeys) == 0 {
275 labelKeys, labelValues = append(labelKeys, "backend"), append(labelValues, cleanBackendNamescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/cleanBackendName().(vIdentifier))
276 labelKeys, labelValues = append(labelKeys, "server"), append(labelValues, "unknown")
277 }
278 }
279 if len(labelKeys) == 0 {
280 labelKey := fqIdentifiersscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqIdentifiers.[name]
281 if len(labelKey) == 0 {
282 labelKey = "id"
283 }
284 labelKeys, labelValues = append(labelKeys, labelKey), append(labelValues, vIdentifier)
285 }
286 }
287
288 // create groupings by moving part of the fq name as a label and optional total
289 for _, grouping := range fqGroupPrefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/fqGroupPrefixes. {
290 fqTotal := exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace. + "_" + grouping.totalscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#total.
291 fqPrefix := exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace. + "_" + grouping.prefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#prefix.
292 fqNewName := fqPrefix
293 if len(grouping.newPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#newPrefix.) > 0 {
294 fqNewName = exporterNamespacescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/exporterNamespace. + "_" + grouping.newPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#newPrefix.
295 }
296 if name == fqTotal {
297 // @note total should not be a label as it breaks aggregation
298 name, description = fqNewName+"_total", grouping.descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc.
299 break
300 } else if len(name) > len(fqPrefix)+1 && stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25.0 strings/HasPrefix().(name, fqPrefix+"_") {
301 labelKey := "type"
302 if len(grouping.labelKeyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#labelKey.) > 0 {
303 labelKey = grouping.labelKeyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#labelKey.
304 }
305 labelKeys, labelValues = append(labelKeys, labelKey), append(labelValues, name[len(fqPrefix)+1:])
306 name, description = fqNewName, grouping.descscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/grouping#desc.
307 break
308 }
309 }
310 }
311 return name, description, labelKeys, labelValues
312 }
313
314 func prometheusTrimGroupPrefixscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusTrimGroupPrefix().(name string) string {
315 nameLower := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(name)
316 for _, group := range groupsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/groups. {
317 for _, prefix := range group.prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes. {
318 if startsWithscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWith().(nameLower, prefix, caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive.) {
319 return name[len(prefix):]
320 }
321 }
322 }
323 return name
324 }
325
326 // Always returns at least one main label
327 func prometheusGroupscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/prometheusGroup().(vName string) string {
328 vNameLower := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.ToLowerscip-go gomod github.com/golang/go/src go1.25.0 strings/ToLower().(vName)
329 for _, group := range groupsscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/groups. {
330 if startsWithAnyscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/startsWithAny().(vNameLower, group.prefixesscip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#prefixes., caseSensitivescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/caseSensitive.) {
331 return group.namescip-go gomod github.com/otto-de/prometheus_varnish_exporter . `github.com/otto-de/prometheus_varnish_exporter`/group#name.
332 }
333 }
334 return "main"
335 }