vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletserver/tabletenv/stats.go (about) 1 /* 2 Copyright 2020 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 tabletenv 18 19 import ( 20 "time" 21 22 "vitess.io/vitess/go/stats" 23 vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" 24 "vitess.io/vitess/go/vt/servenv" 25 ) 26 27 // Stats contains tracked by various parts of TabletServer. 28 type Stats struct { 29 MySQLTimings *servenv.TimingsWrapper // Time spent executing MySQL commands 30 QueryTimings *servenv.TimingsWrapper // Query timings 31 QPSRates *stats.Rates // Human readable QPS rates 32 WaitTimings *servenv.TimingsWrapper // waits like Consolidations etc 33 KillCounters *stats.CountersWithSingleLabel // Connection and transaction kills 34 ErrorCounters *stats.CountersWithSingleLabel 35 InternalErrors *stats.CountersWithSingleLabel 36 Warnings *stats.CountersWithSingleLabel 37 Unresolved *stats.GaugesWithSingleLabel // For now, only Prepares are tracked 38 UserTableQueryCount *stats.CountersWithMultiLabels // Per CallerID/table counts 39 UserTableQueryTimesNs *stats.CountersWithMultiLabels // Per CallerID/table latencies 40 UserTransactionCount *stats.CountersWithMultiLabels // Per CallerID transaction counts 41 UserTransactionTimesNs *stats.CountersWithMultiLabels // Per CallerID transaction latencies 42 ResultHistogram *stats.Histogram // Row count histograms 43 TableaclAllowed *stats.CountersWithMultiLabels // Number of allows 44 TableaclDenied *stats.CountersWithMultiLabels // Number of denials 45 TableaclPseudoDenied *stats.CountersWithMultiLabels // Number of pseudo denials 46 47 UserActiveReservedCount *stats.CountersWithSingleLabel // Per CallerID active reserved connection counts 48 UserReservedCount *stats.CountersWithSingleLabel // Per CallerID reserved connection counts 49 UserReservedTimesNs *stats.CountersWithSingleLabel // Per CallerID reserved connection duration 50 } 51 52 // NewStats instantiates a new set of stats scoped by exporter. 53 func NewStats(exporter *servenv.Exporter) *Stats { 54 stats := &Stats{ 55 MySQLTimings: exporter.NewTimings("Mysql", "MySQl query time", "operation"), 56 QueryTimings: exporter.NewTimings("Queries", "MySQL query timings", "plan_type"), 57 WaitTimings: exporter.NewTimings("Waits", "Wait operations", "type"), 58 KillCounters: exporter.NewCountersWithSingleLabel("Kills", "Number of connections being killed", "query_type", "Transactions", "Queries", "ReservedConnection"), 59 ErrorCounters: exporter.NewCountersWithSingleLabel( 60 "Errors", 61 "Critical errors", 62 "error_code", 63 vtrpcpb.Code_OK.String(), 64 vtrpcpb.Code_CANCELED.String(), 65 vtrpcpb.Code_UNKNOWN.String(), 66 vtrpcpb.Code_INVALID_ARGUMENT.String(), 67 vtrpcpb.Code_DEADLINE_EXCEEDED.String(), 68 vtrpcpb.Code_NOT_FOUND.String(), 69 vtrpcpb.Code_ALREADY_EXISTS.String(), 70 vtrpcpb.Code_PERMISSION_DENIED.String(), 71 vtrpcpb.Code_UNAUTHENTICATED.String(), 72 vtrpcpb.Code_RESOURCE_EXHAUSTED.String(), 73 vtrpcpb.Code_FAILED_PRECONDITION.String(), 74 vtrpcpb.Code_ABORTED.String(), 75 vtrpcpb.Code_OUT_OF_RANGE.String(), 76 vtrpcpb.Code_UNIMPLEMENTED.String(), 77 vtrpcpb.Code_INTERNAL.String(), 78 vtrpcpb.Code_UNAVAILABLE.String(), 79 vtrpcpb.Code_DATA_LOSS.String(), 80 vtrpcpb.Code_CLUSTER_EVENT.String(), 81 ), 82 InternalErrors: exporter.NewCountersWithSingleLabel("InternalErrors", "Internal component errors", "type", "Task", "StrayTransactions", "Panic", "HungQuery", "Schema", "TwopcCommit", "TwopcResurrection", "WatchdogFail", "Messages"), 83 Warnings: exporter.NewCountersWithSingleLabel("Warnings", "Warnings", "type", "ResultsExceeded"), 84 Unresolved: exporter.NewGaugesWithSingleLabel("Unresolved", "Unresolved items", "item_type", "Prepares"), 85 UserTableQueryCount: exporter.NewCountersWithMultiLabels("UserTableQueryCount", "Queries received for each CallerID/table combination", []string{"TableName", "CallerID", "Type"}), 86 UserTableQueryTimesNs: exporter.NewCountersWithMultiLabels("UserTableQueryTimesNs", "Total latency for each CallerID/table combination", []string{"TableName", "CallerID", "Type"}), 87 UserTransactionCount: exporter.NewCountersWithMultiLabels("UserTransactionCount", "transactions received for each CallerID", []string{"CallerID", "Conclusion"}), 88 UserTransactionTimesNs: exporter.NewCountersWithMultiLabels("UserTransactionTimesNs", "Total transaction latency for each CallerID", []string{"CallerID", "Conclusion"}), 89 ResultHistogram: exporter.NewHistogram("Results", "Distribution of rows returned", []int64{0, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000}), 90 TableaclAllowed: exporter.NewCountersWithMultiLabels("TableACLAllowed", "ACL acceptances", []string{"TableName", "TableGroup", "PlanID", "Username"}), 91 TableaclDenied: exporter.NewCountersWithMultiLabels("TableACLDenied", "ACL denials", []string{"TableName", "TableGroup", "PlanID", "Username"}), 92 TableaclPseudoDenied: exporter.NewCountersWithMultiLabels("TableACLPseudoDenied", "ACL pseudodenials", []string{"TableName", "TableGroup", "PlanID", "Username"}), 93 94 UserActiveReservedCount: exporter.NewCountersWithSingleLabel("UserActiveReservedCount", "active reserved connection for each CallerID", "CallerID"), 95 UserReservedCount: exporter.NewCountersWithSingleLabel("UserReservedCount", "reserved connection received for each CallerID", "CallerID"), 96 UserReservedTimesNs: exporter.NewCountersWithSingleLabel("UserReservedTimesNs", "Total reserved connection latency for each CallerID", "CallerID"), 97 } 98 stats.QPSRates = exporter.NewRates("QPS", stats.QueryTimings, 15*60/5, 5*time.Second) 99 return stats 100 }