redash使う簡易メモ

実際に使ってみる。

MySQL準備

参照するテーブル等作っておく。

$ mysql -u root -p

# ユーザー
mysql> CREATE USER 'mfham'@'localhost' IDENTIFIED BY '****';

# 権限
mysql> show grants for 'mfham'@'localhost';
+-------------------------------------------+
| Grants for mfham@localhost                |
+-------------------------------------------+
| GRANT USAGE ON *.* TO 'mfham'@'localhost' |
+-------------------------------------------+
1 row in set (0.00 sec)

mysql> GRANT SELECT ON redash_test.statistics to 'mfham'@'localhost';                                                                                                                   
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'mfham'@'localhost';                                                                                                                                             
+-------------------------------------------------------------------+
| Grants for mfham@localhost                                        |
+-------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'mfham'@'localhost'                         |
| GRANT SELECT ON `redash_test`.`statistics` TO 'mfham'@'localhost' |
+-------------------------------------------------------------------+
2 rows in set (0.00 sec)

# テーブルこんな感じ
mysql> select * from redash_test.statistics;
+------------+----------+----------+----------+----------+----------+
| date       | summaryA | summaryB | summaryC | summaryD | summaryE |
+------------+----------+----------+----------+----------+----------+
| 2016-10-01 |       10 |      123 |       30 |     3000 |      100 |
| 2016-10-02 |       14 |      113 |       10 |     2400 |      200 |
| 2016-10-03 |       30 |      313 |       23 |     1300 |      140 |
| 2016-10-04 |       50 |      613 |       83 |     6300 |      641 |
| 2016-10-05 |        6 |       23 |       13 |      500 |       41 |
+------------+----------+----------+----------+----------+----------+
5 rows in set (0.00 sec)

Re:dash

summaryA, summaryB, summaryCを棒グラフに

こんな感じ。
f:id:mfham:20161104003733p:plain:w300

iframeも吐き出してくれる

さっきの画像の左下にある「<>Embed」をクリックするとiframeソースをポップアップで教えてくれます。
自前のHTMLにペロッと貼ってそれを共有用にするのもいいかも。
f:id:mfham:20161104005016p:plain:w300

その他

1日1回SQLカウントするバッチを作る代わりに、SQL定期実行をRe:dashにやらせてデータも保持してくれたら最高やんって思ってたけど、単に与えられたSQLを実行して表示してるだけっぽいかな・・・
だからデータは手元で持っておかんといかんぽい。
さっきの画像には載ってないけど、ボタンひとつで結果をCSVExcelとしてダウンロードできるので、エンジニア以外の人が手軽にデータ見たりダウンロードしたりできるのはいいかも。