Coder Social home page Coder Social logo

Cannot fetch data about mongodb-grafana HOT 25 CLOSED

jamesosgood avatar jamesosgood commented on August 19, 2024
Cannot fetch data

from mongodb-grafana.

Comments (25)

jonymaldo avatar jonymaldo commented on August 19, 2024 2

Right, it's ok after changing the type of time, thanks!

@yulidai How was this problem solved? I have the same problem, I changed the time type to isodate but it doesn't work.

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024 1

Right, it's ok after changing the type of time, thanks!

from mongodb-grafana.

JamesOsgood avatar JamesOsgood commented on August 19, 2024

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Query:
db.test.aggregate()

Error in Response
{ "message": "Cannot read property 'length' of undefined" }

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Thanks for your reply. I changed query to:
db.test.aggregate({"$group" : {"_id" : "$name", "num_tutorial" : {"$sum" : 1}}})

Then there's no wrong messge. But still not info showed in "Table Panel", but has result when running in mongo-cli

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

you need to project the following fields in order for it to show on the panel:

db.test.aggregate([
    {"$group" : {
        "_id" : "$name",
        "num_tutorial" : {"$sum" : 1},
        "time" : {"$first" : "$your_time_column_name"}
    }},
    {"$project" : {
        "name" : "$_id",
        "value" : "$num_tutorial",
        "ts" : "$time",
        "_id" : 0
    }}
])

You can check the README for more info on the required fields that the api expects

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

@minh0722 Thank you for your patience

Here is my data in mongo with command in mongo:

db.myCollection.find()

{ "_id" : ObjectId("5b6c2f134202c48ce09a6a13"), "time" : 1533816595792, "value" : 1, "metric" : "first" }
{ "_id" : ObjectId("5b6c2f1b4202c48ce09a6a14"), "time" : 1533816603521, "value" : 3, "metric" : "second" }
{ "_id" : ObjectId("5b6c34a74202c48ce09a6a15"), "time" : 1533818023968, "value" : 5, "metric" : "second" }

Then the query in panel is:

db.myCollection.aggregate([
    {"$group" : {
        "_id" : "$name",
        "num_tutorial" : {"$sum" : 1},
        "time" : {"$first" : "$time"}
    }},
    {"$project" : {
        "name" : "$_id",
        "value" : "$num_tutorial",
        "ts" : "$time",
        "_id" : 0
    }}
])

But still nothing showed in either Graph or Table. Any help will be appreciated, thank you!

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

You don't have a column name anywhere in your db. Try changing "_id" : "$name" to "_id" : "$metric"

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

Sorry I edited my prev comment

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

@minh0722 Thank you, Still nothing after changing, any other problem?

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

what's the response from the query?

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

target is

target:"db.myCollection.aggregate([ {"$group" : { "_id" : "$metric", "num_tutorial" : {"$sum" : 1}, "time" : {"$first" : "$time"} }}, {"$project" : { "name" : "$_id", "value" : "$num_tutorial", "ts" : "$time", "_id" : 0 }} ])"

response is

response:Array[1]
    0:Object
        columns:Array[0]
        rows:Array[0]
    type:"table"

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

change the type to timeserie. Table type is not supported

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Result after changing type to timeserie

response:Array[0]

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Maybe the reason is caused by time zone(here is china), but when i change time range from "last 6h" to "last 24h". But still nothing to show, i don't know why... T.T

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

I dont think that's the problem cause you dont have a "$match" pipeline in your aggregate. But just to try it out add this before "$group":
{ "$match" : { "time" : { "$gte" : "$from", "$lte" : "$to" } } },

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

No data too.

when run in mongo-cli with:

db.myCollection.aggregate([ {
  "$group" : { 
    "_id" : "$metric",
    "num_tutorial" : {"$sum" : 1},
    "time" : {"$first" : "$time"} }
}, {
  "$project" : { 
    "name" : "$_id", 
    "value" : "$num_tutorial", 
    "ts" : "$time", "_id" : 0 }
} ])

Will get data below:

{ "name" : "second", "value" : 2, "ts" : 1533816603521 }
{ "name" : "first", "value" : 1, "ts" : 1533816595792 }

But with nothing in grafana. Maybe caused by my grafana setting? But datasource test is success. And i rechecked config is same to the document

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

did you select the datasource that is above the query box?

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Here is the db config:

db:Object
  url:"mongodb://rpiread:[email protected]:27017,rpi-sensor-data-shard-00-01-ifxxs.mongodb.net:27017,rpi-sensor-data-shard-00-02-ifxxs.mongodb.net:27017/test?ssl=true&replicaSet=rpi-sensor-data-shard-0&authSource=admin"
  db:"test"

And the mongodb is running in local, Datasource testing info is:

Data source is working

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Yes i did select the mongodb as the datasouce

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

Oh my god, the Datasource testing always success even though closing the database. I think is the proxy hide the error, i'll check it...

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

check if data source is correctly configured. I had problem with some proxy settings and I had to write the full proxy domain name in mongodb url so you can check that too

from mongodb-grafana.

yulidai avatar yulidai commented on August 19, 2024

@minh0722 When i change "MongoDB URL" to localhost, the response is different:
target:

db.myCollection.aggregate([ {
  "$group" : { 
    "_id" : "$metric",
    "num_tutorial" : {"$sum" : 1},
    "time" : {"$first" : "$time"} }
}, {
  "$project" : { 
    "name" : "$_id", 
    "value" : "$num_tutorial", 
    "ts" : "$time", "_id" : 0 }
} ])

response:

response:Object
  message:"doc.ts.getTime is not a function"

from mongodb-grafana.

minh0722 avatar minh0722 commented on August 19, 2024

I think the field time has to be of type Date

from mongodb-grafana.

Adhira-Deogade avatar Adhira-Deogade commented on August 19, 2024

I am facing same issues - my query is this -
db.test_profile.aggregate ( [ { "$match" : { "job_name" : "metric_name", "start_time" : { "$gte" : "15" } } } ])

and response is -
response:Array[0]

from mongodb-grafana.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.