Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!dist
!server
!package*.json
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:carbon

WORKDIR /usr/src/app

COPY . .
RUN npm install

EXPOSE 3333
CMD ["npm", "run", "server"]
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ Allows MongoDB to be used as a data source for Grafana by providing a proxy to c
* **Grafana** > 3.x.x
* **MongoDB** > 3.4.x

## Demo in Docker

* Bootstraps [Grafana](https://github.com/grafana/grafana-docker) with mongodb proxy plugin
* Launches mongodb proxy service
* Imports preconfigured Dashboards

Grafana will be available on `3000` port

```
git clone https://github.com/JamesOsgood/mongodb-grafana.git
docker-compose up
```

## Installation

### Install the Grafana plugin components
Expand Down Expand Up @@ -47,7 +60,7 @@ Clicking on the title of the graph allows you to see the aggregation query being
The query here is

```javascript
db.sensor_value.aggregate ( [
db.sensor_value.aggregate ( [
{ "$match" : { "sensor_type" : "$sensor", "host_name" : "$host", "ts" : { "$gte" : "$from", "$lte" : "$to" } } },
{"$sort" : {"ts" : 1}},
{"$project" : { "name" : "value", "value" : "$sensor_value", "ts" : "$ts", "_id" : 0} } ])
Expand All @@ -73,10 +86,10 @@ db.sensor_value.aggregate ( [
Grafana tells the backend server the date range along with the size of the buckets that should be used to calculate points. Therefore it's possible to use the MongoDB aggregation operator [$bucketAuto](https://docs.mongodb.com/manual/reference/operator/aggregation/bucketAuto/) to automatically bucket the data points into display points. To support this the backend provides the `$dateBucketCount` macro so that queries such as the one below can be written

```javascript
db.sensor_value.aggregate( [
db.sensor_value.aggregate( [
{ "$match" : { "sensor_type" : "$sensor", "host_name" : "$host" , "ts" : { "$gte" : "$from", "$lt" : "$to" }}},
{ "$bucketAuto" : { "groupBy" : "$ts",
"buckets" : "$dateBucketCount",
"buckets" : "$dateBucketCount",
"output" : { "maxValue" : { "$max" : "$sensor_value" } } } },
{ "$project" : { "name" : "value", "value" : "$maxValue", "ts" : "$_id.min", "_id" : 0 } } ] )
```
Expand All @@ -91,13 +104,3 @@ The dashboard in `examples\RPI MongoDB Bucket - Atlas.json` shows this.
* run `launchctl load mongodb-grafana-proxy` from ~/Library/LaunchAgents

This launch ctrl plist runs the node script via forever. To check it's running, use `forever list`. Logs go into /usr/local/var/lib/grafana/plugins/mongodb-grafana/dist/server










14 changes: 14 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '2.2'
services:
graphana:
image: grafana/grafana:latest
ports:
- "3000:3000"
volumes:
- ".:/var/lib/grafana/plugins/grafana-mongodb-datasource"
- "./examples/docker-demo/datasources:/etc/grafana/provisioning/datasources"
- "./examples/docker-demo/dashboards:/etc/grafana/provisioning/dashboards"
- "./examples:/var/lib/grafana/dashboards"
gf-mdb-proxy:
build: .
image: jamesosgood/mongodb-grafana
30 changes: 6 additions & 24 deletions examples/RPI MongoDB - Atlas.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
{
"__inputs": [
{
"name": "DS_RPI_- ATLAS",
"label": "RPI - Atlas",
"description": "",
"type": "datasource",
"pluginId": "grafana-mongodb-datasource",
"pluginName": "MongoDB"
},
{
"name": "DS_RPI_- LOCAL",
"label": "RPI - Local",
"description": "",
"type": "datasource",
"pluginId": "grafana-mongodb-datasource",
"pluginName": "MongoDB"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "4.6.3"
"version": ""
},
{
"type": "datasource",
"id": "grafana-mongodb-datasource",
"name": "MongoDB",
"version": "1.3.5"
"version": ""
},
{
"type": "panel",
Expand Down Expand Up @@ -67,7 +49,7 @@
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_RPI_- ATLAS}",
"datasource": "DS_RPI_ATLAS",
"fill": 1,
"id": 1,
"legend": {
Expand Down Expand Up @@ -164,7 +146,7 @@
{
"allValue": null,
"current": {},
"datasource": "${DS_RPI_- LOCAL}",
"datasource": "DS_RPI_LOCAL",
"hide": 0,
"includeAll": false,
"label": "",
Expand All @@ -184,7 +166,7 @@
{
"allValue": null,
"current": {},
"datasource": "${DS_RPI_- LOCAL}",
"datasource": "DS_RPI_LOCAL",
"hide": 0,
"includeAll": false,
"label": "sensor",
Expand Down Expand Up @@ -235,4 +217,4 @@
"timezone": "",
"title": "RPI Mongo - Atlas",
"version": 4
}
}
26 changes: 4 additions & 22 deletions examples/RPI MongoDB Bucket - Atlas.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
{
"__inputs": [
{
"name": "DS_RPI_- ATLAS",
"label": "RPI - Atlas",
"description": "",
"type": "datasource",
"pluginId": "grafana-mongodb-datasource",
"pluginName": "MongoDB"
},
{
"name": "DS_RPI_- LOCAL",
"label": "RPI - Local",
"description": "",
"type": "datasource",
"pluginId": "grafana-mongodb-datasource",
"pluginName": "MongoDB"
}
],
"__requires": [
{
"type": "grafana",
Expand Down Expand Up @@ -67,7 +49,7 @@
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_RPI_- ATLAS}",
"datasource": "DS_RPI_ATLAS",
"fill": 1,
"id": 1,
"legend": {
Expand Down Expand Up @@ -168,7 +150,7 @@
{
"allValue": null,
"current": {},
"datasource": "${DS_RPI_- LOCAL}",
"datasource": "DS_RPI_LOCAL",
"hide": 0,
"includeAll": false,
"label": "",
Expand All @@ -188,7 +170,7 @@
{
"allValue": null,
"current": {},
"datasource": "${DS_RPI_- LOCAL}",
"datasource": "DS_RPI_LOCAL",
"hide": 0,
"includeAll": false,
"label": "sensor",
Expand Down Expand Up @@ -239,4 +221,4 @@
"timezone": "",
"title": "RPI Mongo Bucket - Atlas",
"version": 3
}
}
6 changes: 6 additions & 0 deletions examples/docker-demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Grafana Configuration Files
===========================

### Documentation references
* [Datasources](http://docs.grafana.org/administration/provisioning/#datasources)
* [Dashboards ](http://docs.grafana.org/administration/provisioning/#dashboards)
10 changes: 10 additions & 0 deletions examples/docker-demo/dashboards/custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: 1

providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
options:
path: /var/lib/grafana/dashboards
19 changes: 19 additions & 0 deletions examples/docker-demo/datasources/custom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: 1

datasources:
- name: DS_RPI_LOCAL
type: grafana-mongodb-datasource
access: proxy
url: http://gf-mdb-proxy:3333
jsonData:
mongodb_db: rpi
mongodb_url: mongodb://rpiread:[email protected]:27017,rpi-sensorreadings-shard-00-01-fgscn.mongodb.net:27017,rpi-sensorreadings-shard-00-02-fgscn.mongodb.net:27017/test?ssl=true&replicaSet=RPI-SensorReadings-shard-0&authSource=admin
editable: true
- name: DS_RPI_ATLAS
type: grafana-mongodb-datasource
access: proxy
url: http://gf-mdb-proxy:3333
jsonData:
mongodb_db: rpi
mongodb_url: mongodb://rpiread:[email protected]:27017,rpi-sensorreadings-shard-00-01-fgscn.mongodb.net:27017,rpi-sensorreadings-shard-00-02-fgscn.mongodb.net:27017/test?ssl=true&replicaSet=RPI-SensorReadings-shard-0&authSource=admin
editable: true