Skip to content

Commit 796d837

Browse files
committed
Add quick start script
1 parent 15c756d commit 796d837

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Grafana MongoDB Data Source
22

3-
**Visualize your MongoDB data in Grafana with powerful aggregation queries.**
3+
Integrate MongoDB to Grafana
44

55
![ci](https://github.com/haohanyang/mongodb-datasource/actions/workflows/ci.yml/badge.svg?branch=master)
66

@@ -10,21 +10,27 @@ This plugin enables you to query and visualize data from your MongoDB databases
1010

1111
## Features
1212

13-
- **Flexible Querying:** Craft precise queries using MongoDB's aggregation pipeline syntax in JSON or JavaScript.
13+
- **Flexible Querying:** Query data using MongoDB's aggregation pipeline syntax in JSON or JavaScript. Support query variables to create dynamic dashboards.
1414
- **Time Series & Table Data:** Visualize time-based data or display results in tabular format for various Grafana panels.
15-
- **Secure Execution:** Execute JavaScript queries within a secure ShadowRealm sandbox to control access.
16-
- **Legacy Plugin Compatibility:** Seamlessly migrate from the legacy plugin with support for its query syntax.
17-
- **Up-to-date:** Use the latest Grafana Plugin SDKs and follow best practices.
15+
- **MongoDB Atlas Support** Connect to MongoDB Atlas Services.
16+
- **Legacy Plugin Compatibility:** Easy migrate from the legacy plugin with support for its query syntax.
17+
18+
## Authentication methods
19+
* No authentication
20+
* Username/Password authentication
1821

1922
## Getting Started
23+
### Quick start
24+
Run the script `scripts/start_docker.py` to start a MongoDB and Grafana container with the plugin
25+
```
26+
python3 scripts/start_docker.py
27+
```
28+
### Full steps
2029
1. **Download:** Obtain the latest plugin build from the [Release page](https://github.com/haohanyang/mongodb-datasource/releases) or [workflow artifacts](https://github.com/haohanyang/mongodb-datasource/actions?query=branch%3Amaster).
2130

2231
2. **Install:**
2332
- Extract the downloaded archive (`haohanyang-mongodb-datasource-<version>.zip`) into your Grafana plugins directory (`/var/lib/grafana/plugins` or similar).
2433
- Ensure the plugin binaries (`mongodb-datasource/gpx_mongodb_datasource_*`) have execute permissions (`chmod +x`).
25-
```bash
26-
chmod 0755 mongodb-datasource/gpx_mongodb_datasource_*
27-
```
2834
- Configure the plugin as a data source within Grafana, providing your MongoDB connection details.
2935

3036
Refer to the [example docker-compose.prod.yaml](/docker-compose.prod.yaml) file for a production-ready setup.

scripts/start_docker.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import urllib.request
2+
import json
3+
import tempfile
4+
import zipfile
5+
import os
6+
import glob
7+
import subprocess
8+
import shutil
9+
10+
dist_dir = "mongodb-datasource"
11+
if os.path.isdir(dist_dir):
12+
shutil.rmtree(dist_dir)
13+
14+
# Download the latest release build
15+
with urllib.request.urlopen(
16+
"https://api.github.com/repos/haohanyang/mongodb-datasource/releases/latest"
17+
) as response:
18+
data = json.loads(response.read())
19+
20+
for asset in data["assets"]:
21+
if asset["content_type"] == "application/zip":
22+
with tempfile.NamedTemporaryFile() as temp_file:
23+
print("Downloading " + asset["name"] + "...")
24+
urllib.request.urlretrieve(
25+
asset["browser_download_url"], temp_file.name
26+
)
27+
print("Extracting files to " + dist_dir)
28+
with zipfile.ZipFile(temp_file.name, "r") as zip_ref:
29+
zip_ref.extractall(os.getcwd())
30+
os.rename("haohanyang-mongodb-datasource", "mongodb-datasource")
31+
32+
# Grant execute permission go binaries
33+
for bin in glob.glob("mongodb-datasource/gpx_mongodb_datasource_*"):
34+
os.chmod(bin, 755)
35+
36+
subprocess.call(
37+
["sudo", "docker", "compose", "-f", "docker-compose.prod.yaml", "up", "-d"]
38+
)

0 commit comments

Comments
 (0)