Skip to content
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

Using PostgresDB as a DataSource #548

Open
the-jan-peter opened this issue Nov 17, 2022 · 4 comments
Open

Using PostgresDB as a DataSource #548

the-jan-peter opened this issue Nov 17, 2022 · 4 comments

Comments

@the-jan-peter
Copy link

I was wondering if and how to use PostgresDB as a datasource.

Any hints would be highly welcomed.

@JamesGibo
Copy link
Collaborator

Have you got any exisiting dashboards that use the PostgresDB datasource?
If so please could you download the JSON and share this? I am only interested in the part where the datasource and query are defined as I can use this to compare to the formatting used in grafanalib.

@the-jan-peter
Copy link
Author

Aweseomly quick response!

I created a demo dashboard and copied the dashboard json from the dashboard settings:

{ "annotations": { "list": [ { "builtIn": 1, "datasource": "-- Grafana --", "enable": true, "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "target": { "limit": 100, "matchAny": false, "tags": [], "type": "dashboard" }, "type": "dashboard" } ] }, "editable": true, "fiscalYearStartMonth": 0, "gnetId": null, "graphTooltip": 0, "id": 5, "links": [], "liveNow": false, "panels": [ { "datasource": null, "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "custom": { "align": "auto", "displayMode": "auto" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 80 } ] } }, "overrides": [] }, "gridPos": { "h": 9, "w": 12, "x": 0, "y": 0 }, "id": 2, "options": { "showHeader": true }, "pluginVersion": "8.2.6", "targets": [ { "format": "table", "group": [], "metricColumn": "none", "rawQuery": true, "rawSql": "SELECT *\nFROM\n account", "refId": "A", "select": [ [ { "params": [ "value" ], "type": "column" } ] ], "timeColumn": "time", "where": [ { "name": "$__timeFilter", "params": [], "type": "macro" } ] } ], "title": "account - table", "type": "table" } ], "schemaVersion": 32, "style": "dark", "tags": [], "templating": { "list": [] }, "time": { "from": "now-6h", "to": "now" }, "timepicker": {}, "timezone": "", "title": "New dashboard", "uid": "Y8a7onO4z", "version": 2 }

@JamesGibo
Copy link
Collaborator

JamesGibo commented Nov 17, 2022

It looks like a new datasource needs to be added for PostgresDB, is this something you would be able to create a PR for?

A new class need to be added to add the PostgresDB target to replicate the following JSON data from your example.
The InfluxDB datasource could be used as a template.
https://github.com/weaveworks/grafanalib/blob/main/grafanalib/influxdb.py

{
      "format": "table",
      "group": [],
      "metricColumn": "none",
      "rawQuery": true,
      "rawSql": "SELECT *\nFROM\n account",
      "refId": "A",
      "select": [
          [
              {
                  "params": [
                      "value"
                  ],
                  "type": "column"
              }
          ]
      ],
      "timeColumn": "time",
      "where": [
          {
              "name": "$__timeFilter",
              "params": [],
              "type": "macro"
          }
      ]
}

@the-jan-peter
Copy link
Author

No, I sadly do not fee capable of providing the PR.

I can test the implementation, though

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

No branches or pull requests

2 participants