-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserverStatus.go
63 lines (53 loc) · 1.47 KB
/
serverStatus.go
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
package main
import (
"dblogin"
"fmt"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"log"
)
func main() {
session, err := mgo.Dial(dblogin.Bookstore) // mongodb://username:yourpasscode@serverip:27017/database?authSource=admin
if err != nil {
log.Fatalf("Error connecting to MongoDB: %s", err)
}
defer session.Close()
db := session.DB("test")
//collectionName := "people"
result := &bson.D{}
err = db.Run(&bson.D{bson.DocElem{Name: "serverStatus", Value: 1}}, result)
if err != nil {
log.Fatalf("Failed to get collection stats: %s", err)
}
c := result.Map()["connections"]
cu := result.Map()["current"]
pid := result.Map()["pid"]
fmt.Println("connections: ", c)
fmt.Println("connections: ", cu)
fmt.Println("connections pid: ", pid)
}
/*
"host" : "mongodb",
"version" : "3.4.6",
"process" : "mongod",
"pid" : NumberLong(535),
"uptime" : 4247807,
"uptimeMillis" : NumberLong("4247807370"),
"uptimeEstimate" : NumberLong(4247807),
"localTime" : ISODate("2018-01-06T04:05:34.783Z"),
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 113,
"rollovers" : 0
},
"connections" : {
"current" : 14,
"available" : 805,
"totalCreated" : 717
},
"extra_info" : {
"note" : "fields vary by platform",
"page_faults" : 515
*/