Brendan Abolivier 6 年 前
コミット
21a77219bb
署名者: Brendan Abolivier <contact@brendanabolivier.com> GPGキーID: 8EF1500759F70623
共有1 個のファイルを変更した75 個の追加0 個の削除を含む
  1. 75
    0
      README.md

+ 75
- 0
README.md ファイルの表示

@@ -0,0 +1,75 @@
1
+# Grafana Dashboard Manager
2
+
3
+The Grafana Dashboard Manager is a tool to help you manage your Grafana dashboards using Git.
4
+
5
+## Manager
6
+
7
+The manager is split in two parts:
8
+
9
+### The puller
10
+
11
+The puller is a tool that will pull all the dashboards from the Grafana API, except the ones with a name starting with a specific prefix (if provided in the configuration file), and commit them to the Git repository if needed (and push them to the remote afterwards).
12
+
13
+To determine if a dashboard sould be commited to the repository, the puller relies on Grafana's dashboard version management. It will store the versions of all known dashboards (in a file called `versions.json`, which it will create if it doesn't exist), and commit changes to a dashboard only if the version retrieved from the Grafana API has a greater version number than the one stored in `versions.json` (if none is stored, it will systematically commit the retrieved dashboard).
14
+
15
+If a dashboard has changes to be commited, its JSON description will be stored in a JSON file at the root of the repository (named `[dashboard slug].json`), and will be added to the Git index. Once all new or modified files have been added to the index, the puller creates a commit with the detail of the update in the commit message, then pushes it to the remote.
16
+
17
+If there wasn't any error causing it to `panic`, the puller exits once all commited changes have been pushed to the Git remote.
18
+
19
+### The pusher
20
+
21
+The pusher is a tool that will expose a webhook to a given address (`interface:port/path`) and process incoming push events sent by the Git remote.
22
+
23
+For every push event on the `master` branch of the repository, it will look at the files added or modifed by the pushed commits (ignoring the ones with a name starting with a specific prefix (if provided in the configuration file)). It will then proceed to push them to the Grafana API to update modified dashboards or create added ones.
24
+
25
+It will then call the puller to have all the files up to date. This is mainly done to update the version number of each dashboard, as Grafana updates them automatically when a new or updated dashboard is pushed.
26
+
27
+Because it hosts a webserver, the pusher runs as a daemon and never exists unless it `panic`s because of an error, or it is killed (e.g. with `Ctrl+C`).
28
+
29
+
30
+## Build
31
+
32
+The manager can be built using [gb](https://getgb.io), which can be installed by running
33
+
34
+```bash
35
+go get github.com/constabulary/gb/...
36
+```
37
+
38
+It can then be built by cloning the repository and running
39
+
40
+```bash
41
+cd grafana-dashboard-manager
42
+gb build
43
+```
44
+
45
+Once built, binaries are located in the `bin` directory (which is created by `gb` if it doesn't exist).
46
+
47
+## Run
48
+
49
+To run either the puller or the pusher, simply execute the corresponding binary
50
+
51
+```bash
52
+./puller
53
+```
54
+
55
+or
56
+
57
+```bash
58
+./pusher
59
+```
60
+
61
+Of course, this command line call may depend on the location and name of the binaries.
62
+
63
+You can specify a configuration file via the command line flag `--config`, which works with both the puller and pusher. For example, here's how the full call should look like when passing a configuration file path to the puller:
64
+
65
+```bash
66
+./puller --config /etc/grafana-dashboard-manager/config.yaml
67
+```
68
+
69
+If the `--config` flag isn't present in the command line call, it will default to a `config.yaml` file located in the directory from where the call is made.
70
+
71
+## Configure
72
+
73
+To run either the puller or the pusher, you will need a configuration file first. The simplest way to create one is to copy the `config.example.yaml` file at the root of this repository and replace all of the placeholder values with your own.
74
+
75
+Since all the keys are documented as comments in the `config.example.yaml` file, there won't be any more documentation about them in this README file.