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

Refactor to allow packaging of oracledb_exporter #308

Merged
merged 5 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,48 @@ Everything must compile, including mattn driver for oracle.

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

## Import into your Golang Application
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also let me know if this snippet is too long for your preference :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's perfect.


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.

Here is a small snippet of an example usage of the exporter in code:

```go
promLogConfig := &promlog.Config{}
// create your own config
logger := promlog.New(promLogConfig)

// replace with your connection string
connectionString := "oracle://username:password@localhost:1521/orcl.localnet"
oeExporter, err := oe.NewExporter(logger, &oe.Config{
DSN: connectionString,
MaxIdleConns: 0,
MaxOpenConns: 10,
QueryTimeout: 5,
})

if err != nil {
panic(err)
}

metricChan := make(chan prometheus.Metric, len(oeExporter.DefaultMetrics().Metric))
oeExporter.Collect(metricChan)

// alternatively its possible to run scrapes on an interval
// and Collect() calls will only return updated data once
// that intervaled scrape is run
// please note this is a blocking call so feel free to run
// in a separate goroutine
// oeExporter.RunScheduledScrapes(context.Background(), time.Minute)

for r := range metricChan {
// Write to the client of your choice
// or spin up a promhttp.Server to serve these metrics
r.Write(&dto.Metric{})
}

```

# FAQ/Troubleshooting

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