Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to connect with MongoDB on a docker container (Many issues) #105

Open
victordamazio opened this issue Oct 6, 2020 · 21 comments
Open

Comments

@victordamazio
Copy link

Hi, my main issue is that I'm trying to connect to a MongoDB database which is actually included into a Docker Container.

I managed to connect to it just fine using Robo 3T

image

Using the IP 172.18.0.16 and the port 27017, I managed to connect to the database even though it was on a container.

Now, I need to connect Grafana to that database, but I can't, here's how I am trying:

image

Is the URL http://172.18.0.16:27017 correct?

When I tried to use "Server", it gave me the error message "HTTP Error Bad Gateway", but when using the "Browser", the error message is "NetworkError when attempting to fetch resource".

Why the "proxy" option is not appearing? Did I make a mistake when installing? It was removed?

The MongoDB URL is correct?

MongoDB Database as "rpi" is correct?

@JamesOsgood
Copy link
Owner

JamesOsgood commented Oct 6, 2020 via email

@victordamazio
Copy link
Author

victordamazio commented Oct 7, 2020

image

Sorry, I still have many doubts, is this closer to what I should do?

Grafana really is on localhost:3000, but should I do something to make sure I really need to write localhost:3000 on those forms?

Should I pick browser or server?

Where can I do the requests -> MQL queries? Is it really MQL?

Is the MongoDB URL correct? Or close to correct?

Should the MongoDB Database really be "rpi", or should be "device_history" or "admin_25c6b5"?

@JamesOsgood
Copy link
Owner

JamesOsgood commented Oct 7, 2020 via email

@victordamazio
Copy link
Author

Thanks.

image

And now?

@JamesOsgood
Copy link
Owner

JamesOsgood commented Oct 7, 2020 via email

@victordamazio
Copy link
Author

victordamazio commented Oct 7, 2020

Before all of this, I installed MongoDB in a Docker container, I need to access that container.

I think I have another MongoDB installation outside of the container, but I'm not sure.

Where the mongodb-grafana directory should be?

Edit. Sorry, I know where it is, gonna try that.

@victordamazio
Copy link
Author

Ok, I think that worked, with the testing.

But I still need to connect with the Database in the Docker container, which is probably not on localhost:3333

@JamesOsgood
Copy link
Owner

JamesOsgood commented Oct 7, 2020 via email

@victordamazio
Copy link
Author

victordamazio commented Oct 8, 2020

Ok, so I guess I need to place everything related to the container on MongoDB URL and MongoDB Database, right?

@victordamazio
Copy link
Author

victordamazio commented Oct 8, 2020

Yeah, I think I managed to connect with the MongoDB inside the container.

Now I think I just need a few more tips, I am creating a new dashboard from scratch, how can I access the data inside it to put on the panel? Now I think that's just something unrelated to the plugin, but can you help me on that?

image

This is how the MongoDB is shown on Robo 3T.

@victordamazio
Copy link
Author

victordamazio commented Oct 14, 2020

Hi again, I think I am really close, the only thing I need now is the query.

It's currently like this:

db.admin_25c6b5.aggregate( [ 
{  "$match" :  {  "sensor_type" : "$sensor", "host_name" : "$host" , "ts" : { "$gte" : "$from", "$lt" : "$to" }}},
{  "$bucketAuto" :  { "groupBy" : "$ts",  
                           "buckets" : "$dateBucketCount", 
                            "output" :  {  "maxValue" : { "$max" : "$sensor_value" }  }   }   },  
{  "$project" :  {  "name" : "Temperatura",  "value" : "$value",  "ts" : "$_id.min",  "_id" : 0  }  }  ]  )

What do you think I need to change? I don't know much about those MongoDB queries.

Look at how the MongoDB is above, what should I replace or add.

Also, the current error message is Unrecognized pipeline stage name: '$bucketAuto'

@victordamazio
Copy link
Author

I tried making a new query, here's how it is now:

db.admin_25c6b5.aggregate( 
[ 
{ "$match" :  {  attr : "temperature" } },
{ "$project" :  {  value : 1 }  }  
])

The error message that appears is: Unexpected token a in JSON at position 23

When I placed this query at Robo 3T, it worked, no error message, but at Grafana it appeared.

@victordamazio
Copy link
Author

victordamazio commented Oct 15, 2020

image

image

When I placed this query on Robo 3T, it worked like I wanted, I got the temperature values, so why when I place this into Grafana, it doesn't work and nothing is showing on the panel? Do I have to do something else?

db.admin_25c6b5.aggregate( 
[ 
{ "$match" :  { "attr" : "temperature" } },
{ "$sort" : { "ts" : 1 } }, 
{ "$project" :  { "value" : 1, "_id" : 0 } }
])

@victordamazio
Copy link
Author

victordamazio commented Oct 20, 2020

I think I am now close, really close to what I am trying to achieve.

The connection string is:

image

The query, which I made changes:

image

The real issue now is the variables $sensor and $host, I don't know where they should go, the Grafana User Interface is so different from the tutorial, look:

image

image

Do you think the tutorial could be updated for the new Grafana User Interface? Or my Grafana Installation has a problem?

@victordamazio
Copy link
Author

victordamazio commented Oct 21, 2020

The URL is the URL of the local proxy that is used to convert grafana requests -> MQL queries so it should be localhost:3000 and you need to run the node server as per the docs. James

Please, I need answers, I am stuck, and I think I am close to finishing it.

@JamesOsgood
Copy link
Owner

JamesOsgood commented Oct 21, 2020 via email

@victordamazio
Copy link
Author

Ok thanks.

@victordamazio
Copy link
Author

But actually, I'm trying to create a brand new dashboard, the tutorials you provided worked fine, I need a new dashboard with new data, that's what I need to do.

@victordamazio
Copy link
Author

victordamazio commented Oct 22, 2020

I decided to install MongoDB again, outside of the container, here's how I am trying to do it:

The database:

image

The connection:

image

The Dashboard:

image

I tried doing everything according to the tutorial, and it still didn't work.

Maybe it's the sensor, sensor_type, host and host_name variables?

@pnicolli
Copy link

pnicolli commented Dec 8, 2020

Maybe it's the sensor, sensor_type, host and host_name variables?

If you haven't set those variables in the dashboard, they will definitely not work.
Try removing them from your match step.

{ "$match": { "ts": { "$gte": "$from", "$lte": "$to" } } },

Also, in order for this to work, ts needs to be the name of the date field in the documents that are in your collection.

@subhranilbagchi7
Copy link

Ok, so I guess I need to place everything related to the container on MongoDB URL and MongoDB Database, right?

How you resolve the issue? Could you please help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants