forked from vitessio/vitess
/
querystats.go
34 lines (30 loc) · 849 Bytes
/
querystats.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
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package framework
import (
"encoding/json"
"fmt"
"net/http"
)
// QueryStat contains the stats for one query.
type QueryStat struct {
Query, Table, Plan string
QueryCount, Time, RowCount, ErrorCount int
}
// QueryStats parses /debug/query_stats and returns
// a map of the query stats keyed by the query.
func QueryStats() map[string]QueryStat {
out := make(map[string]QueryStat)
var list []QueryStat
response, err := http.Get(fmt.Sprintf("%s/debug/query_stats", ServerAddress))
if err != nil {
return out
}
defer response.Body.Close()
_ = json.NewDecoder(response.Body).Decode(&list)
for _, stat := range list {
out[stat.Query] = stat
}
return out
}