如何在Grafana中将OpenSearch/ElasticSearch SQL插件配置为数据源?

huangapple go评论64阅读模式
英文:

How to configure OpenSearch/ElasticSearch SQL plug-in as a datasource in Grafana?

问题

OpenSearch(或ElasticSearch)有一个SQL插件,可以通过/_plugins/_sql URL访问。

我可以使用以下查询在ES仪表板上运行SQL查询:

POST /_plugins/_sql
{
  "query": "SELECT test_name,sum(run-time) FROM test_metrics GROUP BY test_name"
}

我正在尝试找出如何将此SQL插件添加为Grafana中的数据源,以便可以通过Grafana运行类似的查询。

英文:

OpenSearch (or ElasticSearch) has a SQL plug-in that is accessible via /_plugins/_sql URL.

I can run a SQL Query on the ES Dashboard using a query like this:

POST /_plugins/_sql
{
  "query": "SELECT test_name,sum(run-time) FROM test_metrics GROUP BY test_name"
}

I'm trying to figure out how can I add this SQL plug-in as a datasource in Grafana so that I can run a similar query via Grafana?

答案1

得分: 2

只有POST请求,因此任何可以进行POST请求的插件都可以实现这一点,例如marcusolsson-json-datasourceyesoreyeram-infinity-datasource。当然,您需要设置适当的身份验证标头和合适的输出格式(JSON)。

英文:

It is only POST request, so any plugin, which can make a POST request can do that: e.g. marcusolsson-json-datasource, yesoreyeram-infinity-datasource. Of course you will need to set proper header for authentication and suitable output format (json).

答案2

得分: 1

感谢@Jan Garaj提供的指引,我成功找到了一个适用于此目的的插件。

  1. 安装grafana-infinity-datasource插件
  2. 如果适用,配置您的身份验证设置
  3. 使用以下设置配置您的数据源
    • 类型:JSON
    • 解析器:后端
    • 源:URL
      • URL:<OPENSEARCH_SERVICE_IP>/_plugin/_sql
  4. 使用以下设置配置您的URL选项
    • HTTP方法:POST
    • 正文类型:原始
      • 正文内容类型:JSON
      • 正文内容:<SQL查询>
        • 例如:{ &quot;query&quot;: &quot;SELECT * FROM ES_DATA_INDEX_NAME }
  5. 配置解析选项以映射您的数据
    • 解析选项和结果字段:datarows
    • 列:将字段(按顺序)映射到所需的列名
      • 例如:选择器0 作为时间
英文:

Thanks for @Jan Garaj for the pointer, I was able to find a plugin that works for this purpose.

  1. Install grafana-infinity-datasource plugin
  2. Configure your authentication settings if applicable
  3. Use these settings to configure your datasource
    • Type: JSON
    • Parser: Backend
    • Source: URL
      • URL: &lt;OPENSEARCH_SERVICE_IP&gt;/_plugin/_sql
  4. Use these for your URL Options
    • HTTP Method: POST
    • Body Type: Raw
      • Body Content Type: JSON
      • Body Content: <SQL QUERY>
        • e.g. { &quot;query&quot;: &quot;SELECT * FROM ES_DATA_INDEX_NAME }
  5. Configure your parsing options to map your data
    • Parsing options & Result fields: datarows
    • Columns: Map your fields (in order) to desired column-names
      • e.g. Selector: 0 as: time

huangapple
  • 本文由 发表于 2023年2月23日 22:27:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546158.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定