JamesOsgood / mongodb-grafana

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

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

Open victordamazio opened 4 years ago

victordamazio commented 4 years ago

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 commented 4 years ago

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

On Tue, 6 Oct 2020 at 14:48, victordamazio notifications@github.com wrote:

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: image] https://user-images.githubusercontent.com/25162231/95209142-64220b00-07c0-11eb-8baf-22df53c3c95e.png

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: image] https://user-images.githubusercontent.com/25162231/95209047-448ae280-07c0-11eb-91af-17bfc477459f.png

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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JamesOsgood/mongodb-grafana/issues/105, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWPD6AH6ZGIJYRPTWUT7YTSJMN3JANCNFSM4SGBTTUA .

victordamazio commented 4 years ago

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 commented 4 years ago

Sorry - was on the move. Should be port 3333. Follow the instructions here

James

On Wed, 7 Oct 2020 at 12:41, victordamazio notifications@github.com wrote:

[image: image] https://user-images.githubusercontent.com/25162231/95326261-ac046900-0878-11eb-9288-baec9e1410c9.png

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

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JamesOsgood/mongodb-grafana/issues/105#issuecomment-704878027, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWPD6EAVKFNVZIF3SSMLGLSJRHVJANCNFSM4SGBTTUA .

victordamazio commented 4 years ago

Thanks.

image

And now?

JamesOsgood commented 4 years ago

Have you done this?

Install and Start the MongoDB proxy server

On Wed, 7 Oct 2020 at 13:05, victordamazio notifications@github.com wrote:

Thanks.

[image: image] https://user-images.githubusercontent.com/25162231/95328558-19fe5f80-087c-11eb-9171-f0502b16d3b5.png

And now?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JamesOsgood/mongodb-grafana/issues/105#issuecomment-704889407, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWPD6EZUMPPEEOZOTY3ZE3SJRKPNANCNFSM4SGBTTUA .

victordamazio commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Grafana talks to the proxy ( listening on localhost:3333), the proxy talks to the database.

On Wed, 7 Oct 2020 at 15:11, victordamazio notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JamesOsgood/mongodb-grafana/issues/105#issuecomment-704963630, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWPD6DOH43WNAVTWYNUMS3SJRZKLANCNFSM4SGBTTUA .

victordamazio commented 4 years ago

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

victordamazio commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

I have a very busy day job at MongoDB so just do this out of the goodness of my heart. I haven't touched the code for years.

The Grafana interface is the same. You are editing the templates which drive the dropdowns, not the agg query that drives the graph. Click on the title of the graph 'Sensor Value' and then 'Edit'. Grafana needs a time returned in the query with the name 'ts' so you will need to project a time value ( in epoch time ) in the query. The query needs to return name, value, ts - make your query return the same values as the example.

James

On Wed, 21 Oct 2020 at 14:10, victordamazio notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JamesOsgood/mongodb-grafana/issues/105#issuecomment-713557843, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABWPD6HAOFKFQWIEPCNCOBLSL3MVXANCNFSM4SGBTTUA .

victordamazio commented 4 years ago

Ok thanks.

victordamazio commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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.