Merge remote-tracking branch 'origin/pr/263' into PMM-1429_test_metrics

This commit is contained in:
Kamil Dziedzic
2017-09-14 22:07:20 +02:00
10 changed files with 180 additions and 20 deletions

View File

@@ -7,11 +7,13 @@ import (
"gopkg.in/mgo.v2/bson"
)
// docsExamined is renamed from nscannedObjects in 3.2.0
type SystemProfile struct {
AllUsers []interface{} `bson:"allUsers"`
Client string `bson:"client"`
CursorExhausted bool `bson:"cursorExhausted"`
DocsExamined int `bson:"docsExamined"`
NscannedObjects int `bson:"nscannedObjects"`
ExecStats struct {
Advanced int `bson:"advanced"`
ExecutionTimeMillisEstimate int `bson:"executionTimeMillisEstimate"`

View File

@@ -90,7 +90,12 @@ func (s *Stats) Add(doc proto.SystemProfile) error {
s.setQueryInfoAndCounters(key, qiac)
}
qiac.Count++
qiac.NScanned = append(qiac.NScanned, float64(doc.DocsExamined))
// docsExamined is renamed from nscannedObjects in 3.2.0.
if doc.NscannedObjects > 0 {
qiac.NScanned = append(qiac.NScanned, float64(doc.NscannedObjects))
} else {
qiac.NScanned = append(qiac.NScanned, float64(doc.DocsExamined))
}
qiac.NReturned = append(qiac.NReturned, float64(doc.Nreturned))
qiac.QueryTime = append(qiac.QueryTime, float64(doc.Millis))
qiac.ResponseLength = append(qiac.ResponseLength, float64(doc.ResponseLength))
@@ -269,7 +274,7 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
queryStats.QueryTime.Pct = queryStats.QueryTime.Total * 100 / tc.QueryTime
}
if tc.Bytes > 0 {
queryStats.ResponseLength.Pct = queryStats.ResponseLength.Total / tc.Bytes
queryStats.ResponseLength.Pct = queryStats.ResponseLength.Total * 100 / tc.Bytes
}
if queryStats.Returned.Total > 0 {
queryStats.Ratio = queryStats.Scanned.Total / queryStats.Returned.Total
@@ -281,6 +286,7 @@ func countersToStats(query QueryInfoAndCounters, uptime int64, tc totalCounters)
func aggregateCounters(queries []QueryInfoAndCounters) QueryInfoAndCounters {
qt := QueryInfoAndCounters{}
for _, query := range queries {
qt.Count += query.Count
qt.NScanned = append(qt.NScanned, query.NScanned...)
qt.NReturned = append(qt.NReturned, query.NReturned...)
qt.QueryTime = append(qt.QueryTime, query.QueryTime...)

View File

@@ -165,7 +165,8 @@ func main() {
if opts.Limit > 0 && len(sortedQueryStats) > opts.Limit {
sortedQueryStats = sortedQueryStats[:opts.Limit]
}
for _, qs := range sortedQueryStats {
for i, qs := range sortedQueryStats {
qs.Rank = i + 1
t.Execute(os.Stdout, qs)
}
@@ -426,15 +427,11 @@ func sortQueries(queries []stats.QueryStats, orderby []string) []stats.QueryStat
case "ratio":
f = func(c1, c2 *stats.QueryStats) bool {
ratio1 := c1.Scanned.Max / c1.Returned.Max
ratio2 := c2.Scanned.Max / c2.Returned.Max
return ratio1 < ratio2
return c1.Ratio < c2.Ratio
}
case "-ratio":
f = func(c1, c2 *stats.QueryStats) bool {
ratio1 := c1.Scanned.Max / c1.Returned.Max
ratio2 := c2.Scanned.Max / c2.Returned.Max
return ratio1 > ratio2
return c1.Ratio > c2.Ratio
}
//

View File

@@ -22,7 +22,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 0.9995949739087844,
"Pct": 99.95949739087844,
"Total": 1061230,
"Min": 1061230,
"Max": 1061230,
@@ -75,7 +75,7 @@
"Median": 7
},
"ResponseLength": {
"Pct": 0.00020251304560782172,
"Pct": 0.020251304560782172,
"Total": 215,
"Min": 215,
"Max": 215,
@@ -128,7 +128,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 0.00020251304560782172,
"Pct": 0.020251304560782172,
"Total": 215,
"Min": 215,
"Max": 215,

View File

@@ -6,8 +6,8 @@
"Fingerprint": "",
"FirstSeen": "0001-01-01T00:00:00Z",
"LastSeen": "0001-01-01T00:00:00Z",
"Count": 0,
"QPS": 0,
"Count": 3,
"QPS": 3,
"Rank": 0,
"Ratio": 134.33333333333334,
"QueryTime": {
@@ -21,7 +21,7 @@
"Median": 0
},
"ResponseLength": {
"Pct": 1,
"Pct": 100,
"Total": 1061660,
"Min": 215,
"Max": 1061230,