Skip to content

Commit eae751f

Browse files
author
Yannig Perré
committed
Change the way we retrieve information on sessions activity.
Use only one request to retrieve active and inactive sessions. Add a new information about session type (USER or BACKGROUND). Update README to reflect change in metrics name.
1 parent bb5dc5c commit eae751f

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ The following metrics are exposed currently.
1616
- oracledb_activity_parse_count_total
1717
- oracledb_activity_user_commits
1818
- oracledb_activity_user_rollbacks
19-
- oracledb_sessions_active
20-
- oracledb_sessions_inactive
19+
- oracledb_sessions_activity
20+
- oracledb_sessions_active (deprecated. Use ``sum(oracledb_sessions_activity{status='ACTIVE'})`` instead.)
21+
- oracledb_sessions_inactive (deprecated. Use ``sum(oracledb_sessions_activity{status='INACTIVE'})`` instead.)
2122
- oracledb_wait_time_application
2223
- oracledb_wait_time_commit
2324
- oracledb_wait_time_concurrency

main.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
155155
e.scrapeErrors.WithLabelValues("wait_time").Inc()
156156
}
157157

158+
if err = DeprecatedScrapeSessions(db, ch); err != nil {
159+
log.Errorln("Error scraping for sessions:", err)
160+
e.scrapeErrors.WithLabelValues("sessions").Inc()
161+
}
162+
158163
if err = ScrapeSessions(db, ch); err != nil {
159164
log.Errorln("Error scraping for sessions:", err)
160165
e.scrapeErrors.WithLabelValues("sessions").Inc()
@@ -163,7 +168,8 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
163168
}
164169

165170
// ScrapeSessions collects session metrics from the v$session view.
166-
func ScrapeSessions(db *sql.DB, ch chan<- prometheus.Metric) error {
171+
// DEPRECATED
172+
func DeprecatedScrapeSessions(db *sql.DB, ch chan<- prometheus.Metric) error {
167173
var err error
168174
var activeCount float64
169175
var inactiveCount float64
@@ -176,7 +182,7 @@ func ScrapeSessions(db *sql.DB, ch chan<- prometheus.Metric) error {
176182

177183
ch <- prometheus.MustNewConstMetric(
178184
prometheus.NewDesc(prometheus.BuildFQName(namespace, "sessions", "active"),
179-
"Gauge metric with count of sessions marked ACTIVE", []string{}, nil),
185+
"Gauge metric with count of sessions marked ACTIVE. DEPRECATED: use sum(oracledb_sessions_activity{status='ACTIVE}) instead.", []string{}, nil),
180186
prometheus.GaugeValue,
181187
activeCount,
182188
)
@@ -188,14 +194,48 @@ func ScrapeSessions(db *sql.DB, ch chan<- prometheus.Metric) error {
188194

189195
ch <- prometheus.MustNewConstMetric(
190196
prometheus.NewDesc(prometheus.BuildFQName(namespace, "sessions", "inactive"),
191-
"Gauge metric with count of sessions marked INACTIVE.", []string{}, nil),
197+
"Gauge metric with count of sessions marked INACTIVE. DEPRECATED: use sum(oracledb_sessions_activity{status='INACTIVE'}) instead.", []string{}, nil),
192198
prometheus.GaugeValue,
193199
inactiveCount,
194200
)
195201

196202
return nil
197203
}
198204

205+
// ScrapeSessions collects session metrics from the v$session view.
206+
func ScrapeSessions(db *sql.DB, ch chan<- prometheus.Metric) error {
207+
var (
208+
rows *sql.Rows
209+
err error
210+
)
211+
// Retrieve status and type for all sessions.
212+
rows, err = db.Query("SELECT status, type, COUNT(*) FROM v$session GROUP BY status, type")
213+
if err != nil {
214+
return err
215+
}
216+
217+
defer rows.Close()
218+
for rows.Next() {
219+
var (
220+
status string
221+
sessionType string
222+
count float64
223+
)
224+
if err := rows.Scan(&status, &sessionType, &count); err != nil {
225+
return err
226+
}
227+
ch <- prometheus.MustNewConstMetric(
228+
prometheus.NewDesc(prometheus.BuildFQName(namespace, "sessions", "activity"),
229+
"Gauge metric with count of sessions by status and type", []string{"status", "type"}, nil),
230+
prometheus.GaugeValue,
231+
count,
232+
status,
233+
sessionType,
234+
)
235+
}
236+
return nil
237+
}
238+
199239
// ScrapeWaitTime collects wait time metrics from the v$waitclassmetric view.
200240
func ScrapeWaitTime(db *sql.DB, ch chan<- prometheus.Metric) error {
201241
var (

0 commit comments

Comments
 (0)