Debian Codegraph @

prometheus/collectors/dbstats_collector.go

raw symbols SCIP
1 // Copyright 2021 The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package collectorsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/
15
16 import (
17 "database/sqlscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/"
18
19 "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/"
20 )
21
22 type dbStatsCollectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector# struct {
23 dbscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#db. *sqlscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/.DBscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DB#
24
25 maxOpenConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxOpenConnections. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
26
27 openConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#openConnections. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
28 inUseConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#inUseConnections. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
29 idleConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#idleConnections. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
30
31 waitCountscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitCount. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
32 waitDurationscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitDuration. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
33 maxIdleClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleClosed. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
34 maxIdleTimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleTimeClosed. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
35 maxLifetimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxLifetimeClosed. *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#
36 }
37
38 // NewDBStatsCollector returns a collector that exports metrics about the given *sql.DB.
39 // See https://golang.org/pkg/database/sql/#DBStats for more information on stats.
40 func NewDBStatsCollectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/NewDBStatsCollector().(db *sqlscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/.DBscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DB#, dbName string) prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Collectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Collector# {
41 fqName := func(name string) string {
42 return "go_sql_" + name
43 }
44 return &dbStatsCollectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#{
45 dbscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#db.: db,
46 maxOpenConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxOpenConnections.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
47 fqName("max_open_connections"),
48 "Maximum number of open connections to the database.",
49 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
50 ),
51 openConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#openConnections.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
52 fqName("open_connections"),
53 "The number of established connections both in use and idle.",
54 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
55 ),
56 inUseConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#inUseConnections.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
57 fqName("in_use_connections"),
58 "The number of connections currently in use.",
59 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
60 ),
61 idleConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#idleConnections.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
62 fqName("idle_connections"),
63 "The number of idle connections.",
64 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
65 ),
66 waitCountscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitCount.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
67 fqName("wait_count_total"),
68 "The total number of connections waited for.",
69 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
70 ),
71 waitDurationscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitDuration.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
72 fqName("wait_duration_seconds_total"),
73 "The total time blocked waiting for a new connection.",
74 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
75 ),
76 maxIdleClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleClosed.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
77 fqName("max_idle_closed_total"),
78 "The total number of connections closed due to SetMaxIdleConns.",
79 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
80 ),
81 maxIdleTimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleTimeClosed.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
82 fqName("max_idle_time_closed_total"),
83 "The total number of connections closed due to SetConnMaxIdleTime.",
84 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
85 ),
86 maxLifetimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxLifetimeClosed.: prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.NewDescscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/NewDesc().(
87 fqName("max_lifetime_closed_total"),
88 "The total number of connections closed due to SetConnMaxLifetime.",
89 nil, prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Labelsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Labels#{"db_name": dbName},
90 ),
91 }
92 }
93
94 // Describe implements Collector.
95 func (c *dbStatsCollectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#) Describescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#Describe().(ch chan<- *prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Descscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Desc#) {
96 ch <- c.maxOpenConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxOpenConnections.
97 ch <- c.openConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#openConnections.
98 ch <- c.inUseConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#inUseConnections.
99 ch <- c.idleConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#idleConnections.
100 ch <- c.waitCountscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitCount.
101 ch <- c.waitDurationscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitDuration.
102 ch <- c.maxIdleClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleClosed.
103 ch <- c.maxLifetimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxLifetimeClosed.
104 ch <- c.maxIdleTimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleTimeClosed.
105 }
106
107 // Collect implements Collector.
108 func (c *dbStatsCollectorscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#) Collectscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#Collect().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/Metric#) {
109 stats := c.dbscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#db..Statsscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DB#Stats().()
110 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.maxOpenConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxOpenConnections., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/GaugeValue., float64(stats.MaxOpenConnectionsscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#MaxOpenConnections.))
111 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.openConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#openConnections., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/GaugeValue., float64(stats.OpenConnectionsscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#OpenConnections.))
112 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.inUseConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#inUseConnections., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/GaugeValue., float64(stats.InUsescip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#InUse.))
113 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.idleConnectionsscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#idleConnections., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.GaugeValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/GaugeValue., float64(stats.Idlescip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#Idle.))
114 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.waitCountscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitCount., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.CounterValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/CounterValue., float64(stats.WaitCountscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#WaitCount.))
115 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.waitDurationscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#waitDuration., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.CounterValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/CounterValue., stats.WaitDurationscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#WaitDuration..Secondsscip-go gomod github.com/golang/go/src go1.23.0 time/Duration#Seconds().())
116 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.maxIdleClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleClosed., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.CounterValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/CounterValue., float64(stats.MaxIdleClosedscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#MaxIdleClosed.))
117 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.maxLifetimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxLifetimeClosed., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.CounterValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/CounterValue., float64(stats.MaxLifetimeClosedscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#MaxLifetimeClosed.))
118 ch <- prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.MustNewConstMetricscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/MustNewConstMetric().(c.maxIdleTimeClosedscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus/collectors`/dbStatsCollector#maxIdleTimeClosed., prometheusscip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/.CounterValuescip-go gomod github.com/prometheus/client_golang . `github.com/prometheus/client_golang/prometheus`/CounterValue., float64(stats.MaxIdleTimeClosedscip-go gomod github.com/golang/go/src go1.23.0 `database/sql`/DBStats#MaxIdleTimeClosed.))
119 }