Giter VIP home page Giter VIP logo

pgbouncer-healthcheck's Introduction

PGBouncer healthcheck

Introduction

This implements a http /health check for PGBouncer hosts. This healthcheck provides a simple yes/no health response based on attempting to connect to PGBouncer and execute a request, as well as checking the Datadog agent.

There are also several endpoints used for diagnostics.

Building and running

This can be built on a local system with docker using the provided Makefile.

$ make build

You can then run the server binary

$ ./pgbouncer-healthcheck

Configuration

The binary takes its configuration from several environment variables.

Postgres connection string for PGBouncer connection

The connection string comes from the env var CONNSTR. The default is host=localhost port=6543 dbname=pgbouncer sslmode=disable. This should be fine for most use cases.

The intention is that the username and password will be supplied by setting the PGUSER and PGPASSWORD standard variables.

Other parameters

  • PORT: The TCP port the daemon should use to listen for HTTP connections (default: 8000)
  • ENHANCED_CHECK: If true, test the PGBouncer health by connecting and sending a query. If false, use a simple port probe. (default: false)
  • CHECK_DDAGENT: If true, the /health endpoint will also run datadog-agent health and the return value will affect the health status (default: false)
  • PGBOUNCER_PORT: The TCP port used if using the basic port probe healthcheck (default: 6543)
  • ENABLE_DEBUG_ENDPOINTS: If true, the extra /debug/ endpoints will be enabled. See below (default: false)

The result of the defaults is that the standard mode is just to do a TCP port probe of 6543 on the localhost to test if PGBouncer is alive.

Main Endpoints

Note: See https://pgbouncer.github.io/usage.html for details of the PGBouncer SHOW command outputs.

/

This always returns a 200 OK

/health

The healthcheck returns a 200 OK response or a 500 Internal Server Error response. It will probe the PGBouncer using a method depending on ENHANCED_CHECK. If CHECK_DDAGENT is true it will also check the Datadog Agent.

PGBouncer Information Endpoints

/status/users

Returns the results of PGBouncer's SHOW USERS command formatted as JSON.

Example:

[
  {
    "Name": "dd-agent",
    "PoolMode": null
  },
  {
    "Name": "jasoirwjofjdsslkmcknmwofn",
    "PoolMode": null
  },
  {
    "Name": "pgbouncer",
    "PoolMode": null
  },
  {
    "Name": "sidekiq_realtime",
    "PoolMode": null
  }
]

/status/configs

Returns the results of PGBouncer's SHOW CONFIG command formatted as JSON.

Example:

[
  {
    "Key": "job_name",
    "Value": "pgbouncer",
    "Changeable": false
  },
  {
    "Key": "conffile",
    "Value": "/etc/pgbouncer/pgbouncer.ini",
    "Changeable": true
  },
  {
    "Key": "logfile",
    "Value": "",
    "Changeable": true
  },
  {
    "Key": "pidfile",
    "Value": "/var/run/postgresql/pgbouncer.pid",
    "Changeable": false
  },
  {
    "Key": "listen_addr",
    "Value": "0.0.0.0",
    "Changeable": false
  },
  {
    "Key": "listen_port",
    "Value": "6543",
    "Changeable": false
  }
]

(Truncated for brevity)

/status/databases

Returns the results of PGBouncer's SHOW DATABASES command formatted as JSON. This is essentially the content of the [databases] section in the config file.

Example:

[
  {
    "Name": "delivery_prod",
    "Host": "roo-prod-96.example.eu-west-1.rds.amazonaws.com",
    "Port": "12345",
    "Database": "prod",
    "ForceUser": null,
    "PoolSize": 100,
    "ReservePool": 1,
    "PoolMode": null,
    "MaxConnections": 0,
    "CurrentConnections": 0
  },
  {
    "Name": "delivery_prod_read1",
    "Host": "roo-prod-96-read1.example.eu-west-1.rds.amazonaws.com",
    "Port": "12345",
    "Database": "prod",
    "ForceUser": null,
    "PoolSize": 100,
    "ReservePool": 1,
    "PoolMode": null,
    "MaxConnections": 0,
    "CurrentConnections": 0
  }
]

/status/pools

Returns the results of PGBouncer's SHOW POOLS command formatted as JSON. This is similar to SHOW DATABASES, except it's a product of that set by the users, since the pooling is per user per logical DB.

Example:

[
  {
    "Database": "prod_read1_web",
    "User": "kldfwokoekrokerkreo",
    "ClActive": 459,
    "ClWaiting": 0,
    "SvActive": 2,
    "SvIdle": 5,
    "SvUsed": 0,
    "SvTested": 0,
    "SvLogin": 0,
    "MaxWait": 0,
    "PoolMode": "transaction"
  },
  {
    "Database": "prod_read1_worker",
    "User": "kldfwokoekrokerkreo",
    "ClActive": 127,
    "ClWaiting": 0,
    "SvActive": 0,
    "SvIdle": 4,
    "SvUsed": 0,
    "SvTested": 0,
    "SvLogin": 0,
    "MaxWait": 0,
    "PoolMode": "transaction"
  }
]

/status/clients

Returns the results of PGBouncer's SHOW CLIENTS command formatted as JSON.

Example:

  {
    "Type": "C",
    "User": "kldfwokoekrokerkreo",
    "Database": "prod_read1_web",
    "State": "active",
    "Addr": "10.0.129.60",
    "Port": 50962,
    "LocalAddr": "10.0.78.178",
    "LocalPort": 6543,
    "ConnectTime": "2018-11-05 08:18:34",
    "RequestTime": "2018-11-05 10:51:22",
    "Ptr": "0x55fb15292a18",
    "Link": "",
    "RemotePid": 0,
    "TLS": ""
  },
  {
    "Type": "C",
    "User": "kldfwokoekrokerkreo",
    "Database": "prod_read1_web",
    "State": "active",
    "Addr": "10.0.69.98",
    "Port": 39750,
    "LocalAddr": "10.0.78.178",
    "LocalPort": 6543,
    "ConnectTime": "2018-11-05 08:53:58",
    "RequestTime": "2018-11-05 10:18:28",
    "Ptr": "0x7f7159b2a420",
    "Link": "",
    "RemotePid": 0,
    "TLS": ""
  }
]

/status/servers

Returns the results of PGBouncer's SHOW SERVERS command formatted as JSON.

Example:

[
  {
    "Type": "S",
    "User": "kldfwokoekrokerkreo",
    "Database": "prod_read1_web",
    "State": "idle",
    "Addr": "34.254.85.1",
    "Port": 31872,
    "LocalAddr": "10.0.78.178",
    "LocalPort": 45492,
    "ConnectTime": "2018-11-05 12:03:12",
    "RequestTime": "2018-11-05 12:10:12",
    "Ptr": "0x55fb15589028",
    "Link": "",
    "RemotePid": 64451,
    "TLS": "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1"
  },
  {
    "Type": "S",
    "User": "kldfwokoekrokerkreo",
    "Database": "prod_read1_web",
    "State": "idle",
    "Addr": "34.254.85.1",
    "Port": 31872,
    "LocalAddr": "10.0.78.178",
    "LocalPort": 44966,
    "ConnectTime": "2018-11-05 11:43:18",
    "RequestTime": "2018-11-05 12:10:12",
    "Ptr": "0x55fb159663e0",
    "Link": "",
    "RemotePid": 57603,
    "TLS": "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1"
  }
]

/status/mems

Returns the results of PGBouncer's SHOW MEM command formatted as JSON.

Example:

[
  {
    "Name": "user_cache",
    "Size": 200,
    "Used": 5,
    "Free": 76,
    "MemTotal": 16200
  },
  {
    "Name": "db_cache",
    "Size": 208,
    "Used": 21,
    "Free": 57,
    "MemTotal": 16224
  },
  {
    "Name": "pool_cache",
    "Size": 408,
    "Used": 11,
    "Free": 39,
    "MemTotal": 20400
  },
  {
    "Name": "server_cache",
    "Size": 392,
    "Used": 78,
    "Free": 322,
    "MemTotal": 156800
  },
  {
    "Name": "client_cache",
    "Size": 392,
    "Used": 2708,
    "Free": 10092,
    "MemTotal": 5017600
  },
  {
    "Name": "iobuf_cache",
    "Size": 4112,
    "Used": 3,
    "Free": 797,
    "MemTotal": 3289600
  }
]

/status/stats

Returns the results of PGBouncer's SHOW STATS command formatted as JSON.

Example:

[
  {
    "Database": "pgbouncer",
    "TotalRequests": 16,
    "TotalReceived": 0,
    "TotalSent": 0,
    "TotalQueryTime": 0,
    "AvgReq": 0,
    "AvgRecv": 0,
    "AvgSent": 0,
    "AvgQuery": 0
  }
]

Server Debug Endpoints

These were added to help debug unreachable servers. You need to start the binary with ENABLE_DEBUG_ENDPOINTS=1 to make the available.

/debug/dmesg

Returns the raw output of dmesg

/debug/processes

Returns the raw output of ps -eo user,pid,ppid,c,stime,tty,%cpu,%mem,vsz,rsz,cmd

/debug/meminfo

Returns the contents of /proc/meminfo.

/debug/logs

Returns the output of journalctl --reverse -b --no-pager -n 50

pgbouncer-healthcheck's People

Contributors

bikochan avatar cyrinenajar avatar fergalhk avatar jphastings avatar nikhilnilawar-deliveroo avatar sljory avatar

Stargazers

 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  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

pgbouncer-healthcheck's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • chore(deps): update deliveroo/circleci docker tag to v0.8.5
  • chore(deps): update golang docker tag to v1.22.6
  • chore(deps): update actions/checkout action to v4
  • chore(deps): update deliveroo/circleci docker tag to v4
  • chore(deps): update github/codeql-action action to v3
  • ๐Ÿ” Create all pending approval PRs at once ๐Ÿ”

Detected dependencies

circleci
.circleci/config.yml
  • deliveroo/circleci 0.4.2
dockerfile
Dockerfile
  • golang 1.10.2-alpine
github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v3
  • github/codeql-action v2
  • github/codeql-action v2
  • github/codeql-action v2
regex
.circleci/config.yml
  • deliveroo/circleci 0.4.2

  • Check this box to trigger a request for Renovate to run again on this repository

Create build packages

Currently this project requires go build tools and make be installed on a server to compile a go binary for deployment.

It would be nice to have circle-ci / github-actions / travis-ci build these packages and store them as a github release.

Ideally to install this program, users could just add a debian or yum repo, then install the package

add-apt-repository foo/pgbouncer-healthcheck
apt install pgbouncer-healthcheck

or

wget github.com/deliveroo/pgbouncer-healthcheck/releases/v0.0.1/pgbrouncer-healthcheck_0.0.1_amd64.deb
dpkg -i pgbouncer-healthcheck_0.0.1_amd64.deb

I'm willing to help bulid these packages but would first like to get some guidance on which direction you would like to go:

  1. Is there interest in adding pre-build packages?
  2. What CI system is preferred?

Endpoints show errors

/app # curl http://pgbouncer-healthchecker.default.svc.cluster.local/status/stats
An error occured: Error fetching stats from PGBouncer: Failed to fetch row from results: sql: expected 15 destination arguments in Scan, not 9

Error appears on sending GET request to the above point.

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.