vitess.io/vitess@v0.16.2/go/vt/vttablet/endtoend/framework/querystats.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package framework 18 19 import ( 20 "encoding/json" 21 "fmt" 22 "net/http" 23 ) 24 25 // QueryStat contains the stats for one query. 26 type QueryStat struct { 27 Query, Table, Plan string 28 QueryCount, Time, MysqlTime, RowsAffected, RowsReturned, ErrorCount int 29 } 30 31 // QueryStats parses /debug/query_stats and returns 32 // a map of the query stats keyed by the query. 33 func QueryStats() map[string]QueryStat { 34 out := make(map[string]QueryStat) 35 var list []QueryStat 36 response, err := http.Get(fmt.Sprintf("%s/debug/query_stats", ServerAddress)) 37 if err != nil { 38 return out 39 } 40 defer response.Body.Close() 41 _ = json.NewDecoder(response.Body).Decode(&list) 42 for _, stat := range list { 43 out[stat.Query] = stat 44 } 45 return out 46 }