Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Add support for influxdb datasource #33

Closed
StefanSa opened this issue Dec 8, 2018 · 12 comments
Closed

Add support for influxdb datasource #33

StefanSa opened this issue Dec 8, 2018 · 12 comments
Labels
enhancement New feature or request
Milestone

Comments

@StefanSa
Copy link

StefanSa commented Dec 8, 2018

Thanks for the interesting plugin.
I would also like to use it, but as datasource i have influxdb.
Is there a chance that influxdb will be supported?

@dmgtn dmgtn changed the title Future request, datasource influxdb Add support for influxdb datasource Dec 10, 2018
@dmgtn
Copy link
Member

dmgtn commented Dec 10, 2018

@StefanSa, we are not using InfluxDB on a daily basis, so probably it's not in our nearest roadmap. Of course, we are open for contribution, and we'll be happy to help with PR.

@voiprodrigo
Copy link

I may be interested in tackling this, time permitting.

Any pointers from the developers on the approach to follow? Never developed for Grafana..

Sent with GitHawk

@diafour
Copy link
Collaborator

diafour commented Dec 10, 2018

@voiprodrigo There is an inconsistence between datasource results. Panel plugin has handler for 'data-received' event: https://github.com/flant/grafana-statusmap/blob/master/src/status_heatmap_ctrl.js#L132
Datasource plugin generate a result array and this result is passed as payload of 'data-received' event. The inconsistence is between result structures. Prometheus datasource returns a structure like this:

data = [
{
  target: <target_field_value_from_matrecis_tab>,
  datapoints: [
  [1, 1544462491],
  [1, 1544462496],
  [0, 1544462511],
  ...
  ]  },
{target, datapoints},
{target, datapoints},
...
]

So, each datapoint has timestamp in item with index 1 and value in item with index 0. InfluxDB and Graphite datasources can use another indices — this fact should be discovered and handled in convertToCards method. Index for timestamp is used here: https://github.com/flant/grafana-statusmap/blob/master/src/status_heatmap_ctrl.js#L323
May be something has changed and I am wrong and indices for timestamp and value are the same for all datasources — in this case statusmap-panel should "just work" with InfluxDB and Graphite.

@voiprodrigo
Copy link

voiprodrigo commented Dec 10, 2018

@diafour thanks, this info should be very helpful.

But I just tested on Grafana 5.4.0 and.. it actually seems to be working!

@dmgtn
Copy link
Member

dmgtn commented Dec 11, 2018

So what, we just have to add info to the README about InfluxDB support and close this ticket?

@voiprodrigo, can you confirm, that plugin is working with InfluxDB?

@voiprodrigo
Copy link

Well, I did not test extensively. But I added a query on top of a suitable measurement, used the value to text mapping feature also, and that gave the expected result. From that experience, it’s working.

Sent with GitHawk

@diafour diafour added this to the 0.1.0 milestone Feb 14, 2019
@diafour
Copy link
Collaborator

diafour commented Feb 14, 2019

I should finally test it and fix a README.

@diafour diafour added the enhancement New feature or request label Feb 14, 2019
@konstantinblaesi
Copy link

konstantinblaesi commented Feb 21, 2019

I am confused whether this can work with InfluxDB or not. https://github.com/flant/grafana-statusmap#prometheus says we should set up discrete values , but this InfluxDB ticket sounds as if such a query is not supported by InfluxDB ? I can only add WHERE clauses for tags in my InfluxDB database. This is also the reason why I didn't map my status strings to numbers. Maybe I should make my Status column a tag in InfluxDB?

pv
pv2

As you can see in my InfluxDB response every inverters last status is Warten , but these are not shown in the visualization?

InfluxDB request/response as JSON (click to expand)

{
  "xhrStatus": "complete",
  "request": {
    "method": "GET",
    "url": "api/datasources/proxy/4/query",
    "params": {
      "db": "yasdi_logger_db",
      "q": "SELECT \"Status\" FROM \"20years\".\"inverters\" WHERE time >= 1550768073890ms and time <= 1550768427067ms GROUP BY \"type\"",
      "epoch": "ms"
    },
    "data": null,
    "precision": "ms"
  },
  "response": {
    "results": [
      {
        "statement_id": 0,
        "series": [
          {
            "name": "inverters",
            "tags": {
              "type": "WR11E-03"
            },
            "columns": [
              "time",
              "Status"
            ],
            "values": [
              [
                1550768087000,
                "Mpp"
              ],
              [
                1550768107000,
                "Mpp"
              ],
              [
                1550768127000,
                "Mpp"
              ],
              [
                1550768147000,
                "Warten"
              ],
              [
                1550768167000,
                "Netzueb."
              ],
              [
                1550768187000,
                "Warten"
              ],
              [
                1550768207000,
                "Netzueb."
              ],
              [
                1550768227000,
                "Stoer."
              ],
              [
                1550768247000,
                "Stoer."
              ],
              [
                1550768267000,
                "Netzueb."
              ],
              [
                1550768287000,
                "Netzueb."
              ],
              [
                1550768307000,
                "Warten"
              ],
              [
                1550768327000,
                "Warten"
              ],
              [
                1550768347000,
                "Warten"
              ],
              [
                1550768367000,
                "Warten"
              ],
              [
                1550768387000,
                "Warten"
              ],
              [
                1550768407000,
                "Warten"
              ]
            ]
          },
          {
            "name": "inverters",
            "tags": {
              "type": "WR30-002"
            },
            "columns": [
              "time",
              "Status"
            ],
            "values": [
              [
                1550768075000,
                "Mpp"
              ],
              [
                1550768085000,
                "Mpp"
              ],
              [
                1550768095000,
                "Mpp"
              ],
              [
                1550768105000,
                "Mpp"
              ],
              [
                1550768114000,
                "Mpp"
              ],
              [
                1550768125000,
                "Mpp"
              ],
              [
                1550768135000,
                "Mpp"
              ],
              [
                1550768144000,
                "Mpp"
              ],
              [
                1550768155000,
                "Mpp"
              ],
              [
                1550768165000,
                "Mpp"
              ],
              [
                1550768175000,
                "Mpp"
              ],
              [
                1550768185000,
                "Mpp"
              ],
              [
                1550768194000,
                "Mpp"
              ],
              [
                1550768204000,
                "Mpp"
              ],
              [
                1550768214000,
                "Mpp"
              ],
              [
                1550768224000,
                "Mpp"
              ],
              [
                1550768235000,
                "Mpp"
              ],
              [
                1550768245000,
                "Mpp"
              ],
              [
                1550768255000,
                "Mpp"
              ],
              [
                1550768265000,
                "Mpp"
              ],
              [
                1550768275000,
                "Mpp"
              ],
              [
                1550768285000,
                "Warten"
              ],
              [
                1550768295000,
                "Warten"
              ],
              [
                1550768305000,
                "Warten"
              ],
              [
                1550768315000,
                "Warten"
              ],
              [
                1550768325000,
                "Warten"
              ],
              [
                1550768335000,
                "Warten"
              ],
              [
                1550768345000,
                "Warten"
              ],
              [
                1550768355000,
                "Warten"
              ],
              [
                1550768365000,
                "Warten"
              ],
              [
                1550768375000,
                "Warten"
              ],
              [
                1550768385000,
                "Warten"
              ],
              [
                1550768394000,
                "Warten"
              ],
              [
                1550768405000,
                "Warten"
              ],
              [
                1550768415000,
                "Warten"
              ],
              [
                1550768424000,
                "Warten"
              ]
            ]
          },
          {
            "name": "inverters",
            "tags": {
              "type": "WR30-040"
            },
            "columns": [
              "time",
              "Status"
            ],
            "values": [
              [
                1550768077000,
                "Warten"
              ],
              [
                1550768097000,
                "Warten"
              ],
              [
                1550768117000,
                "Warten"
              ],
              [
                1550768137000,
                "Warten"
              ],
              [
                1550768157000,
                "Warten"
              ],
              [
                1550768177000,
                "Warten"
              ],
              [
                1550768197000,
                "Warten"
              ],
              [
                1550768217000,
                "Warten"
              ],
              [
                1550768237000,
                "Warten"
              ],
              [
                1550768257000,
                "Warten"
              ],
              [
                1550768277000,
                "Warten"
              ],
              [
                1550768297000,
                "Warten"
              ],
              [
                1550768317000,
                "Warten"
              ],
              [
                1550768337000,
                "Warten"
              ],
              [
                1550768357000,
                "Warten"
              ],
              [
                1550768377000,
                "Warten"
              ],
              [
                1550768397000,
                "Warten"
              ],
              [
                1550768417000,
                "Warten"
              ]
            ]
          },
          {
            "name": "inverters",
            "tags": {
              "type": "WR30-W03"
            },
            "columns": [
              "time",
              "Status"
            ],
            "values": [
              [
                1550768076000,
                "Mpp"
              ],
              [
                1550768086000,
                "Mpp"
              ],
              [
                1550768096000,
                "Mpp"
              ],
              [
                1550768106000,
                "Mpp"
              ],
              [
                1550768116000,
                "Mpp"
              ],
              [
                1550768126000,
                "Mpp"
              ],
              [
                1550768136000,
                "Mpp"
              ],
              [
                1550768146000,
                "Mpp"
              ],
              [
                1550768156000,
                "Mpp"
              ],
              [
                1550768166000,
                "Mpp"
              ],
              [
                1550768176000,
                "Mpp"
              ],
              [
                1550768186000,
                "Mpp"
              ],
              [
                1550768196000,
                "Mpp"
              ],
              [
                1550768206000,
                "Mpp"
              ],
              [
                1550768216000,
                "Mpp"
              ],
              [
                1550768226000,
                "Mpp"
              ],
              [
                1550768236000,
                "Mpp"
              ],
              [
                1550768246000,
                "Warten"
              ],
              [
                1550768256000,
                "Warten"
              ],
              [
                1550768266000,
                "Warten"
              ],
              [
                1550768276000,
                "Warten"
              ],
              [
                1550768286000,
                "Warten"
              ],
              [
                1550768296000,
                "Warten"
              ],
              [
                1550768306000,
                "Warten"
              ],
              [
                1550768316000,
                "Warten"
              ],
              [
                1550768326000,
                "Warten"
              ],
              [
                1550768336000,
                "Warten"
              ],
              [
                1550768346000,
                "Warten"
              ],
              [
                1550768356000,
                "Warten"
              ],
              [
                1550768366000,
                "Warten"
              ],
              [
                1550768376000,
                "Warten"
              ],
              [
                1550768386000,
                "Warten"
              ],
              [
                1550768396000,
                "Warten"
              ],
              [
                1550768406000,
                "Warten"
              ],
              [
                1550768416000,
                "Warten"
              ],
              [
                1550768426000,
                "Warten"
              ]
            ]
          }
        ]
      }
    ]
  }
}

@diafour
Copy link
Collaborator

diafour commented Feb 26, 2019

I am confused whether this can work with InfluxDB or not. https://github.com/flant/grafana-statusmap#prometheus says we should set up discrete values , but this InfluxDB ticket sounds as if such a query is not supported by InfluxDB ? I can only add WHERE clauses for tags in my InfluxDB database. This is also the reason why I didn't map my status strings to numbers. Maybe I should make my Status column a tag in InfluxDB?
As you can see in my InfluxDB response every inverters last status is Warten , but these are not shown in the visualization?

As i can understand, 7581 is about setups when status pushed into influxdb only when it is changed and it seems as not your case.
We designed plugin with Prometheus in mind and data is handled with assumption that timeseries from different queries has matching timestamps for values and matching count of values.
I can see from your screenshots that timestamps are not matching and "WR30-002" and "WR30-W03" have different count of values than "WR30-040" and "WR11E-03". The small difference in timestamps is rendered quite nicely but render is quite bad in case of difference in values count.
In case of Prometheus this problem is solved by aggregation over interval time period so we get multiple values for one timestamp. I think that InfluxDB has similar aggregations and your json can help.

TODO:

  • add InfluxDB section into README, make and add query with recommended aggregation
  • remove clipping of value count and add a warning div in metrics tab or options tab with message about aggregation
  • think about multi values aggregation by interval in data handling code to nicely render difference in timestamps and values count for data sources without support of aggregation over time period

@diafour
Copy link
Collaborator

diafour commented Mar 5, 2019

@konstantinblaesi your case is fixed by #55 , see screenshots in #53 (comment)

@konstantinblaesi
Copy link

Thanks for fixing this, looks great!

@diafour
Copy link
Collaborator

diafour commented Mar 11, 2019

InfluxDB related information is added in README.
Multi values aggregation is addressed by #53

Close it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants