Pau*_*l C 3 java connection-pooling mongodb
我需要在调用 REST 服务时发布(到 Graphite)Mongo db 实例的“可用活动连接数”状态。我知道我们可以使用 db.serverStatus() 来了解服务器端连接的详细信息。我希望使用 JAVA API 在客户端获取“可用活动连接数”信息。MongoDB Java Driver API 文档对此没有太大帮助。
假设您使用的是 3.0.x 驱动程序,并在默认端口上连接到 localhost:
MongoClient mongoClient = new MongoClient();
MongoDatabase database = mongoClient.getDatabase("admin");
Document serverStatus = database.runCommand(new Document("serverStatus", 1));
Map connections = (Map) serverStatus.get("connections");
Integer current = (Integer) connections.get("current");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8660 次 |
| 最近记录: |