prometheus-community / postgres_exporter

A PostgreSQL metric exporter for Prometheus
Apache License 2.0
2.82k stars 743 forks source link

Exporter log error "queryNamespaceMappings returned 1 errors" when running custom query #965

Open mg250492 opened 1 year ago

mg250492 commented 1 year ago

What did you do? I have 1 postgres server with multiple databases for multiple services, and I run multiple metrics on all databases, And I want to setup a custom query for specific database.

the query:

    pg_open:
      query: "SELECT status status,count(*) total FROM repository group by status"
      metrics:
        - status:
            usage: "LABEL"
            description: "status"      
        - total:
            usage: "GAUGE"
            description: "total"  

What did you expect to see? To not see error logs from running this query, I want this query to run on 1 database only.

What did you see instead? Under which circumstances? Error logs:

caller=namespace.go:236 level=info err="Error running query on database \"localhost:5432\": pg_open pq: relation \"repository\" does not exist"
caller=postgres_exporter.go:682 level=error err="queryNamespaceMappings returned 1 errors"

Environment

Linux 5.15.0-79-generic x86_64

postgres_exporter, version 0.15.0 (branch: HEAD, revision: 68c176b8833b7580bf847cecf60f8e0ad5923f9a) build user: root@05d0b99bd5f7 build date: 20231108-12:59:10 go version: go1.20.11 platform: linux/amd64 tags: unknown

        - name: DATA_SOURCE_USER
          value: postgres
        - name: DATA_SOURCE_URI
          value: localhost?sslmode=disable
        - name: PG_EXPORTER_EXTEND_QUERY_PATH
          value: /config/queries.yaml
        - name: PG_EXPORTER_AUTO_DISCOVER_DATABASES
          value: 'true'

postgres:13-alpine