github.com/matrixorigin/matrixone@v0.7.0/pkg/util/metric/m_sql.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package metric 16 17 var ( 18 StatementCounterFactory = NewCounterVec( 19 CounterOpts{ 20 Subsystem: "sql", 21 Name: "statement_total", 22 Help: "Counter of executed sql statement", 23 }, 24 []string{constTenantKey, "type"}, 25 false, 26 ) 27 28 TransactionCounterFactory = NewCounterVec( 29 CounterOpts{ 30 Subsystem: "sql", 31 Name: "transaction_total", 32 Help: "Counter of transaction", 33 }, 34 []string{constTenantKey}, 35 false, 36 ) 37 38 TransactionErrorsFactory = NewCounterVec( 39 CounterOpts{ 40 Subsystem: "sql", 41 Name: "transaction_errors", 42 Help: "Counter of errors on execute commit/rollback statement", 43 }, 44 []string{constTenantKey, "type"}, 45 false, 46 ) 47 48 StatementErrorsFactory = NewCounterVec( 49 CounterOpts{ 50 Subsystem: "sql", 51 Name: "statement_errors", 52 Help: "Counter of executed sql statement failed.", 53 }, 54 []string{constTenantKey, "type"}, 55 false, 56 ) 57 ) 58 59 type SQLType string 60 61 var ( 62 SQLTypeSelect SQLType = "select" 63 SQLTypeInsert SQLType = "insert" 64 SQLTypeUpdate SQLType = "update" 65 SQLTypeDelete SQLType = "delete" 66 SQLTypeOther SQLType = "other" 67 68 SQLTypeBegin SQLType = "begin" 69 SQLTypeCommit SQLType = "commit" 70 SQLTypeRollback SQLType = "rollback" 71 SQLTypeAutoCommit SQLType = "auto_commit" 72 SQLTypeAutoRollback SQLType = "auto_rollback" 73 ) 74 75 // StatementCounter accept t as tree.QueryType 76 func StatementCounter(tenant string, t string) Counter { 77 return StatementCounterFactory.WithLabelValues(tenant, t) 78 } 79 80 func TransactionCounter(tenant string) Counter { 81 return TransactionCounterFactory.WithLabelValues(tenant) 82 } 83 84 func TransactionErrorsCounter(account string, t SQLType) Counter { 85 return TransactionErrorsFactory.WithLabelValues(account, string(t)) 86 } 87 88 // StatementErrorsCounter accept t as tree.QueryType 89 func StatementErrorsCounter(account string, t string) Counter { 90 return StatementErrorsFactory.WithLabelValues(account, t) 91 }