Skip to content

Commit 1131001

Browse files
author
Yannig Perré
committed
enhancement: add metrics via a configuration file
New option to add custom metrics from TOML file. Add examples and update README file. You can also use env var. Refactor the way we retrieve informations from oracle by introducing new functions ScrapeGenericValues and GeneratePrometheusMetrics to simplify Prometheus metrics generation. Porting several existing function to use ScrapeGenericValues and removing specific methods to scrape values. Introducing new Metric struct describing metrics to scrape. Add a new structure with all metrics defined. Stop using a new connection everytime we scrape values. Go handle case where connections is lost. New metrics to retrieve asm diskgroup informations and resource limit. Update version of ubuntu in Dockerfile.
1 parent dd59e20 commit 1131001

File tree

6 files changed

+386
-205
lines changed

6 files changed

+386
-205
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:17.04
1+
FROM ubuntu:17.10
22
MAINTAINER Seth Miller <seth@sethmiller.me>
33

44
RUN apt-get -qq update && \

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ deps:
2020
@sudo rpm -Uvh --nodeps oracle*rpm
2121
@echo /usr/lib/oracle/12.2/client64/lib | sudo tee /etc/ld.so.conf.d/oracle.conf
2222
@sudo ldconfig
23+
@PKG_CONFIG_PATH=${PWD} go get
2324

2425
test:
2526
@echo test

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ The following metrics are exposed currently.
3131
- oracledb_tablespace_bytes
3232
- oracledb_tablespace_max_bytes
3333
- oracledb_tablespace_bytes_free
34+
- oracledb_resource_current_utilization
35+
- oracledb_resource_limit_value
3436

3537
# Installation
3638

@@ -67,12 +69,99 @@ Usage of oracledb_exporter:
6769
If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
6870
-log.level value
6971
Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
72+
-custom.metrics string
73+
File that may contain various custom metrics in a TOML file.
7074
-web.listen-address string
7175
Address to listen on for web interface and telemetry. (default ":9161")
7276
-web.telemetry-path string
7377
Path under which to expose metrics. (default "/metrics")
7478
```
7579

80+
# Custom metrics
81+
82+
This exporter does not have the metrics you want? You can provide new one using TOML file. To specify this file to the exporter, you can:
83+
- Use ``-custom.metrics`` flag followed by the TOML file
84+
- Export CUSTOM_METRICS variable environment (``export CUSTOM_METRICS=my-custom-metrics.toml``)
85+
86+
This file must contain the following elements:
87+
- One or several metric section (``[[metric]]``)
88+
- For each section a context, a request and a map between a field of your request and a comment.
89+
90+
Here's a simple example:
91+
92+
```
93+
[[metric]]
94+
context = "test"
95+
request = "SELECT 1 as value_1, 2 as value_2 FROM DUAL"
96+
metricsdesc = { value_1 = "Simple example returning always 1.", value_2 = "Same but returning always 2." }
97+
```
98+
99+
This file produce the following entries in the exporter:
100+
101+
```
102+
# HELP oracledb_test_value_1 Simple example returning always.
103+
# TYPE oracledb_test_value_1 gauge
104+
oracledb_test_value_1 1
105+
# HELP oracledb_test_value_2 Same but returning always 2.
106+
# TYPE oracledb_test_value_2 gauge
107+
oracledb_test_value_2 2
108+
```
109+
110+
You can also provide labels using labels field. Here's an example providing two metrics, with and without labels:
111+
112+
```
113+
[[metric]]
114+
context = "context_no_label"
115+
request = "SELECT 1 as value_1, 2 as value_2 FROM DUAL"
116+
metricsdesc = { value_1 = "Simple example returning always 1.", value_2 = "Same but returning always 2." }
117+
118+
[[metric]]
119+
context = "context_with_labels"
120+
labels = [ "label_1", "label_2" ]
121+
request = "SELECT 1 as value_1, 2 as value_2, 'First label' as label_1, 'Second label' as label_2 FROM DUAL"
122+
metricsdesc = { value_1 = "Simple example returning always 1.", value_2 = "Same but returning always 2." }
123+
```
124+
125+
This TOML file produce the following result:
126+
127+
```
128+
# HELP oracledb_context_no_label_value_1 Simple example returning always 1.
129+
# TYPE oracledb_context_no_label_value_1 gauge
130+
oracledb_context_no_label_value_1 1
131+
# HELP oracledb_context_no_label_value_2 Same but returning always 2.
132+
# TYPE oracledb_context_no_label_value_2 gauge
133+
oracledb_context_no_label_value_2 2
134+
# HELP oracledb_context_with_labels_value_1 Simple example returning always 1.
135+
# TYPE oracledb_context_with_labels_value_1 gauge
136+
oracledb_context_with_labels_value_1{label_1="First label",label_2="Second label"} 1
137+
# HELP oracledb_context_with_labels_value_2 Same but returning always 2.
138+
# TYPE oracledb_context_with_labels_value_2 gauge
139+
oracledb_context_with_labels_value_2{label_1="First label",label_2="Second label"} 2
140+
```
141+
142+
Last, you can set metric type using **metricstype** field.
143+
144+
```
145+
[[metric]]
146+
context = "context_with_labels"
147+
labels = [ "label_1", "label_2" ]
148+
request = "SELECT 1 as value_1, 2 as value_2, 'First label' as label_1, 'Second label' as label_2 FROM DUAL"
149+
metricsdesc = { value_1 = "Simple example returning always 1 as counter.", value_2 = "Same but returning always 2 as gauge." }
150+
# Can be counter or gauge (default)
151+
metricstype = { value_1 = "counter" }
152+
```
153+
154+
This TOML file will produce the following result:
155+
156+
```
157+
# HELP oracledb_test_value_1 Simple test example returning always 1 as counter.
158+
# TYPE oracledb_test_value_1 counter
159+
oracledb_test_value_1 1
160+
# HELP oracledb_test_value_2 Same test but returning always 2 as gauge.
161+
# TYPE oracledb_test_value_2 gauge
162+
oracledb_test_value_2 2
163+
```
164+
76165
# Integration with Grafana
77166

78167
An example Grafana dashboard is available [here](https://grafana.com/dashboards/3333).

0 commit comments

Comments
 (0)