free / sql_exporter

Database agnostic SQL exporter for Prometheus
MIT License
537 stars 171 forks source link

Can this exporterr support oracle? #2

Open william-yang opened 6 years ago

william-yang commented 6 years ago

Can this exporter support orcale? If not, did you have plan to do it?

free commented 6 years ago

[Apologies for not answering before, for some reason I am getting no email notification from newly created issues and I just noticed this.]

As stated in the first paragraph of the README, SQL Exporter supports any database for which a Go driver is available. There exist a couple of Go drivers for Oracle but they both require an external library (oci8.pc) to be placed in a specific location. Seeing as how this is quite error prone and I don't even have an Oracle instance to test against, I have opted to not add it initially.

If you're willing to do the work yourself (including particularly testing and documenting the process) I will happily accept PRs. Otherwise I might need to monitor an Oracle instance at some point (it's not yet decided if or when) so I might do it myself then.

free commented 6 years ago

Oh, I forgot to mention this: if you want to get SQL Exporter working with Oracle, you'll need to follow the installation steps for either of the Oracle drivers, import the driver package into SQL Exporter's sql.go and rebuild SQL Exporter. Not all that complicated (once you've set up the Oracle driver).

marksteward commented 6 years ago

https://github.com/Corundex/database_exporter has started doing this along with a rebrand, which is currently the top hit on Google. Did anyone start work on a PR?

free commented 6 years ago

Did anyone start work on a PR?

Not as far as I know. But we could just "borrow" it back from the Corundex exporter. I'm sure they won't mind :o)

arnaudlemaignen commented 6 years ago

So in the end, will this exporter is supposed to work with Oracle, or should we use the one from Corundex? I tried the Corundex one, it is working mostly but I have issues with long queries (which takes 10min in sqlplus). I got following issues for that query

bad thing is, there is no "Issue" blog in the Corundex repo, so I can not report any errors or discuss how to contribute.

GETandSELECT commented 5 years ago

any news on Oracle support?

xuanyuanaosheng commented 4 years ago

@free any news on Oracle support?

arnaudlemaignen commented 4 years ago

I have a working solution but not pushable in the current depot. Actually there are 2 issues:

  1. to query an oracle DB in go you need the oracle instant client, this client is depending on the libaio.

The issue is that the sql_exporter is based on busybox and I did not found a good/easy way to install the libaio package with dpkg

RUN wget http://ftp.fr.debian.org/debian/pool/main/liba/libaio/libaio1_0.3.112-3_i386.deb RUN wget http://ftp.fr.debian.org/debian/pool/main/g/glibc/libc6_2.28-10_amd64.deb RUN dpkg -i libc6_2.28-10_amd64.deb RUN dpkg -i libaio1_0.3.112-3_i386.deb

but then tons of dependencies should be installed as well, and did not had the courage to sort those all

  1. the packaging for compiling the sql_exporter binary

I add a few lines in query.go and add godror lib (https://github.com/godror/godror, previsouly called goracle) to query with oracle

whatever I am trying to adapt the Makefile, I am ending with this error. It seems related to the CGO compilation of the godror lib

make build

building binaries sql_exporter

github.com/godror/godror

src/github.com/godror/godror/orahlp.go:452:53: undefined: VersionInfo src/github.com/godror/godror/orahlp.go:461:53: undefined: VersionInfo src/github.com/godror/godror/orahlp.go:479:19: undefined: VersionInfo src/github.com/godror/godror/orahlp.go:480:19: undefined: VersionInfo src/github.com/godror/godror/orahlp.go:481:30: undefined: ObjectType src/github.com/godror/godror/orahlp.go:482:31: undefined: Event src/github.com/godror/godror/orahlp.go:482:41: undefined: Subscription src/github.com/godror/godror/orahlp.go:483:10: undefined: StartupMode src/github.com/godror/godror/orahlp.go:484:11: undefined: ShutdownMode src/github.com/godror/godror/orahlp.go:485:59: undefined: Data src/github.com/godror/godror/orahlp.go:485:59: too many errors

WA :

  1. change the base image from busybox to centos or other and install libaio

FROM centos:7 RUN yum -y update \ && yum -y install libaio \ && yum clean all ... COPY --from=builder /go/src/github.com/free/sql_exporter/sql_exporter /bin/sql_exporter ...

Copy DB instant client rpms and setup correctly the dependencies

ENV ORACLE_VERSION 12.1.2 ENV ORACLE_VERSION_SHORT 12.1

COPY dependency/oracle-instantclient-$ORACLE_VERSION.rpm /tmp COPY dependency/oracle-instantclient-$ORACLE_VERSION-devel.rpm /tmp RUN rpm -ivh /tmp/oracle-instantclient-$ORACLE_VERSION.rpm RUN rpm -ivh /tmp/oracle-instantclient-$ORACLE_VERSION-devel.rpm

ENV LD_LIBRARY_PATH /usr/lib/oracle/$ORACLE_VERSION_SHORT/client64/lib/${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} RUN mkdir /usr/lib/oracle/$ORACLE_VERSION_SHORT/client64/rdbms RUN ln -s /usr/include/oracle/$ORACLE_VERSION_SHORT/client64 /usr/lib/oracle/$ORACLE_VERSION_SHORT/client64/rdbms/public ENV ORACLE_HOME /usr/lib/oracle/$ORACLE_VERSION_SHORT/client64

ENTRYPOINT [ "/bin/sql_exporter" ]

  1. Here it is a question of how to build correctly the binary, I am not knowledgeable on that Makefile :(. I had to use tricks to make it works (reusing the Makefile and folder structure from Corundex, ie moving the cmd files in root and moving the root files to the exporter folder).

If someone can help me to solve issue 1. and 2. in the current sql_exporter branch, I would be happy to maintain the oracle DB related items for this exporter. I can provide the whole project if needed and I have the good infra to test it.

4dr14ns1 commented 4 years ago

I managed to add godror driver to current sql_exporter. These are the steps:

$ rpm -qa | grep oracle-instantclient | grep -e basic -e devel oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64 oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64


- prepare package config for oci8 and export LD_LIBRARY_PATH

$ ls -go /usr/local/lib/pkgconfig/ total 4 -rw-r--r--. 1 283 Mar 17 21:36 oci8_linux_amd64.pc lrwxrwxrwx. 1 19 Mar 17 21:36 oci8.pc -> oci8_linux_amd64.pc

$ cat /usr/local/lib/pkgconfig/oci8_linux_amd64.pc prefix=/usr

version=12.2 build=client64

libdir=${prefix}/lib/oracle/${version}/${build}/lib includedir=${prefix}/include/oracle/${version}/${build}

Name: oci8 Description: Oracle database engine Version: ${version} Libs: -L${libdir} -lclntsh Libs.private: Cflags: -I${includedir}

$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig $ pkg-config --libs --cflags oci8 -I/usr/include/oracle/12.2/client64 -L/usr/lib/oracle/12.2/client64/lib -lclntsh

$ export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib:/usr/local/lib:/usr/lib64:/lib64:$LD_LIBRARY_PATH

- check that CGO_ENABLED is set to 1

$ go env | grep CGO_ENABLED CGO_ENABLED="1"

- get github.com/godror/godror
`$ go get github.com/godror/godror`
- get github.com/free/sql_exporter
`$ go get github.com/free/sql_exporter`
- apply patch for 
    * .promu.yml (cgo set to true, static set to false -> dynamic executable (oracle lib dependencies) , and ld flags - in this particular case is hardcoded for oracle version 12.2) 
    * sql.go (register godror driver and oracle dsn prefix)

diff --git a/.promu.yml b/.promu.yml index 0297aa0..3b0be69 100644 --- a/.promu.yml +++ b/.promu.yml @@ -1,5 +1,5 @@ go:

I just ran a simple test with one metric and i noticed that i have to make aliases for the columns (column in lowercase between double quotes) otherwise key_labels and values must be written in uppercase in the yaml file.

I do not know if i broke something else but at least for me is working for oracle database.

stud0709 commented 3 years ago

@4dr14ns1, I am not a gopher, and I run into problems with the compilation. I can follow you regarding the changes you make to sql.go. And then I tried to go build the stuff, but it fails with

# _/home/ydzh/Documents/git/sql_exporter
./metric.go:99:28: cannot use mf.config.ValueType() (type "github.com/free/sql_exporter/vendor/github.com/prometheus/client_golang/prometheus".ValueType) as type "github.com/prometheus/client_golang/prometheus".ValueType in return argument

Is it something you address within .promu.yml or a different issue?

4dr14ns1 commented 3 years ago

@4dr14ns1, I am not a gopher, and I run into problems with the compilation. I can follow you regarding the changes you make to sql.go. And then I tried to go build the stuff, but it fails with ... Is it something you address within .promu.yml or a different issue?

I am not a gopher also, two ears ago i spend some time on it just enough to be able to build sql_exporter. In case that you did not made any mistake regarding patch details most probably is from godror because there was no update on sql_exporter since 2019.

stud0709 commented 3 years ago

@4dr14ns1, no, because if you git clone sql_exporter "as is" and go build it - you get the same error.