Coder Social home page Coder Social logo

influxdb-dashboard-renderer's Introduction

InfluxDB 2.0 Dashboard Renderer

Code that renders (subset of) InfluxDB 2.0 Dashboards as images.

The first goal of the project is to render dashboards that only use a subset of InfluxDB 2.0 functionality as an image.

The longer term goal is to mimic most views and specifics of InfluxDB 2.0 dashboards to also allow rendering more complex dashboards.

Below is an example rendering of an example dashboard:

Example output dashboard

The dashboard rendered with this Python module is shown on the left side of the image.

The right side of the image shows the same dashboard as rendered by the InfluxDB UI.

Getting started

Web server

Run locally without docker:

$ PYTHONPATH=. ./server/server.py

Run locally using docker:

$ docker build -t influxdb-dashboard-renderer-server .
$ docker run -p 5000:5000 influxdb-dashboard-renderer-server

Next, you can invoke the /render endpoint to retrieve a ready to use image in PNG format. Such as:

curl --header "Content-Type: application/json" -X POST \
--data '{
  "url": "(url)",
  "token": "(access token)",
  "org_id": "(organization id)",
  "id": "(dashboard id)",
  "width": 1280,
  "height": 720,
  "dpi": 75
}' http://127.0.0.1:5000/render >image.png

Where (url) is the URL to the InfluxDB - such as https://us-west-2-1.aws.cloud2.influxdata.com for InfluxDB Cloud US West-2 region.

The (access token) should be an all-access token for your organization inside InfluxDB instance, as those are needed to retrieve information about dashboards.

The (organization id) and (dashboard id) as 16-letter hexadecimal identifiers of the organization and dashboard inside InfluxDB. The identifiers can be extracted from the dashboard view URL, where the URL is https://hostname/orgs/(organization id)/dashboards/(dashboard id).

For more information on building and running the included web server functionality, please check the server directory.

Python package and rendering outputs manually

Below is minimal code to use the package on its own:

from influxdb_dashboard import InfluxDBClient, InfluxDBDashboardView, InfluxDBDashboardOutput

TOKEN='(your InfluxDB 2.0 token)'
ORG_ID='(your 16 characters org ID)'
LABEL='(label in InfluxDB 2.0 that has a dashboard associated with it)'

c = InfluxDBClient(url='https://eu-central-1-1.aws.cloud2.influxdata.com', token=TOKEN, org=ORG_ID)
d = InfluxDBDashboardView.find_by_label(c, LABEL)

# optionally set timeRangeStart, timeRangeStop and windowPeriod to show last 30 days, using 15 minute windows
d.set_time_range(start_offset=-(30*24*60), end_offset=0, window_period=15, offset_unit='m')

# render to an image - defaults to 1920x1080 pixels image, but this can be customized
o = InfluxDBDashboardOutput(dpi=150, rows=d.height)
img = o.draw(d)
img.save('./image1.png')

# render a black and white image, using white background instead of default black one ; image is suitable for eink displays
o = InfluxDBDashboardOutput(width=1200, height=825, rows=d.height, dpi=150, mode='bw', dark=False)
img = o.draw(d)
img.save('./image-eink.png')

What is currently working

  • Basic Flux queries
  • Queries that require v.timeRangeStart, v.timeRangeStop and v.windowPeriod
  • Graph cells
  • Single stat cells
  • Graph + single stat cells (with minor caveats regarding centering of single stat relative to graph)
  • gauge cells (currently only partially rendering correct content)

Available output modes

The following table summarizes available options for the mode parameter to InfluxDBDashboardOutput:

Mode Description
color (default) Render the dashboard as regular, color image
bw Render the dashboard using only black and white colors, suitable for 2-color e-ink displays
bw4 Render the dashboard using only 4-color grayscale, suitable for 4-color e-ink displays

influxdb-dashboard-renderer's People

Contributors

levonisrayelyan avatar rickspencer3 avatar wojciechka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

influxdb-dashboard-renderer's Issues

Cannot render a dashboard

Hi!
I'm trying to use the python script in the REAMD and the server and in both caes i have the same error. My main goal is export the dashboard to make a pdf report.

Below the output of script and the server usage. Any help would be appreciated

Error in server stdout

[2021-08-06 19:58:24,233] ERROR in app: Exception on /render [POST]
Traceback (most recent call last):
File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1513, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib64/python3.6/site-packages/flask/app.py", line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "./server/server.py", line 87, in render
result = get_dashboard_from_request()
File "./server/server.py", line 49, in get_dashboard_from_request
d = InfluxDBDashboardView(c, dashboard_id)
File "/home/user/influxdb-dashboard-renderer/influxdb_dashboard/client.py", line 214, in init
self.name = info.name
AttributeError: 'dict' object has no attribute 'name'
127.0.0.1 - - [06/Aug/2021 19:58:24] "POST /render HTTP/1.1" 500 -

** Curl Command **

[root@server influxdb-dashboard-renderer] curl --header "Content-Type: application/json" -X POST \

--data '{^
"url": "http://10.x.x.x:8086",
"token": "token_id_created_in_influx",
"org_id": "organization_id_taken_from_about_section",
"id": "id_of_the_dashboard",
"width": 1280,
"height": 720,
"dpi": 75
}' http://127.0.0.1:5000/render

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

[root@silenox influxdb-dashboard-renderer]#

Error in script

Traceback (most recent call last):
File "influx.py", line 9, in
d = InfluxDBDashboardView.find_by_label(c, LABEL)
File "/home/user/influxdb-dashboard-renderer/influxdb_dashboard/client.py", line 250, in find_by_label
return cls(client, matches[0].id, org_id=org_id)
File "/home/user/influxdb-dashboard-renderer/influxdb_dashboard/client.py", line 214, in init
self.name = info.name
AttributeError: 'dict' object has no attribute 'name'

** Parameter **
TOKEN='token_id_created_in_influx'
ORG_ID='organization_id_taken_from_about_section'
LABEL='name_of_the_label_asociated_with_dashboard'

c = InfluxDBClient(url='http://10.x.x.x:8086', token=TOKEN, org=ORG_ID)

** Aditional note **
I found and error in script about the import. I use this:

from influxdb_dashboard import InfluxDBDashboardView, InfluxDBDashboardOutput
from influxdb_client import InfluxDBClient

Regards,
Mariano

error

I'v tried to get this working but no mater what I enter I only get
{"status": "error", "message": "not all arguments were provided"}

I have Token, location, org id set as variables in the docker image

the URL I'm sending is http://192.168.0.11:5000/render?lable=House

thanks

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.