未从 KAA 服务器获取 MongoDB Log Appender 的数据

Not Getting Data of MongoDB Log Appender from KAA server

我已经使用 Java 和 MongoDB 日志附加程序配置了我的第一个 KAA 应用程序,能够在 KAA 服务器数据库日志中看到。 但我的问题是如何从 MongoDB Log Appenders 检索数据到我的本地系统或 Java 系统。

尝试过:

我也尝试调用 POSTMAN 服务,但找不到任何特定的 API。 http://10.110.25.52:8080/kaaAdmin/rest/api/logAppenders/536590273894852265 未在其中找到任何 API 的 LogAppneders 内容。

我尝试使用 MongoDb 的 KAA 服务器 ip 通过 Java 建立数据库连接,但没有成功。 下面的代码:

public static void main(String[] args) {

    try {

        MongoClient mongo = new MongoClient("127.0.0.1", 27017);


        // if database doesn't exists, MongoDB will create it for you
        com.mongodb.DB db = mongo.getDB("Kaa");
        System.out.println("db="+db);

        DBCollection table = db.getCollection("logs_53659027389148522657");
        System.out.println("table="+table);

        BasicDBObject searchQuery = new BasicDBObject();
        searchQuery.put("temperature", "30");

        DBCursor cursor = table.find(searchQuery);

        while (cursor.hasNext()) {
            System.out.println(cursor.next());
        }
        System.out.println("Done");

    } catch (UnknownHostException e) {
        e.printStackTrace();
    } catch (MongoException e) {
        e.printStackTrace();
    }

Kaa 不提供 REST API 来检索使用 Log Appender 添加到 MongoDB 的数据。您可以在 documentation 中找到所有可用的 REST API。您可以使用自己的应用程序连接到 MongoDB 并进行数据检索。

解决方案:在VM中将网络类型更改为"Bridge type"并通过"hostname -I"检查ubuntu中的ip,将特定IP设置为沙盒默认IP,运行 你的第一个 KAA 应用程序。日志将在 MongoDB Log Appender 中生成。但是要连接,您需要通过 运行 宁此命令更改配置文件 "Vim /etc/mongod.conf" 像这样注释掉 defualt ip "#127.0.0.1" 因为它只能允许 localhost 因为这个我不是能够在虚拟机之外连接它。 更改 IP 后,您需要再次生成应用程序的 SDK,以便它可以连接到该 IP,而不是 "localhost".

通过使用 roboClient,您可以轻松连接到 mongodb 数据库并进行分析。