Skip to content

Commit

Permalink
fix oracle plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
UlricQin committed Jul 26, 2022
1 parent c333851 commit cba82ca
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions inputs/oracle/oracle_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"strings"
"sync"
"sync/atomic"
"time"

"flashcat.cloud/categraf/config"
Expand Down Expand Up @@ -84,22 +83,25 @@ func (ins *Instance) Init() error {

connString := ins.getConnectionString()
var err error
client, err = sqlx.Open("godror", connString)
ins.client, err = sqlx.Open("godror", connString)
if err != nil {
return fmt.Errorf("failed to open oracle connection: %v", err)
}

client.SetMaxOpenConns(ins.MaxOpenConnections)
ins.client.SetMaxOpenConns(ins.MaxOpenConnections)
return nil
}

func (ins *Instance) Drop() error {
if config.Config.DebugMode {
log.Println("D! dropping oracle connection:", ins.Address)
}

if err := ins.Close(); err != nil {
if err := ins.client.Close(); err != nil {
log.Println("E! failed to close oracle connection:", ins.Address, "error:", err)
}

return nil
}

func (ins *Instance) Gather(slist *types.SampleList) {
Expand All @@ -119,8 +121,8 @@ func (ins *Instance) Gather(slist *types.SampleList) {

waitMetrics := new(sync.WaitGroup)

for i := 0; i < len(o.Metrics); i++ {
m := o.Metrics[i]
for i := 0; i < len(ins.Metrics); i++ {
m := ins.Metrics[i]
waitMetrics.Add(1)
go ins.scrapeMetric(waitMetrics, slist, m, tags)
}
Expand All @@ -141,7 +143,7 @@ func (ins *Instance) scrapeMetric(waitMetrics *sync.WaitGroup, slist *types.Samp
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

rows, err := client.QueryContext(ctx, metricConf.Request)
rows, err := ins.client.QueryContext(ctx, metricConf.Request)

if ctx.Err() == context.DeadlineExceeded {
log.Println("E! oracle query timeout, request:", metricConf.Request)
Expand Down

0 comments on commit cba82ca

Please sign in to comment.