42
SQL Datasources in Grafana Carl Bergquist & Marcus Efraimsson

SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

SQL Datasources in GrafanaCarl Bergquist & Marcus Efraimsson

Page 2: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 3: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Usage stats

Page 4: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Mysql:

Postgres:

MSSQL:

22000

7800

3000

Page 5: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 6: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Basic usage

Page 7: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 8: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 9: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 10: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Template variables from SQL

Page 11: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

What’s new for SQL datasources

Page 12: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Up until Grafana 5.0● MySQL in 4.3● Postgres in 4.6

(Oracle Database available as a premium plugin)

Page 13: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Grafana 5.1

Page 14: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Microsoft SQL Server support

Page 15: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Grafana 5.3

Page 16: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Postgres graphical query builder

Page 17: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Postgres TimescaleDB extension support

Page 18: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Grafana 5.4

Page 19: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

MySQL graphical query builder

Page 20: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Grafana 6.0

Page 21: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

MySQL SSL support

Page 22: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 23: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Tips and tricks!

Page 24: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Read only user

Page 25: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Permissions

● Grafana cannot sanitize the database input● Only grant select permissions on database and tables for database user

Page 26: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Performance

● Easy to write really expensive queries (SELECT * FROM)● Can slow database server down● Can hang browser where Grafana is used● Use a separate database from production/data warehouse

Page 27: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Time zones● Run Grafana and database server on UTC time zone● Use time zone-aware data types for storing dates ● Use epochs (seconds since 1970)

Page 28: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Time series queries● Most panels expects time series data● Must include a column named time

Page 29: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Pie Chart panel● Without having a time

column?● You create one

Page 30: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Graph panel - stacked bar chart

???

Page 31: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Graph panel - stacked bar chart● Need to supply a value for every interval● Use $__timeGroup/$__unixEpochGroup macro with fill parameter

$__timeGroup(dateColumn,‘5m’, 0)$__unixEpochGroup(dateColumn,‘5m’, 0)

Page 32: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Grafana GitHub statsCarl Bergquist & Marcus Efraimsson

Page 33: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

BackgroundGitHub Insights

Google Docs

Page 34: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Background cont.● Pull request activity kept growing

● WHY?○ Probably because Grafana Labs are growing?○ We maybe have a lot of new contributors?○ Non-Grafana Labs contributors are probably as active as before?

● Clearly needed a solution to remove the uncertainty!

Page 35: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Problem descriptionWe want to measure and visualize GitHub activity of Grafana Labs vs contributors over time to make sure we have a healthy community and keep growing the contributor base

Page 36: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Solution● Process GitHub events● Build pre-aggregated views ● Store in a relational database● Visualize in Grafana● Highly inspired by CNCF devstats

Page 37: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate
Page 38: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Relational database schemas

Page 39: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Relational database schemas optimized for● Ease of use in Grafana● Separation of “business logic” and visualization logic● Performance

Page 40: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Demo

Page 41: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Next steps?● Make dashboards publicly available on play.grafana.org ● Make it easier to use for other projects/companies● Process GitHub events older than 2015-01-01● Track bugs, feature requests and feature areas?● Other kinds of visualizations?

We contributions

Page 42: SQL Datasources in Grafana...Performance Easy to write really expensive queries (SELECT * FROM) Can slow database server down Can hang browser where Grafana is used Use a separate

Resources● Soon available on https://play.grafana.org ● Source code: https://github.com/grafana/devtools ● Public GitHub events archive: https://www.gharchive.org/ ● https://all.devstats.cncf.io ● https://github.com/cncf/devstats