Giter VIP home page Giter VIP logo

pgbouncer_exporter's People

Contributors

a5r0n avatar aravind avatar benwh avatar dependabot[bot] avatar kenneth-duffel avatar larseen avatar marcusteixeira avatar prombot avatar rsommer avatar shamil avatar sshankar avatar stanhu avatar superq avatar suprememoocow avatar tacerus avatar yansal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgbouncer_exporter's Issues

Show Version is failing in pgbouncer versions older than 1.12

We are using pgbouncer version 1.9. And we are seeing following error in the exporter logs,
level=info ts=2021-01-28T08:33:21.015Z caller=collector.go:406 msg="Starting scrape" level=error ts=2021-01-28T08:33:21.015Z caller=collector.go:412 msg="error getting version" err="show version didn't return version column"

I can see from the change log of pgbouncer that SHOW VERSION output is changed to normal result from notice message. Is there a way we can disable this version metric or can you make it work with the older versions of pgbouncer as well?

Log msg inconsistent

During exporter initialization, the message from stackdriver_exporter is displayed, when it should be pgbouncer_exporter.

Example:
level=info ts=2021-02-10T15:15:44.792Z caller=pgbouncer_exporter.go:80 msg="Starting stackdriver_exporter" version="(version=0.4.0, branch=HEAD, revision=f0ec9fcb91d6cd2ba02e7f6b1d83f658f65dea82)"

image

Exporter can't connect to pgbouncer's unix socket

I ran into an issue setting up the exporter in the same VM where pgbouncer is running.
I have a pgbouncer_exporter user setup with a password to connect to the pgbouncer DB locally through pgbouncer's unix socket.

I can connect to the pgbouncer DB with all these 3 commands:

pgbouncer_exporter@db-host:~$ psql postgres://pgbouncer_exporter:****@%2Fvar%2Frun%2Fpostgresql:6432/pgbouncer
pgbouncer_exporter@db-host:~$ psql postgres://pgbouncer_exporter:****@[/var/run/postgresql]:6432/pgbouncer
pgbouncer_exporter@db-host:~$ psql postgres://pgbouncer_exporter:****@:6432/pgbouncer

But none of the 3 connection strings work in the pgbouncer_exporter:

pgbouncer_exporter@db-host:~$ /usr/local/bin/pgbouncer_exporter --pgBouncer.connectionString="postgres://pgbouncer_exporter:****@/var/run/postgresql:6432/pgbouncer"ts=2023-12-01T12:19:52.371Z caller=collector.go:138 level=error msg="error setting up DB connection" err="error pinging pgbouncer: pq: password authentication failed for user \"pgbouncer_exporter\""
pgbouncer_exporter@db-host:~$ /usr/local/bin/pgbouncer_exporter --pgBouncer.connectionString="postgres://pgbouncer_exporter:****@%2Fvar%2Frun%2Fpostgresql:6432/pgbouncer"
ts=2023-12-01T12:20:16.842Z caller=collector.go:138 level=error msg="error setting up DB connection" err="error pinging pgbouncer: parse \"postgres://pgbouncer_exporter:****@%2Fvar%2Frun%2Fpostgresql:6432/pgbouncer\": invalid URL escape \"%2F\""
pgbouncer_exporter@db-host:~$ /usr/local/bin/pgbouncer_exporter --pgBouncer.connectionString="postgres://pgbouncer_exporter:****@[/var/run/postgresql]:6432/pgbouncer"
ts=2023-12-01T12:20:19.659Z caller=collector.go:138 level=error msg="error setting up DB connection" err="error pinging pgbouncer: parse \"postgres://pgbouncer_exporter:****@[/var/run/postgresql]:6432/pgbouncer\": missing ']' in host"

I can see by default if the host is not specified, pgbouncer_exporter will use localhost ::1 instead of using the unix socket. PGbouncer logs from the login failure:

Dec 01 10:55:38 db-host pgbouncer[472115]: C-0x563c122c7050: (nodb)/(nouser)@[::1]:45336 closing because: SSL required (age=0s)
Dec 01 10:55:38 db-host pgbouncer[472115]: C-0x563c122c7050: (nodb)/(nouser)@[::1]:45336 pooler error: SSL required

So then I have to specify the unix socket directory. How can I do this with the exporter?

Add configuration via environment variables

It would be helpful to be able to use environment variables to set configuration on the exporter. This is a fairly common pattern and absolutely necessary if running this as a sidecar in the Zalando pgsql operator, which currently only allows environment variables to be defined and prevents using command line arguments. I would be glad to put up a PR to add this functionality.

How does this work?

How do I set up this exporter? What is the connection string supposed to be? I tried the example, but all I get is level=error ts=2021-10-14T10:29:24.248Z caller=collector.go:129 msg="error setting up DB connection" err="error pinging pgbouncer: \"pq: not allowed\"".

extra_float_digits problem

Hi,

When connecting, I get this:

ts=2023-01-09T14:32:54.310Z caller=collector.go:129 level=error msg="error setting up DB connection" err="error pinging pgbouncer: "pq: unsupported startup parameter: extra_float_digits""

Any clue on how to solve it? I know I can set pgbouncer to ignore extra_float_digits, but I'm afraid to break something, since the documentation says that newer JBDC drivers use it.

Prometheus reports ' "INVALID" is not a valid start token "

Prometheus reports an error " "INVALID" is not a valid start token " for pgbouncer exporter endpoint.
image

We use such products versions:
pgbouncer - v1.16.2
pgbouncer exporter - v0.4.1
prometheus - v2.31.1

pgbouncer, pgbouncer exporter and prometheus are deployed on Kubernetes
pgbouncer and pgbouncer exporter are deployed as two containers within a single pod in its own namespace. Prometheus is deployed as a separate pod in its own namespace. There is network connectivity between all components.
When we configure port-forward for pgbouncer exporter we're able to browse exposed data:
image
However, it seems like Prometheus is not able to parse this data as valid.

Please advise me on possible directions for investigation of this issue.

Please add new pgbouncer-v1.21.0 metrics related to prepared statements

It would be great if someone could kindly cut a new release including the new pgbouncer-v1.21.0 metrics related to prepared statements.

I would be happy to submit a simple PR but in order to do so I would first have to go through some painful bureaucratic hoops. Hope you understand and I don't come across as entitled brat... :-)

Thank you!

Feature request: Add ENV vars alternative to set parameters

Hello.
Thank you for the pgbouncer_exporter. I was surprised that there is a new one maintained by prometheus-community.

As I see, kingpin supports environment variables in addition to already existing command-line flags.
https://github.com/alecthomas/kingpin/blob/master/_examples/chat1/main.go#L11
So I think it would be nice to add this. I could try to do PR if needed.

P.S. Also there is no information about command-line flags in Readme.md, so I have to download binary and check -h output. It might be good to add it there I suppose.

Grafana Dashboard

Is there any Grafana dashboards for this exporter?
i found a dashboard for similiar exporter but queries not match!
if we have no dashboards i want to create one

Fix Docker image vulnerabilities

The security team blocked us from implementing this exporter due of the following vulnerabilities:

❯ docker scout cves quay.io/prometheuscommunity/pgbouncer-exporter:v0.8.0
    i New version 1.11.0 available (installed version is 1.6.3) at https://github.com/docker/scout-cli
    ✓ Pulled
    ✓ Image stored for indexing
    ✓ Indexed 27 packages
    ✗ Detected 2 vulnerable packages with a total of 5 vulnerabilities


## Overview

                    │                     Analyzed Image                       
────────────────────┼──────────────────────────────────────────────────────────
  Target            │  quay.io/prometheuscommunity/pgbouncer-exporter:v0.8.0   
    digest          │  ca78408f49b6                                            
    platform        │ linux/arm64/v8                                           
    vulnerabilities │    1C     1H     2M     0L     2?                        
    size            │ 9.2 MB                                                   
    packages        │ 27                                                       


## Packages and Vulnerabilities

   1C     1H     1M     0L     2?  stdlib 1.22.1
pkg:golang/[email protected]

    ✗ CRITICAL CVE-2024-24790
      https://scout.docker.com/v/CVE-2024-24790
      Affected range : >=1.22.0-0  
                     : <1.22.4     
      Fixed version  : 1.22.4      
    
    ✗ HIGH CVE-2024-24791
      https://scout.docker.com/v/CVE-2024-24791
      Affected range : >=1.22.0-0  
                     : <1.22.5     
      Fixed version  : 1.22.5      
    
    ✗ MEDIUM CVE-2024-24789
      https://scout.docker.com/v/CVE-2024-24789
      Affected range : >=1.22.0-0  
                     : <1.22.4     
      Fixed version  : 1.22.4      
    
    ✗ UNSPECIFIED CVE-2024-24788
      https://scout.docker.com/v/CVE-2024-24788
      Affected range : >=1.22.0-0  
                     : <1.22.3     
      Fixed version  : 1.22.3      
    
    ✗ UNSPECIFIED CVE-2023-45288
      https://scout.docker.com/v/CVE-2023-45288
      Affected range : >=1.22.0-0  
                     : <1.22.2     
      Fixed version  : 1.22.2      
    

   0C     0H     1M     0L  golang.org/x/net 0.22.0
pkg:golang/golang.org/x/[email protected]

    ✗ MEDIUM CVE-2023-45288 [Uncontrolled Resource Consumption]
      https://scout.docker.com/v/CVE-2023-45288
      Affected range : <0.23.0                                       
      Fixed version  : 0.23.0                                        
      CVSS Score     : 5.3                                           
      CVSS Vector    : CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L  
    
6 vulnerabilities found in 2 packages
  UNSPECIFIED  2  
  LOW          0  
  MEDIUM       2  
  HIGH         1  
  CRITICAL     1

hardcoded db-name, and sslmode=disabled not recognized

Hi Team:

Thank you for your great contibution.

I am trying to use the prebuild binary (pgbouncer_exporter version 0.6.0 linux amd64) in my micro-service. I am automating it via supervisord. As you can see that the connection string here has ?sslmode=disable,
but the error shows up saying that SSL is disabled and the program quits.

I have tried different users as well (postgres user and root user). I also tried changing the database name
in connection-string to 'pgbouncer' , 'postgres' etc. Here is the entries on my setup:

-- supervisord config --
[program:bouncer_metrics]
autorestart=true command=pgbouncer_exporter --log.level=debug --log.format=json --web.listen-address=":9007" --pgBouncer.connectionString="postgresql://sankalra:[email protected]:6432/bouncer_postgres?sslmode=disable" --pgBouncer.pid-file=/
dev/shm/pg_bouncer.pid
stderr_logfile=/dev/log/bouncer_exporter.err
stdout_logfile=/dev/log/bouncer_exporter.log

-- logs : bouncer_exporter.err --
{"caller":"collector.go:138","err":"error pinging pgbouncer: pq: SSL is not enabled on the server","level":"error","msg":"error setting up DB connection","ts":"2023-03-24T19:42:23.608Z"}
{"caller":"collector.go:138","err":"error pinging pgbouncer: pq: SSL is not enabled on the server","level":"error","msg":"error setting up DB connection","ts":"2023-03-24T19:42:23.710Z"}
{"caller":"collector.go:138","err":"error pinging pgbouncer: pq: SSL is not enabled on the server","level":"error","msg":"error setting up DB connection","ts":"2023-03-24T19:42:23.829Z"}

I have looked at code. The system try to connect to DB at collector.go:L138 -> Calls Other function on collector.go:L333
and I see this code:
db, err := sql.Open("postgres", conn)

-1:
My question is "why is database name 'postgres' hard-coded"? and not pulled from dsn or connectionString ?
I do not have postgres db in my system. I do not have pgbouncer db as well? I do have bouncer_postgres as alias db.
I did tried the two db names also but it still failed.

-2:
The error issue is it telling that SSL is not enabled. However, I do have ?sslmode=disable. Is this some side effect of new TLS work done? I haven't digged into it yet
-3:
I did tried to build the system but one of the go library for logger and flags is not
available in github for v2 version that it tries to build with, and i am not sure if
that is something that is being maintained by one of the developers in this community.
The failure to build out of box means that a lot of developers that would like to contribute cannot.

I hope someone from core team will kindly respond here!
Thanks,

Container with pgbouncer_exporter fails immediately after start with "error setting up DB connection"

Full error text is following:
ts=2024-02-14T13:27:09.475Z caller=collector.go:138 level=error msg="error setting up DB connection" err="error pinging pgbouncer: dial tcp 127.0.0.1:5432: connect: connection refused"
PG bouncer Exporter container is configured like that:

pgbouncer-exporter:
    image: prometheuscommunity/pgbouncer-exporter
    env_file: .env
    depends_on:
      - db
    expose:
      - "9127"
    command: --pgBouncer.connectionString=${PGBOUNCER_EXPORTER_CONNECTION_STRING}
    deploy:
      placement:
        max_replicas_per_node: 1
        constraints:
          - "node.role == manager"
    networks:
      - backend

Where PGBOUNCER_EXPORTER_CONNECTION_STRING is like that:
postgres://user:password@db:5432/pgbouncer?sslmode=disable

As I understand pgbouncer for some reason is trying to connect on 127.0.0.1 even though it should connect to db through docker network. What should I do to fix that?

Add process metrics

Getting the process metrics from pgbouncer would be useful, similar to how the haproxy_exporter gathers process metrics via a PID file argument. This is useful for pgbouncer as it's single-threaded. This would eliminate the need for a separate process exporter.

More documentation would be nice

Unfortunately I couldn't find any documentation for this project, official docker image also don't provide any starter guide, so I think some documentation or starte guide\instalation instructions may be in README would be helpful.

QUESTION: error pinging pgbouncer

Hi,

Would you be so kind to advise how the connection string in pgbouncer_exporter works?

      --pgBouncer.connectionString="postgres://postgres:@localhost:6543/pgbouncer?sslmode=disable"  
                               Connection string for accessing pgBouncer.

For example, using the psql client to connect to the local pgbouncer instance

> psql --host=127.0.0.1 --port=6432 --dbname=pgbouncer --username=xxx
psql:/home/app/.psqlrc:1: NOTICE:  SET ignored
Timing is on.
Pager is always used.
Null display is "NULL".
psql (12.5, server 1.15.0/bouncer)
Type "help" for help.

[email protected]:6432 pgbouncer# \q

it succeeds.

Trying to do the same using pgbouncer_exporter results to an error

> /usr/local/sbin/pgbouncer_exporter --pgBouncer.connectionString="postgres://xxx:[email protected]:6432/pgbouncer?sslmode=disable"
level=error ts=2021-04-05T13:02:12.688Z caller=collector.go:129 msg="error setting up DB connection" err="error pinging pgbouncer: \"pq: unsupported startup parameter: extra_float_digits\""

Can you please advise?

collected metric XXX was collected before with the same name and label values

I am trying to set up monitoring for Yandex Odyssey and getting these errors:

An error has occurred while serving metrics:

5 error(s) occurred:
* collected metric "pgbouncer_databases_pool_size" { label:<name:"database" value:"fastcup" > label:<name:"force_user" value:"" > label:<name:"host" value:"127.0.0.1" > label:<name:"name" value:"fastcup" > label:<name:"pool_mode" value:"transaction" > label:<name:"port" value:"5432" > gauge:<value:100 > } was collected before with the same name and label values
* collected metric "pgbouncer_databases_max_connections" { label:<name:"database" value:"fastcup" > label:<name:"force_user" value:"" > label:<name:"host" value:"127.0.0.1" > label:<name:"name" value:"fastcup" > label:<name:"pool_mode" value:"transaction" > label:<name:"port" value:"5432" > gauge:<value:0 > } was collected before with the same name and label values
* collected metric "pgbouncer_databases_current_connections" { label:<name:"database" value:"fastcup" > label:<name:"force_user" value:"" > label:<name:"host" value:"127.0.0.1" > label:<name:"name" value:"fastcup" > label:<name:"pool_mode" value:"transaction" > label:<name:"port" value:"5432" > gauge:<value:3 > } was collected before with the same name and label values
* collected metric "pgbouncer_databases_paused" { label:<name:"database" value:"fastcup" > label:<name:"force_user" value:"" > label:<name:"host" value:"127.0.0.1" > label:<name:"name" value:"fastcup" > label:<name:"pool_mode" value:"transaction" > label:<name:"port" value:"5432" > gauge:<value:0 > } was collected before with the same name and label values
* collected metric "pgbouncer_databases_disabled" { label:<name:"database" value:"fastcup" > label:<name:"force_user" value:"" > label:<name:"host" value:"127.0.0.1" > label:<name:"name" value:"fastcup" > label:<name:"pool_mode" value:"transaction" > label:<name:"port" value:"5432" > gauge:<value:0 > } was collected before with the same name and label values

Support environment variables for credentials

Would it be possible to support environment variables for the exporter's configuration?

I intend to use this exporter with Kubernetes, right now I need to do something like this:

        - name: metrics-exporter
          image: prometheuscommunity/pgbouncer-exporter:v0.7.0
          args:
            - --pgBouncer.connectionString=postgres://pgbouncer:pgbouncer@localhost:5432/pgbouncer
            - --web.listen-address=:9127

It is more ideal to use environment variables as they can be derived from pre configured secrets.

        - name: metrics-exporter
          image: prometheuscommunity/pgbouncer-exporter:v0.7.0
          args:
            - --web.listen-address=:9127
          env:
            - name: PGBOUNCER_CONNECTION_STRING
              valueFrom:
                secretKeyRef:
                  name: pgbouncer-connection-string

This way, the configuration can be safely committed to a Git repo, and the secret can be managed by existing secret management tools within the K8s ecosystem.

about connet to pgbouncer

I don't know whether the connectionstringpointer should connect to pgbouncer or PostgreSQL in the code. I see. Default in the code(“ postgres://postgres: @localhost: 6543 / pgbouncer? Sslmode = disable "), which looks like connecting to Postgres, so should I use pgbouncer's account or Postgres's account

How to correctly specify the connection string

Could you tell me how to correctly specify the connection string if there is a dash in the name of my database. Connection string example:

- --pgBouncer.connectionString=postgres://$(DB_USER):$(DB_PASSWORD)@127.0.0.1:5432/tmp-test-db?sslmode=disable&connect_timeout=10

The error I am getting:

{"caller":"collector.go:129","err":"error pinging pgbouncer: \"pq: unrecognized configuration parameter \\\"stats\\\"\"","level":"error","msg":"error setting up DB connection","ts":"2022-05-10T19:56:15.348Z"}

Or I can't use the current database and I need to create a new one? Could you please helm me? Thanks

Regression of config metrics

PR: #93

Original comment: #93 (comment)

Dear @SuperQ and @kenneth-duffel I have been using pgbouncer_exporter for ages. I have just rebuilt it from master branch and I see in the logs:

{"caller":"collector.go:474","err":"error retrieving columns list from SHOW CONFIG:  <nil>\n","level":"error","msg":"error getting SHOW CONFIG","ts":"2023-01-26T18:51:11.176Z"}

I have PgBouncer 1.17.0 where I have more than 3 colums:

pgbouncer=# SHOW CONFIG;
            key            |                         value                         |                        default                         | changeable
---------------------------+-------------------------------------------------------+--------------------------------------------------------+------------

It should be at least 3, or do I miss something?

columnNames, err := rows.Columns()
if err != nil || len(columnNames) != 3 {
return errors.New(fmt.Sprintln("error retrieving columns list from SHOW CONFIG: ", err))
}

UPDATE: I found it, so the code expects these 3 columns in this order but I have default column as well before the changeabl value

var key string
var values sql.RawBytes
var changeable string

Based on the documentation (https://www.pgbouncer.org/usage.html) there are 4 columns:

SHOW CONFIG
Show the current configuration settings, one per row, with the following columns:

key
  Configuration variable name
value
  Configuration value
default
  Configuration default value
changeable
  Either yes or no, shows if the variable can be changed while running. If no, the variable can be changed only at boot time. 
Use SET to change a variable at run time.

Trying to install the binary getting following error

build github.com/prometheus-community/pgbouncer_exporter: cannot load io/fs: malformed module path "io/fs": missing dot in first path element
!! command failed: build -o /home/anmol_pandey/pgbouncer_exporter/pgbouncer_exporter -ldflags -X github.com/prometheus/common/version.Version=0.6.0 -X github.com/prometheus/common/version.Revision=8f44003fd8b0f2f13d49f11e256acd0596317c1d -X github.com/prometheus/common/version.Branch=master -X github.com/prometheus/common/version.BuildUser=anmol_pandey@dukaan-staging-db -X github.com/prometheus/common/version.BuildDate=20230502-08:00:00 -extldflags '-static' -a -tags 'netgo static_build' github.com/prometheus-community/pgbouncer_exporter: exit status 1
make: *** [Makefile.common:198: common-build] Error 1

OS: ubuntu 20.04

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.