1. 程式人生 > 實用技巧 >基於godror 的 oracle prometheus exporter

基於godror 的 oracle prometheus exporter

iamseth/oracledb_exporter 是一個挺不錯的 oracle prometheus exporter ,但是因為oracle golang 驅動的問題,不是很方便
(構建,使用),所以基於godror/godror 調整了一個版本(很簡單,替換一個依賴包就可以了),以下是參考說明

修改的檔案

go.mod

module github.com/iamseth/oracledb_exporter
go 1.14
require (
  github.com/BurntSushi/toml v0.3.1
  github.com/godror/godror v0.20.10
  github.com/prometheus/client_golang v1.0.0
  github.com/prometheus/common v0.6.0
  gopkg.in/alecthomas/kingpin.v2 v2.2.6
)

main.go

package main
import (
  "bytes"
  "context"
  "crypto/sha256"
  "database/sql"
  "errors"
  "hash"
  "io"
  "net/http"
  "os"
  "strconv"
  "strings"
  "sync"
  "time"
  "github.com/BurntSushi/toml"
  _ "github.com/godror/godror"
  "fmt"
  "github.com/prometheus/client_golang/prometheus"
  "github.com/prometheus/client_golang/prometheus/promhttp"
  "github.com/prometheus/common/log"
  "gopkg.in/alecthomas/kingpin.v2"
  //Required for debugging
  //_ "net/http/pprof"
)

Docker 映象(基於oraclelinux)

FROM golang:1.15 AS build
WORKDIR /go/src/oracledb_exporter
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.cn
COPY . .
RUN go build -v -ldflags "-X main.Version=${VERSION} -s -w"
FROM oraclelinux:7-slim
ARG release=19
ARG update=9
RUN yum -y install oracle-release-el7 && \
   yum -y install oracle-instantclient${release}.${update}-basic && \
   rm -rf /var/cache/yum && \
   yum clean all
COPY --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
ADD ./default-metrics.toml /default-metrics.toml
EXPOSE 9161
ENTRYPOINT ["/oracledb_exporter"]

說明

具體的使用方法沒變,還是以前的方法,只是構建以及使用簡單了

參考資料

https://github.com/iamseth/oracledb_exporter
https://github.com/rongfengliang/oracledb_exporter
https://www.cnblogs.com/rongfengliang/p/14109740.html
https://github.com/godror/godror