|
1 | 1 | # Grafana Materialize Data Source
|
2 | 2 |
|
3 |
| -This is a WIP Grafana data source which can connect to the [Materialize][] streaming SQL database. |
| 3 | +This is a Grafana data source which can connect to the [Materialize][] streaming SQL database. It supports the Grafana Live capabilities for streaming data and hence can be used to visualise data in materialized views 'live'. |
4 | 4 |
|
5 |
| -## Screenshots |
6 |
| - |
7 |
| -https://user-images.githubusercontent.com/5464991/166680691-8df200d7-e354-43bf-a924-8ce9fbc8582a.mov |
8 |
| - |
9 |
| - |
10 |
| - |
11 |
| - |
12 |
| - |
13 |
| -## Getting started |
14 |
| - |
15 |
| -### Using docker-compose |
16 |
| - |
17 |
| -Running `docker-compose up -d` from the repository root will start up a Grafana instance with a |
18 |
| -pre-provisioned instance of this data source pointing to a materialized instance inside Docker. It |
19 |
| -will also start up two processes to watch the backend and frontend directory for changes, |
20 |
| -rebuild the plugin components, and restart the backend process inside the Grafana container. |
21 |
| - |
22 |
| -### Outside of Docker |
23 |
| - |
24 |
| -#### Plugin frontend |
25 |
| - |
26 |
| -At the repository root: |
| 5 | +## Usage |
27 | 6 |
|
28 |
| -1. Install dependencies |
| 7 | +### Configuring the datasource |
29 | 8 |
|
30 |
| - ```bash |
31 |
| - yarn install |
32 |
| - ``` |
| 9 | +Only three parameters are available for the datasource: |
33 | 10 |
|
34 |
| -2. Build plugin in development mode or run in watch mode |
| 11 | +- **Host** - the hostname of the Materialize database |
| 12 | +- **Port** - the port on which to connect to the Materialize database |
| 13 | +- **Username** - the username as which to connect to the Materialize database |
35 | 14 |
|
36 |
| - ```bash |
37 |
| - yarn dev |
38 |
| - ``` |
| 15 | +### Querying the datasource |
39 | 16 |
|
40 |
| - or |
| 17 | +When querying the datasource in a new panel you have two options available to you: |
41 | 18 |
|
42 |
| - ```bash |
43 |
| - yarn watch |
44 |
| - ``` |
| 19 | +- **Relation** - the query builder will populate a list of available relations in the Materialize database. Select one and the relation will be `TAIL`ed to the panel. |
| 20 | +- **Select statement** - input a custom statement into the query field and the output of the statement will be `TAIL`ed to the panel. |
45 | 21 |
|
46 |
| -3. Build plugin in production mode |
| 22 | +### Configuring panels |
47 | 23 |
|
48 |
| - ```bash |
49 |
| - yarn build |
50 |
| - ``` |
| 24 | +The plugin includes the `mz_timestamp` and `mz_diff` columns in the streaming output, which may not be what you want to see. The simplest way to solve this is to use the [Transformations][] functionality of the panels. In the panel editor, click the **Transform** button and add any transformations you like. A good place to start is: |
51 | 25 |
|
52 |
| -#### Plugin backend |
| 26 | +1. Organize fields |
| 27 | + Use this to hide the `mz_diff` field by clicking the 'eye' symbol next to the field name. |
| 28 | +2. Prepare time series |
| 29 | + Select **Multi-frame time series** as the format. |
| 30 | +3. Rename by regex |
| 31 | + Use this to remove any common unwanted prefix from the time series names. E.g. set **Match** to `avg (.*)` and **Replace** to `$1` to remove the prefix `avg `. |
53 | 32 |
|
54 |
| -Make sure you have a recent version of Rust (run `rustup update stable`), and install [`cargo-watch`]. |
| 33 | +See the 'transforms' screenshot for an example. |
55 | 34 |
|
56 |
| -Then run: |
57 |
| - |
58 |
| -```bash |
59 |
| -cargo xtask watch |
60 |
| -``` |
61 |
| - |
62 |
| -This will run the `watch` task using the [`cargo-xtask`] pattern, which rebuilds the backend component on changes, copies the binary into the correct location, and restarts the plugin process (which Grafana subsequently restarts). |
63 |
| - |
64 |
| -#### Running Grafana |
65 |
| - |
66 |
| -You can run a Grafana instance either by cloning the Grafana repository, or running it inside Docker. See the Grafana docs for more information. |
67 |
| - |
68 |
| -## Cross compiling |
69 |
| - |
70 |
| -### From MacOS |
71 |
| - |
72 |
| -1. Install the relevant cross compiler toolchains. Using Homebrew: |
73 |
| - |
74 |
| - ```bash |
75 |
| - brew tap messense/macos-cross-toolchains |
76 |
| - brew install armv7-unknown-linux-musleabihf |
77 |
| - brew install aarch64-unknown-linux-musl |
78 |
| - brew install x86_64-unknown-linux-musl |
79 |
| - brew install mingw-w64 |
80 |
| - ``` |
81 |
| - |
82 |
| -2. Install the relevant Rust targets. Using `rustup`: |
| 35 | +## Screenshots |
83 | 36 |
|
84 |
| - ```bash |
85 |
| - rustup target add armv7-unknown-linux-musleabihf |
86 |
| - rustup target add aarch64-apple-darwin |
87 |
| - rustup target add x86_64-apple-darwin |
88 |
| - rustup target add aarch64-unknown-linux-musl |
89 |
| - rustup target add x86_64-unknown-linux-musl |
90 |
| - rustup target add x86_64-pc-windows-gnu |
91 |
| - ``` |
| 37 | +https://user-images.githubusercontent.com/5464991/166680691-8df200d7-e354-43bf-a924-8ce9fbc8582a.mov |
92 | 38 |
|
93 |
| -3. Run the following to compile the plugin in release mode for each target: |
| 39 | + |
94 | 40 |
|
95 |
| - ```bash |
96 |
| - CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=armv7-unknown-linux-musleabihf-ld cargo build --release --target armv7-unknown-linux-musleabihf --bin grafana-materialize-datasource |
97 |
| - cargo build --release --target aarch64-apple-darwin --bin grafana-materialize-datasource |
98 |
| - cargo build --release --target x86_64-apple-darwin --bin grafana-materialize-datasource |
99 |
| - CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=x86_64-unknown-linux-musl-gcc cargo build --release --target x86_64-unknown-linux-musl --bin grafana-materialize-datasource |
100 |
| - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-unknown-linux-musl-gcc cargo build --release --target aarch64-unknown-linux-musl --bin grafana-materialize-datasource |
101 |
| - CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-gcc cargo build --release --target x86_64-pc-windows-gnu --bin grafana-materialize-datasource |
102 |
| - ``` |
| 41 | + |
103 | 42 |
|
104 |
| -[`cargo-xtask`]: https://github.com/matklad/cargo-xtask |
105 |
| -[`cargo-watch`]: https://github.com/watchexec/cargo-watch/ |
106 | 43 | [Materialize]: https://materialize.com
|
| 44 | +[Transformations]: https://grafana.com/docs/grafana/latest/panels/transform-data/transformation-functions/ |
107 | 45 |
|
0 commit comments