github.com/matrixorigin/matrixone@v1.2.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 StatementDurationFactory = NewCounterVec( 29 CounterOpts{ 30 Subsystem: "sql", 31 Name: "statement_duration_total", 32 Help: "Statement duration of each query type for each account", 33 }, 34 []string{constTenantKey, "type"}, 35 false, 36 ) 37 38 TransactionCounterFactory = NewCounterVec( 39 CounterOpts{ 40 Subsystem: "sql", 41 Name: "transaction_total", 42 Help: "Counter of transaction", 43 }, 44 []string{constTenantKey}, 45 false, 46 ) 47 48 TransactionErrorsFactory = NewCounterVec( 49 CounterOpts{ 50 Subsystem: "sql", 51 Name: "transaction_errors", 52 Help: "Counter of errors on execute commit/rollback statement", 53 }, 54 []string{constTenantKey, "type"}, 55 false, 56 ) 57 58 StatementErrorsFactory = NewCounterVec( 59 CounterOpts{ 60 Subsystem: "sql", 61 Name: "statement_errors", 62 Help: "Counter of executed sql statement failed.", 63 }, 64 []string{constTenantKey, "type"}, 65 false, 66 ) 67 68 StatementCUCounterFactory = NewCounterVec( 69 CounterOpts{ 70 Subsystem: "sql", 71 Name: "statement_cu", 72 Help: "Counter of executed sql statement cu", 73 }, 74 []string{constTenantKey, "sql_source_type"}, 75 false, 76 ) 77 ) 78 79 type SQLType string 80 81 var ( 82 SQLTypeSelect SQLType = "select" 83 SQLTypeInsert SQLType = "insert" 84 SQLTypeUpdate SQLType = "update" 85 SQLTypeDelete SQLType = "delete" 86 SQLTypeOther SQLType = "other" 87 88 SQLTypeBegin SQLType = "begin" 89 SQLTypeCommit SQLType = "commit" 90 SQLTypeRollback SQLType = "rollback" 91 SQLTypeAutoCommit SQLType = "auto_commit" 92 SQLTypeAutoRollback SQLType = "auto_rollback" 93 ) 94 95 // StatementCounter accept t as tree.QueryType 96 func StatementCounter(tenant string, t string) Counter { 97 return StatementCounterFactory.WithLabelValues(tenant, t) 98 } 99 100 func StatementDuration(tenant string, t string) Counter { 101 return StatementDurationFactory.WithLabelValues(tenant, t) 102 } 103 104 func TransactionCounter(tenant string) Counter { 105 return TransactionCounterFactory.WithLabelValues(tenant) 106 } 107 108 func TransactionErrorsCounter(account string, t SQLType) Counter { 109 return TransactionErrorsFactory.WithLabelValues(account, string(t)) 110 } 111 112 // StatementErrorsCounter accept t as tree.QueryType 113 func StatementErrorsCounter(account string, t string) Counter { 114 return StatementErrorsFactory.WithLabelValues(account, t) 115 } 116 117 // StatementCUCounter accept @account, @sqlSourceType 118 // @account is the account name of the user who executes the sql statement. 119 // @sqlSourceType is the type of sql source, such as InternalSql, CloudNoUserSql, ExternalSql, CloudUserSql etc. 120 func StatementCUCounter(account string, sqlSourceType string) Counter { 121 return StatementCUCounterFactory.WithLabelValues(account, sqlSourceType) 122 }