github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/m_register.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  import prom "github.com/prometheus/client_golang/prometheus"
    18  
    19  const constTenantKey = "account"
    20  
    21  // this constant lable is used for sys_* and process_* table
    22  var sysTenantID = prom.Labels{constTenantKey: "sys"}
    23  
    24  // InitCollectors contains all the collectors that belong to SubSystemSql, SubSystemServer, SubSystemProcess and
    25  // SubSystemStatement.
    26  var InitCollectors = []Collector{
    27  	// sql metric
    28  	StatementCounterFactory,
    29  	StatementErrorsFactory,
    30  	StatementCUCounterFactory,
    31  	TransactionCounterFactory,
    32  	TransactionErrorsFactory,
    33  	StatementDurationFactory,
    34  	// server metric
    35  	ConnFactory,
    36  	StorageUsageFactory,
    37  	// process metric
    38  	processCollector,
    39  	// sys metric
    40  	hardwareStatsCollector,
    41  }
    42  
    43  // InternalCollectors contains all the collectors that belong to SubSystemMO
    44  var InternalCollectors = []Collector{
    45  	// mo metric
    46  	MOLogMessageFactory,
    47  }
    48  
    49  type SubSystem struct {
    50  	Name              string
    51  	Comment           string
    52  	SupportUserAccess bool
    53  }
    54  
    55  var AllSubSystem = map[string]*SubSystem{}
    56  
    57  func RegisterSubSystem(s *SubSystem) {
    58  	AllSubSystem[s.Name] = s
    59  }
    60  
    61  const (
    62  	// SubSystemSql is the subsystem which base on query action.
    63  	SubSystemSql = "sql"
    64  	// SubSystemServer is the subsystem which base on server status, trigger by client query.
    65  	SubSystemServer = "server"
    66  	// SubSystemProcess is the subsystem which base on process status.
    67  	SubSystemProcess = "process"
    68  	// SubSystemSys is the subsystem which base on OS status.
    69  	SubSystemSys = "sys"
    70  	// SubSystemMO is the subsystem which show mo internal status
    71  	SubSystemMO = "mo"
    72  )
    73  
    74  func init() {
    75  	RegisterSubSystem(&SubSystem{SubSystemSql, "base on query action", true})
    76  	RegisterSubSystem(&SubSystem{SubSystemServer, "MO Server status, observe from inside", true})
    77  	RegisterSubSystem(&SubSystem{SubSystemProcess, "MO process status", false})
    78  	RegisterSubSystem(&SubSystem{SubSystemSys, "OS status", false})
    79  	RegisterSubSystem(&SubSystem{SubSystemMO, "MO internal status", false})
    80  }