'How to use the incluxdb1-client library of golang to query the data?

My library is github.com/influxdata/influxdb1-client/v2,and I need to use it to operate the VictoriaMetrics, For example, I need to make the following query:

sort_desc(avg(idc_bandwidth_5m_data_cube_just_idc_bandwidth_kilobits{idc=~"$cluster", isp=~"$isp"}[5m]) by (idc))

What should I do? Or is there another better library to use? Help me!!!

Can you give me a sample code?



Solution 1:[1]

I'm afraid github.com/influxdata/influxdb1-client/v2 can't be used for reading data from VcitoriaMetrics. You need a library which can send PromQL/MetricsQL queries via HTTP and parse responses. I'm not sure if there are a good Golang lib for that. I've heard only about JS lib.

In general, sending queries and parsing responses to VictoriaMetrics or Prometheus is rarely needed. And when needed, it is usually implemented from scratch. Please use the following link as a reference.

You might be also interested in the following issue I'm afraid github.com/influxdata/influxdb1-client/v2 can't be used for reading data from VcitoriaMetrics. You need a library which can send PromQL/MetricsQL queries via HTTP and parse responses. I'm not sure if there are a good Golang lib for that. I've heard only about JS lib.

In general, sending queries and parsing responses to VictoriaMetrics or Prometheus is rarely needed. And when needed, it is usually implemented from scratch. Please use the following link as a reference.

You might be also interested in the following issue https://github.com/VictoriaMetrics/VictoriaMetrics/issues/108

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hagen1778