Giter Club home page Giter Club logo

grafana-plugin's Introduction

Couchbase datasource plugin for Grafana

"Couchbase-powered dashboard"

This is a simple community-supported Grafana datasource plugin that allows querying time series and log data from Couchbase Clusters, inclding Capella clusters.

Installation from sources

Please consult with the ./run.sh script that is used to launch Grafana with the plugin in a Docker container for the latest instructions on building the plugin.

  • Clone this repository
  • In couchbase-datasource directory, run yarn install && yarn build
  • Copy couchbase-datasource directory into your Grafana plugins directory.
  • Set the following environment variables (or edit grafana configuration file according to documentation):
    • "GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS=couchbase-datasource"
    • "GF_PLUGIN_APP_TLS_SKIP_VERIFY_INSECURE=true"
  • Restart grafana
  • Add a new datasource in configuration and configure it with your cluster information.

Usage

The datasource plugin provides two functions for time range filtering:

  • str_time_range(<fieldname>) for filtering on RFC3339 dates
  • time_range(<fieldname>) for filtering on millisecond timestamps

Both functions take the name of the field to be used for filtering. Examples:

select count, time_string from test where str_time_range(time_string)
select count, timestamp from test where time_range(timestamp)

These are pseudo-functions, references to them are replaced with a set of WHERE filters on provided field by the plugin before the query is sent to the cluster.

Development instructions

Add datasources/couchbase.yaml with your datasource configuration:

apiVersion: 1
datasources:
- name: Couchbase
  type: couchbase-datasource
  access: proxy
  jsonData:
    host: <...>
    username: <...>
  secureJsonData:
    password: <...>

Use ./run.sh to start grafana in docker container with following mounts:

    volumes:
    - ./couchbase:/var/lib/grafana/plugins/couchbase
    - ./datasources:/etc/grafana/provisioning/datasources

Open grafana at http://localhost:3000, use admin as both login and password. You don't need to setup a new password after you login despite grafana asking you to do that -- just reload the page.

grafana-plugin's People

Contributors

chedim avatar piyush-jain-cb avatar

Stargazers

Paul Capestany avatar Jeff Lockhart avatar Enes Can Güven avatar  avatar Burak Tahtacı avatar Medine avatar Roi Katz avatar Elio Salvatore avatar Marcus Bowyer avatar beni avatar Marcel Goya avatar

Watchers

Steve Yen avatar Sarath Lakshman avatar Denis Rosa avatar Jeffry Morris avatar Priya Rajagopal avatar  avatar James Cloos avatar Brett Lawson avatar Jack Harper avatar Wayne Siu avatar  avatar Dan Owen avatar Dave Finlay avatar  avatar Adam Fraser avatar Keshav Murthy avatar  avatar  avatar

grafana-plugin's Issues

Query error

I am trying to test this plugin. I have a known working query getting a Capella instance and get "Query error
An error occurred within the plugin"

From Grafana 10

grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.04307168Z level=info msg="Processing query" refId=A EXTRA_VALUE_AT_END="TYPE: "
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.043083305Z level=info msg="Transforming query"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.043090305Z level=info msg="Unmarshalled json" query_string=
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.04309643Z level=info msg="Querying couchbase" query_string=
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.8355075Z level=error msg="Query failed: parsing failure | {"client_context_id":"d27b51f8-0bd2-4ed8-b7b1-80882093ef20","errors":[{"Code":3000,"Message":"syntax error - at end of input"}]}"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.835905416Z level=info msg="Processing query" EXTRA_VALUE_AT_END="TYPE: " refId=B
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.835934708Z level=info msg="Transforming query"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.835958125Z level=info msg="Unmarshalled json" query_string="SELECT d.type, d.value AS temperature, d.timestamp\nFROM bucket._default._default AS d\nWHERE d.type = "temperature";"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:50.83597425Z level=info msg="Querying couchbase" query_string="SELECT d.type, d.value AS temperature, d.timestamp\nFROM bucket._default._default AS d\nWHERE d.type = "temperature";"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:51.121194291Z level=info msg="Query ok"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:51.121320625Z level=error msg="Panic occured: interface conversion: interface {} is nil, not map[string]interface {}"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:51.171300458Z level=error msg="plugin process exited" plugin=/var/lib/grafana/plugins/couchbase-datasource/dist/gpx_couchbase_linux_arm64 id=52 error="exit status 2"
grafana | logger=context userId=1 orgId=1 uname=admin t=2024-03-18T22:23:51.171385916Z level=error msg="Internal server error" error="[plugin.downstreamError] client: failed to query data: Failed to query data: rpc error: code = Unavailable desc = error reading from server: EOF" remote_addr=192.168.65.1 traceID=
grafana | logger=context userId=1 orgId=1 uname=admin t=2024-03-18T22:23:51.171553083Z level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=192.168.65.1 time_ms=1206 duration=1.206653042s size=116 referer="http://localhost:3000/explore?orgId=1&schemaVersion=1" handler=/api/ds/query status_source=downstream
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:23:51.305088375Z level=info msg=Profiler enabled=false
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:12.591475552Z level=info msg="QueryData called" request="&{PluginContext:{OrgID:1 PluginID:couchbase-datasource User:0x4000249380 AppInstanceSettings: DataSourceInstanceSettings:0x40004928f0} Headers:map[http_X-Datasource-Uid:ddg2m972wevpcb http_X-Grafana-Org-Id:1 http_X-Panel-Id:3580] Queries:[{RefID:A QueryType: MaxDataPoints:1587 Interval:2s TimeRange:{From:2024-03-18 21:24:12.576 +0000 UTC To:2024-03-18 22:24:12.576 +0000 UTC} JSON:[123 34 97 110 97 108 121 116 105 99 115 34 58 102 97 108 115 101 44 34 100 97 116 97 115 111 117 114 99 101 34 58 123 34 116 121 112 101 34 58 34 99 111 117 99 104 98 97 115 101 45 100 97 116 97 115 111 117 114 99 101 34 44 34 117 105 100 34 58 34 100 100 103 50 109 57 55 50 119 101 118 112 99 98 34 125 44 34 100 97 116 97 115 111 117 114 99 101 73 100 34 58 51 44 34 105 110 116 101 114 118 97 108 77 115 34 58 50 48 48 48 44 34 109 97 120 68 97 116 97 80 111 105 110 116 115 34 58 49 53 56 55 44 34 113 117 101 114 121 34 58 34 34 44 34 114 101 102 73 100 34 58 34 65 34 125]} {RefID:B QueryType: MaxDataPoints:1587 Interval:2s TimeRange:{From:2024-03-18 21:24:12.576 +0000 UTC To:2024-03-18 22:24:12.576 +0000 UTC} JSON:[123 34 97 110 97 108 121 116 105 99 115 34 58 102 97 108 115 101 44 34 100 97 116 97 115 111 117 114 99 101 34 58 123 34 116 121 112 101 34 58 34 99 111 117 99 104 98 97 115 101 45 100 97 116 97 115 111 117 114 99 101 34 44 34 117 105 100 34 58 34 100 100 103 50 109 57 55 50 119 101 118 112 99 98 34 125 44 34 100 97 116 97 115 111 117 114 99 101 73 100 34 58 51 44 34 105 110 116 101 114 118 97 108 77 115 34 58 50 48 48 48 44 34 107 101 121 34 58 34 81 45 50 53 55 49 97 102 97 101 45 99 57 49 97 45 52 56 101 55 45 98 48 102 101 45 53 49 52 101 51 49 97 57 97 54 52 101 45 49 34 44 34 109 97 120 68 97 116 97 80 111 105 110 116 115 34 58 49 53 56 55 44 34 113 117 101 114 121 34 58 34 83 69 76 69 67 84 32 100 46 116 121 112 101 44 32 100 46 96 118 97 108 117 101 96 32 65 83 32 116 101 109 112 101 114 97 116 117 114 101 44 32 100 46 116 105 109 101 115 116 97 109 112 92 110 70 82 79 77 32 96 98 117 99 107 101 116 96 46 95 100 101 102 97 117 108 116 46 95 100 101 102 97 117 108 116 32 65 83 32 100 92 110 87 72 69 82 69 32 100 46 116 121 112 101 32 61 32 92 34 116 101 109 112 101 114 97 116 117 114 101 92 34 59 34 44 34 114 101 102 73 100 34 58 34 66 34 125]}]}"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:12.591561718Z level=info msg="Processing query" EXTRA_VALUE_AT_END="TYPE: " refId=A
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:12.591602677Z level=info msg="Transforming query"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:12.591623177Z level=info msg="Unmarshalled json" query_string=
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:12.591638802Z level=info msg="Querying couchbase" query_string=
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.221292344Z level=error msg="Query failed: parsing failure | {"client_context_id":"e07a69d4-0a7f-459c-9d91-ae7372336f05","errors":[{"Code":3000,"Message":"syntax error - at end of input"}]}"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.22135776Z level=info msg="Processing query" refId=B EXTRA_VALUE_AT_END="TYPE: "
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.221374594Z level=info msg="Transforming query"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.221396302Z level=info msg="Unmarshalled json" query_string="SELECT d.type, d.value AS temperature, d.timestamp\nFROM bucket._default._default AS d\nWHERE d.type = "temperature";"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.221411469Z level=info msg="Querying couchbase" query_string="SELECT d.type, d.value AS temperature, d.timestamp\nFROM bucket._default._default AS d\nWHERE d.type = "temperature";"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.497325969Z level=info msg="Query ok"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.497424719Z level=error msg="Panic occured: interface conversion: interface {} is nil, not map[string]interface {}"
grafana | logger=context userId=1 orgId=1 uname=admin t=2024-03-18T22:24:13.513623635Z level=error msg="Internal server error" error="[plugin.downstreamError] client: failed to query data: Failed to query data: rpc error: code = Unavailable desc = error reading from server: EOF" remote_addr=192.168.65.1 traceID=
grafana | logger=context userId=1 orgId=1 uname=admin t=2024-03-18T22:24:13.51378751Z level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=192.168.65.1 time_ms=940 duration=940.315959ms size=116 referer="http://localhost:3000/explore?orgId=1&schemaVersion=1" handler=/api/ds/query status_source=downstream
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:13.523647469Z level=error msg="plugin process exited" plugin=/var/lib/grafana/plugins/couchbase-datasource/dist/gpx_couchbase_linux_arm64 id=65 error="exit status 2"
grafana | logger=plugin.couchbase-datasource t=2024-03-18T22:24:14.289486344Z level=info msg=Profiler enabled=false

Plugin unavailable

Hello,
Thank you very much for this work.The repo worked properly. But I could not connect couchbase from grafana. I entered the configuration information in the picture, but I cannot plugin.

The entries I tried instead of the cluster address;
http://0.0.0.0:8091
http://<my_ip_address>:8091

Screenshot from 2022-12-28 11-42-59
Screenshot from 2022-12-28 11-42-27
Screenshot from 2022-12-28 11-33-30

500 error when querying

When querying a Couchbase datasource using the plugin, I consistently get 500 errors for all valid queries (invalid queries give other errors). Using the travel-sample bucket and this query:

SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;

I get this error response:

{
  "request": {
    "url": "api/ds/query?ds_type=couchbase-datasource&requestId=explore_nO3",
    "method": "POST",
    "data": {
      "queries": [
        {
          "refId": "A",
          "datasource": {
            "type": "couchbase-datasource",
            "uid": "P520070B0D602FCEC"
          },
          "query": "SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;",
          "analytics": false,
          "datasourceId": 1,
          "intervalMs": 10000,
          "maxDataPoints": 1834
        }
      ],
      "from": "1704379750156",
      "to": "1704401350156"
    },
    "hideFromInspector": false
  },
  "response": {
    "message": "An error occurred within the plugin",
    "messageId": "plugin.downstreamError",
    "statusCode": 500,
    "traceID": ""
  }
}

These are the Docker logs:

grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278700165Z level=info msg="QueryData called" request="&{PluginContext:{OrgID:1 PluginID:couchbase-datasource User:0xc00027f200 AppInstanceSettings:<nil> DataSourceInstanceSettings:0xc0002cc8f0} Headers:map[http_X-Datasource-Uid:P520070B0D602FCEC http_X-Grafana-Org-Id:1 http_X-Panel-Id:undefined] Queries:[{RefID:A QueryType: MaxDataPoints:1834 Interval:10s TimeRange:{From:2024-01-04 14:40:21.271 +0000 UTC To:2024-01-04 20:40:21.271 +0000 UTC} JSON:[123 34 97 110 97 108 121 116 105 99 115 34 58 102 97 108 115 101 44 34 100 97 116 97 115 111 117 114 99 101 34 58 123 34 116 121 112 101 34 58 34 99 111 117 99 104 98 97 115 101 45 100 97 116 97 115 111 117 114 99 101 34 44 34 117 105 100 34 58 34 80 53 50 48 48 55 48 66 48 68 54 48 50 70 67 69 67 34 125 44 34 100 97 116 97 115 111 117 114 99 101 73 100 34 58 49 44 34 105 110 116 101 114 118 97 108 77 115 34 58 49 48 48 48 48 44 34 109 97 120 68 97 116 97 80 111 105 110 116 115 34 58 49 56 51 52 44 34 113 117 101 114 121 34 58 34 83 69 76 69 67 84 32 114 46 100 97 116 101 32 97 115 32 116 105 109 101 44 32 114 46 99 111 110 116 101 110 116 32 70 82 79 77 32 96 116 114 97 118 101 108 45 115 97 109 112 108 101 96 46 105 110 118 101 110 116 111 114 121 46 104 111 116 101 108 32 104 116 32 85 78 78 69 83 84 32 104 116 46 114 101 118 105 101 119 115 32 114 32 76 73 77 73 84 32 49 48 59 34 44 34 114 101 102 73 100 34 58 34 65 34 125]}]}"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278728374Z level=info msg="Processing query" EXTRA_VALUE_AT_END="TYPE: " refId=A
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278739263Z level=info msg="Transforming query"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278780364Z level=info msg="Unmarshalled json" query_string="SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.278786743Z level=info msg="Querying couchbase" query_string="SELECT r.date as time, r.content FROM `travel-sample`.inventory.hotel ht UNNEST ht.reviews r LIMIT 10;"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.302483244Z level=info msg="Query ok"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.302526914Z level=error msg="Panic occured: interface conversion: interface {} is nil, not map[string]interface {}"
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:21.306679763Z level=error msg="plugin process exited" plugin=/var/lib/grafana/plugins/couchbase-datasource/dist/gpx_couchbase_linux_amd64 id=85 error="exit status 2"
grafana  | logger=context userId=1 orgId=1 uname=admin t=2024-01-04T20:40:21.306745712Z level=error msg="Internal server error" error="[plugin.downstreamError] client: failed to query data: Failed to query data: rpc error: code = Unavailable desc = error reading from server: EOF" remote_addr=172.17.0.1 traceID=
grafana  | logger=context userId=1 orgId=1 uname=admin t=2024-01-04T20:40:21.306785532Z level=error msg="Request Completed" method=POST path=/api/ds/query status=500 remote_addr=172.17.0.1 time_ms=31 duration=31.074951ms size=116 referer="http://localhost:3000/explore?orgId=1&schemaVersion=1" handler=/api/ds/query
grafana  | logger=plugin.couchbase-datasource t=2024-01-04T20:40:22.062647163Z level=info msg=Profiler enabled=false

This is with the latest version of Grafana, v10.2.3.

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.