| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package oracledb |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "strconv" |
| 8 | ) |
| 9 | |
| 10 | const querySysMetrics = ` |
| 11 | SELECT |
| 12 | METRIC_NAME, |
| 13 | VALUE |
| 14 | FROM |
| 15 | v$sysmetric |
| 16 | WHERE |
| 17 | METRIC_NAME IN ( |
| 18 | 'Session Count', |
| 19 | 'Session Limit %', |
| 20 | 'Average Active Sessions', |
| 21 | 'Buffer Cache Hit Ratio', |
| 22 | 'Cursor Cache Hit Ratio', |
| 23 | 'Library Cache Hit Ratio', |
| 24 | 'Row Cache Hit Ratio', |
| 25 | 'Global Cache Blocks Corrupted', |
| 26 | 'Global Cache Blocks Lost', |
| 27 | 'Database Wait Time Ratio', |
| 28 | 'SQL Service Response Time' |
| 29 | ) |
| 30 | AND |
| 31 | intsize_csec |
| 32 | = (SELECT max(intsize_csec) FROM sys.v_$sysmetric) |
| 33 | ` |
| 34 | |
| 35 | func (c *Collector) collectSysMetrics(mx map[string]int64) error { |
| 36 | q := querySysMetrics |
| 37 | c.Debugf("executing query: %s", q) |
| 38 | |
| 39 | var name, val string |
| 40 | |
| 41 | return c.doQuery(q, func(column, value string, lineEnd bool) error { |
| 42 | switch column { |
| 43 | case "METRIC_NAME": |
| 44 | name = value |
| 45 | case "VALUE": |
| 46 | val = value |
| 47 | } |
| 48 | if lineEnd { |
| 49 | v, err := strconv.ParseFloat(val, 64) |
| 50 | if err != nil { |
| 51 | return fmt.Errorf("could not parse metric '%s' value '%s': %w", name, val, err) |
| 52 | } |
| 53 | mx[name] = int64(v * precision) |
| 54 | |
| 55 | } |
| 56 | return nil |
| 57 | }) |
| 58 | } |