Skip to content

Commit

Permalink
add postgREST to pgUI backend (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChuckHend authored Feb 14, 2023
1 parent afdf4a3 commit aff5fc3
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 49 deletions.
35 changes: 24 additions & 11 deletions pgUI/pgDagger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,39 @@ A metrics collector-aggregator for Postgres

## Usage


Start the stack:

```
```bash
docker compose up
```

Connect to Dagger's Postgres:
## Query via REST

```psql
```bash
curl http://localhost:3001/pg_locks_count
```

psql postgres://postgres:postgres@localhost:5433/postgres
```json
[
{"time":"2023-02-14T17:55:09.634+00:00","value":1,"series_id":743},
{"time":"2023-02-14T17:55:09.634+00:00","value":0,"series_id":745},
{"time":"2023-02-14T17:55:09.634+00:00","value":0,"series_id":746},
{"time":"2023-02-14T17:55:09.634+00:00","value":0,"series_id":748}
]
```

Connect to the UI's backend postgres:

```psql
psql postgres://postgres:postgres@localhost:5432/postgres
```

Query Postgres:

```sql
select time, value, jsonb(labels) as labels
from prom_metric.pg_stat_activity_count psac
limit 1
from prom_metric.pg_locks_count psac
limit 1;
```

<table>
Expand All @@ -32,18 +45,18 @@ limit 1
</tr>
<tr>
<td> 2023-02-08 23:34:31.394+00 </td>
<td> 1 </td>
<td> 0 </td>
<td>

```json
{
"job": "metrics_exporter",
"mode": "accessexclusivelock",
"group": "postgres",
"state": "active",
"server": "arbitrary_postgres:5432",
"server": "arbitrary_postgres:5433",
"datname": "postgres",
"monitor": "pgDagger-prometheus",
"__name__": "pg_stat_activity_count",
"__name__": "pg_locks_count",
"instance": "metrics_exporter:9187"
}
```
Expand Down
73 changes: 36 additions & 37 deletions pgUI/pgDagger/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,68 @@
version: "3.5"
services:
postgres_dagger:
restart: always
rest:
image: postgrest/postgrest:v10.0.0
restart: unless-stopped
ports:
- 3001:3000
environment:
PGRST_DB_URI: postgres://postgres:postgres@timescaledb:5432/postgres
PGRST_DB_SCHEMA: prom_data
PGRST_DB_ANON_ROLE: postgres
depends_on:
- timescaledb

timescaledb:
image: timescale/timescaledb-ha:pg14-latest
restart: on-failure
ports:
- 5433:5433/tcp
- 5432:5432/tcp
volumes:
- timescaledb-data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
TSTUNE_PROFILE: promscale
command: -p 5433
POSTGRES_DB: postgres
POSTGRES_HOST_AUTH_METHOD: trust

metrics_exporter:
restart: always
image: quay.io/prometheuscommunity/postgres-exporter
image: quay.io/prometheuscommunity/postgres-exporter:v0.11.1
ports:
- 9187:9187
environment:
DATA_SOURCE_NAME: postgresql://postgres:postgres@arbitrary_postgres:5432/postgres?sslmode=disable
DATA_SOURCE_NAME: postgresql://postgres:postgres@arbitrary_postgres:5433/postgres?sslmode=disable

prometheus:
restart: always
image: prom/prometheus:v2.42.0
restart: on-failure
depends_on:
- promscale
volumes:
- ./prometheus/:/etc/prometheus/
# - prometheus_data:/prometheus
command:
- "--config.file=/etc/prometheus/config/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
- "--storage.tsdb.retention=1d" # This is retention.time in future versions of prometheus
- "--web.external-url="
- "--web.enable-admin-api"
- "--web.enable-lifecycle"
- "--query.max-concurrency=400"
- promscale
ports:
- 9090:9090
- 9090:9090/tcp
volumes:
- ${PWD}/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml

promscale:
image: timescale/promscale:0.17
image: timescale/promscale:0.17.0
restart: on-failure
ports:
- 9201:9201/tcp
- 9202:9202/tcp
restart: on-failure
depends_on:
- postgres_dagger
# volumes:
# - ${PWD}/promscale_prometheus.yml:/prometheus.yml
# - ${PWD}/rules.yml:/rules.yml
# - ${PWD}/alerts.yml:/alerts.yml
- timescaledb
environment:
PROMSCALE_DB_URI: postgres://postgres:postgres@postgres_dagger:5433/postgres?sslmode=allow
# PROMSCALE_TRACING_OTLP_SERVER_ADDRESS: ":9202"
# PROMSCALE_TELEMETRY_TRACE_OTEL_ENDPOINT: "otel-collector:4317"
# PROMSCALE_TELEMETRY_TRACE_SAMPLING_RATIO: "0.1"
# PROMSCALE_METRICS_RULES_CONFIG_FILE: /prometheus.yml
PROMSCALE_DB_URI: postgres://postgres:postgres@timescaledb:5432/postgres?sslmode=allow

arbitrary_postgres:
restart: always
image: postgres
image: postgres:15.2
ports:
- 5432:5432
- 5433:5433
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
command: -p 5433

volumes:
timescaledb-data:
11 changes: 10 additions & 1 deletion pgUI/pgDagger/prometheus/config/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ scrape_configs:
labels:
group: 'postgres'

# alerting:
- job_name: promscale
static_configs:
- targets: ['promscale:9201']

# alerting:docker
# alertmanagers:
# - scheme: http
# static_configs:
Expand All @@ -41,6 +45,11 @@ scrape_configs:

remote_write:
- url: "http://promscale:9201/write"
remote_timeout: 100s
queue_config:
max_samples_per_send: 10000


remote_read:
- url: "http://promscale:9201/read"
read_recent: true

0 comments on commit aff5fc3

Please sign in to comment.