Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit d0fbef9

Browse files
authored
Refactor to allow packaging of oracledb_exporter (#308)
* refactor to allow packaging of oracledb_exporter * resync the collector package * add code snippet for readme * bump version to 0.5.0 * revert version bump
1 parent 2372265 commit d0fbef9

File tree

6 files changed

+757
-585
lines changed

6 files changed

+757
-585
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,48 @@ Everything must compile, including mattn driver for oracle.
472472

473473
Next build ./... in oracledb-exporter dir, or install it.
474474

475+
## Import into your Golang Application
476+
477+
The `oracledb_exporter` can also be imported into your Go based applications. The [Grafana Agent](https://github.com/grafana/agent/) uses this pattern to implement the [OracleDB integration](https://grafana.com/docs/grafana-cloud/data-configuration/integrations/integration-reference/integration-oracledb/). Feel free to modify the code to fit your application's use case.
478+
479+
Here is a small snippet of an example usage of the exporter in code:
480+
481+
```go
482+
promLogConfig := &promlog.Config{}
483+
// create your own config
484+
logger := promlog.New(promLogConfig)
485+
486+
// replace with your connection string
487+
connectionString := "oracle://username:password@localhost:1521/orcl.localnet"
488+
oeExporter, err := oe.NewExporter(logger, &oe.Config{
489+
DSN: connectionString,
490+
MaxIdleConns: 0,
491+
MaxOpenConns: 10,
492+
QueryTimeout: 5,
493+
})
494+
495+
if err != nil {
496+
panic(err)
497+
}
498+
499+
metricChan := make(chan prometheus.Metric, len(oeExporter.DefaultMetrics().Metric))
500+
oeExporter.Collect(metricChan)
501+
502+
// alternatively its possible to run scrapes on an interval
503+
// and Collect() calls will only return updated data once
504+
// that intervaled scrape is run
505+
// please note this is a blocking call so feel free to run
506+
// in a separate goroutine
507+
// oeExporter.RunScheduledScrapes(context.Background(), time.Minute)
508+
509+
for r := range metricChan {
510+
// Write to the client of your choice
511+
// or spin up a promhttp.Server to serve these metrics
512+
r.Write(&dto.Metric{})
513+
}
514+
515+
```
516+
475517
# FAQ/Troubleshooting
476518

477519
## Unable to convert current value to float (metric=par,metri...in.go:285

0 commit comments

Comments
 (0)