Skip to content

create a prometheus exporter on a standard http port #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 9, 2022
Merged

create a prometheus exporter on a standard http port #107

merged 12 commits into from
Aug 9, 2022

Conversation

dat2
Copy link
Contributor

@dat2 dat2 commented Aug 3, 2022

This creates a prometheus exporter in process. This was requested in #83.

If you add enable_prometheus_exporter = true to pgcat.toml then you can make a GET request to <pgcat host>:9930/metrics to get a list of metrics.

Here's an example of the prometheus metrics exporter endpoint.

Reference: https://prometheus.io/docs/instrumenting/writing_exporters/

➜  pgcat git:(nickdujay/metric-exports) ✗ http -v :9930/metrics
GET /metrics HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost:9090
User-Agent: HTTPie/3.2.1



HTTP/1.1 200 OK
content-length: 7259
content-type: text/plain; version=0.0.4

# HELP pgcat_sv_idle How many server connections are idle
# TYPE pgcat_sv_idle gauge
pgcat_sv_idle{shard="0",host="127.0.0.1",database="simple_db",role="primary"} 1

# HELP pgcat_avg_recv Average of total_received every 15 seconds
# TYPE pgcat_avg_recv gauge
pgcat_avg_recv{role="primary",shard="0",host="127.0.0.1",database="simple_db"} 3

# HELP pgcat_total_received Number of bytes received from the server
# TYPE pgcat_total_received counter
pgcat_total_received{host="127.0.0.1",shard="0",database="simple_db",role="primary"} 54

# HELP pgcat_avg_wait_time Average of total_wait_time every 15 seconds
# TYPE pgcat_avg_wait_time gauge
pgcat_avg_wait_time{host="127.0.0.1",role="primary",shard="0",database="simple_db"} 1042
#truncated

@dat2 dat2 changed the title [work in progress] expose prometheus metrics on an alternate http port [work in progress] create a prometheus exporter on a separate http port Aug 6, 2022
@dat2 dat2 changed the title [work in progress] create a prometheus exporter on a separate http port create a prometheus exporter on a standard http port Aug 8, 2022
@dat2 dat2 marked this pull request as ready for review August 8, 2022 18:10
Copy link
Contributor

@levkk levkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing, thank you so much!

@levkk levkk merged commit 1b166b4 into postgresml:main Aug 9, 2022
@dat2 dat2 deleted the nickdujay/metric-exports branch August 9, 2022 20:34
jmeagher pushed a commit to jmeagher/pgcat that referenced this pull request Feb 17, 2023
* Prevent clients from sticking to old pools after config update (postgresml#113)

* Re-acquire pool at the beginning of Protocol loop

* Fix query router + add tests for recycling behavior

* create a prometheus exporter on a standard http port (postgresml#107)

* create a hyper server and add option to enable it in config

* move prometheus stuff to its own file; update format

* create metric type and help lookup table

* finish the metric help type map

* switch to a boolean and a standard port

* dont emit unimplemented metrics

* fail if curl returns a non 200

* resolve conflicts

* move log out of config.show and into main

* terminating new line

* upgrade curl

* include unimplemented stats

* Validates pgcat is closed after shutdown python tests (postgresml#116)

* Validates pgcat is closed after shutdown python tests

* Fix pgrep logic

* Moves sigterm step to after cleanup to decouple

* Replace subprocess with os.system for running pgcat

* fix docker compose port allocation for local dev (postgresml#117)

change docker compose port to right prometheus port

* Update CONTRIBUTING.md

* Health check delay (postgresml#118)

* initial commit of server check delay implementation

* fmt

* spelling

* Update name to last_healthcheck and some comments

* Moved server tested stat to after require_healthcheck check

* Make health check delay configurable

* Rename to last_activity

* Fix typo

* Add debug log for healthcheck

* Add address to debug log

* Speed up CI a bit (postgresml#119)

* Sleep for 1s

* use premade image

* quicker

* revert shutdown timeout

* Fix debug log (postgresml#120)

* Make prometheus port configurable (postgresml#121)

* Make prometheus port configurable

* Update circleci config

* Statement timeout + replica imbalance fix (postgresml#122)

* Statement timeout

* send error message too

* Correct error messages

* Fix replica inbalance

* disable stmt timeout by default

* Redundant mark_bad

* revert healthcheck delay

* tests

* set it to 0

* reload config again

* pgcat toml

Co-authored-by: Nicholas Dujay <3258756+dat2@users.noreply.github.com>
Co-authored-by: zainkabani <77307340+zainkabani@users.noreply.github.com>
Co-authored-by: Lev Kokotov <levkk@users.noreply.github.com>
Co-authored-by: Pradeep Chhetri <30620077+chhetripradeep@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants