JamesOsgood / mongodb-grafana

MongoDB plugin for Grafana
MIT License
468 stars 213 forks source link

"Bad Gateway" when running with Docker containers #32

Open lockan opened 6 years ago

lockan commented 6 years ago

I'm running Grafana and MongoDb using docker containers on an AWS EC2 instance.

I've installed the grafana-mongodb plugin as described in the README to ~/data/grafana/plugins, which is then mounted to the grafana container volume. MongoDb: docker run -d --restart on-failure --network local -p 27017:27017 -v ~/data/mongodb/db:/data/db -v ~/data/mongodb/configdb:/data/configdb --name mongodb mongo:latest Grafana: docker run -d --restart on-failure --network local -p 3000:3000 --user root -v ~/data/grafana:/var/lib/grafana --name=grafana grafana/grafana

Both containers are using the --network local bridge connection and I've verified they can communicate with each other on the appropriate ports.

I've then generated a third container via docker build that runs the server proxy with EXPOSE 3333, and started it with the same --network local flag. The container entry point is "npm run server". docker logs will reveal that the proxy is running and listening on port 3333 as expected.

When I try to configure the data source in Grafana I can see MongoDB source as an option. I set the HTTP configuration to http://localhost:3333 and the mongdb connection to mongodb://mongodb:27017 (where "mongodb" is the name of the mongodb container). I've also tried mongodb://localhost:27017.

In either case when I save and test the connection I receive a "Bad Gateway" error. I do not encounter this error when running the applications as services outside of docker.

digitalacorn commented 5 years ago

This error could either be between grafana and the proxy, or the proxy to mongodb. I went with a docker-compose option to run both the grafana and plugin node proxy.

version: '3'
services:
  grafana:
    build:
      context: ./grafana
    ports:
    - "3300:3000"
    volumes:
    - ${PWD}/_dataMount:/var/lib/grafana
    links:
    - mongodbproxy
    entrypoint: 
    - bash
    - /var/lib/setup.sh
  mongodbproxy:
    build:
      context: ./mongodbproxy
    # ports:
    # - "3333:3333"
    volumes:
    - ${PWD}/_dataMount:/var/lib/grafana
    entrypoint: 
    - bash
    - /var/lib/setup.sh

Note the 'links' so the grafana service can see the mongodb proxy service.

Then the configuration of the plugin uses: http://mongodbproxy:3333 for the HTTP proxy URL and mongodb://host.docker.internal:27017 for the MongoDB url (as I'm running my mongodb outside, directly on the host for the container.

Hope that helps.

lockan commented 5 years ago

Thanks for the help. I may revisit this at some point, but I've actually moved away from mongodb for my project for unrelated reasons. Hopefully your reply is helpful to somebody else should they come across the same issue.