-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdiagnostic.nim
96 lines (76 loc) · 3.67 KB
/
diagnostic.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import sequtils
import ../core/[bson, types, utils, wire]
import multisock
## Diagnostics Commands
## ********************
##
## This APIs can be referred `here`_. All these APIs are returning BsonDocument
## so check the `Mongo documentation`__.
##
## **Beware**: These APIs are not tested.
##
## All APIs are async.
##
## .. _here: https://docs.mongodb.com/manual/reference/command/nav-diagnostic/
## __ here_
proc buildInfo*(db: Database[AsyncSocket]): Future[BsonDocument] {.multisock.} =
result = await db.crudops(bson({ buildInfo: 1 }))
proc collStats*(db: Database[AsyncSocket], coll: string, scale = 1024):
Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ collStats: coll, scale: scale}))
proc connPoolStats*(db: Database[AsyncSocket]): Future[BsonDocument] {.multisock.} =
result = await db.crudops(bson({ connPoolStats: 1 }))
proc connectionStatus*(db: Database[AsyncSocket], showPriv = false): Future[BsonDocument] {.multisock.} =
result = await db.crudops(bson({
connectionStatus: 1, showPrivileges: showPriv
}))
proc dataSize*(db: Database[AsyncSocket], coll: string, pattern = bson({"_id": 1}),
min = bson(), max = bson(), estimate = false): Future[BsonDocument]{.multisock.} =
var q = bson({ dataSize: coll, keyPattern: pattern })
q.addOptional("min", min)
q.addOptional("max", max)
q.addConditional("estimate", estimate)
result = await db.crudops(q)
proc dbHash*(db: Database[AsyncSocket], colls: seq[string] = @[]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({
dbHash: 1, collections: colls.map toBson
}))
proc dbStats*(db: Database[AsyncSocket], scale = 1024): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({
dbStats: 1, scale: scale
}))
proc explain*(db: Database[AsyncSocket], cmd = bson(), verbosity = "allPlansExecution", command = ckRead):
Future[BsonDocument] {.multisock.} =
let q = bson({ explain: cmd, verbosity: verbosity })
result = await db.crudops(q, cmd = command)
proc getCmdLineOpts*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ getCmdLineOpts: 1 }), "admin")
proc getLog*(db: Database[AsyncSocket], filter = "global"): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ getLog: filter }), "admin")
proc getLogFilters*(db: Database[AsyncSocket]): Future[seq[string]] {.multisock.} =
let names = await db.getLog("*")
result = names["names"].ofArray.map ofString
proc hostInfo*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ hostInfo: 1 }), "admin")
proc listCommands*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ listCommands: 1 }))
proc ping*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ ping: 1 }))
proc profile*(db: Database[AsyncSocket], level = 0, slowms = 100, sampleRate = 1.0):
Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({
profile: level,
slowms: slowms,
sampleRate: sampleRate
}))
proc serverStat*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({serverStatus:1}))
proc shardConnPoolStats*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ shardConnPoolStats: 1 }))
proc top*(db: Database[AsyncSocket]): Future[BsonDocument]{.multisock.} =
result = await db.crudops(bson({ top: 1 }), "admin")
proc validate*(db: Database[AsyncSocket], coll: string, full = false):
Future[BsonDocument] {.multisock.} =
var q = bson({ validate: coll })
q.addOptional("full", full)
result = await db.crudops(q)