2021-11-03 11:27:24 +00:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2021-05-21 13:48:04 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
2023-04-11 02:32:31 +00:00
|
|
|
// #nosec
|
2021-12-23 03:39:10 +00:00
|
|
|
_ "net/http/pprof"
|
|
|
|
|
2021-06-01 03:04:31 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2021-05-21 13:48:04 +00:00
|
|
|
)
|
|
|
|
|
2021-06-01 08:10:32 +00:00
|
|
|
const (
|
2021-12-13 02:31:17 +00:00
|
|
|
milvusNamespace = "milvus"
|
2022-03-02 08:23:55 +00:00
|
|
|
|
|
|
|
AbandonLabel = "abandon"
|
2022-03-03 08:05:57 +00:00
|
|
|
SuccessLabel = "success"
|
|
|
|
FailLabel = "fail"
|
2024-07-04 07:23:08 +00:00
|
|
|
CancelLabel = "cancel"
|
2022-03-03 08:05:57 +00:00
|
|
|
TotalLabel = "total"
|
2022-03-02 08:23:55 +00:00
|
|
|
|
2024-01-08 07:34:48 +00:00
|
|
|
HybridSearchLabel = "hybrid_search"
|
|
|
|
|
2022-11-07 02:15:02 +00:00
|
|
|
InsertLabel = "insert"
|
|
|
|
DeleteLabel = "delete"
|
2023-01-04 09:21:36 +00:00
|
|
|
UpsertLabel = "upsert"
|
2022-11-07 02:15:02 +00:00
|
|
|
SearchLabel = "search"
|
|
|
|
QueryLabel = "query"
|
2022-03-02 08:23:55 +00:00
|
|
|
CacheHitLabel = "hit"
|
|
|
|
CacheMissLabel = "miss"
|
2022-11-07 02:15:02 +00:00
|
|
|
TimetickLabel = "timetick"
|
|
|
|
AllLabel = "all"
|
2022-03-03 08:05:57 +00:00
|
|
|
|
|
|
|
UnissuedIndexTaskLabel = "unissued"
|
|
|
|
InProgressIndexTaskLabel = "in-progress"
|
|
|
|
FinishedIndexTaskLabel = "finished"
|
|
|
|
FailedIndexTaskLabel = "failed"
|
|
|
|
RecycledIndexTaskLabel = "recycled"
|
|
|
|
|
2022-11-22 11:21:13 +00:00
|
|
|
// Note: below must matchcommonpb.SegmentState_name fields.
|
2022-03-15 13:51:21 +00:00
|
|
|
SealedSegmentLabel = "Sealed"
|
|
|
|
GrowingSegmentLabel = "Growing"
|
|
|
|
FlushedSegmentLabel = "Flushed"
|
|
|
|
FlushingSegmentLabel = "Flushing"
|
2022-11-22 11:21:13 +00:00
|
|
|
DroppedSegmentLabel = "Dropped"
|
2022-03-15 13:51:21 +00:00
|
|
|
|
2024-09-28 09:31:15 +00:00
|
|
|
StreamingDataSourceLabel = "streaming"
|
|
|
|
BulkinsertDataSourceLabel = "bulkinsert"
|
|
|
|
|
2022-11-10 03:51:03 +00:00
|
|
|
Leader = "OnLeader"
|
|
|
|
FromLeader = "FromLeader"
|
|
|
|
|
2023-02-13 08:50:33 +00:00
|
|
|
HookBefore = "before"
|
|
|
|
HookAfter = "after"
|
|
|
|
HookMock = "mock"
|
|
|
|
|
2023-07-11 10:18:28 +00:00
|
|
|
ReduceSegments = "segments"
|
|
|
|
ReduceShards = "shards"
|
|
|
|
|
2024-05-06 12:29:30 +00:00
|
|
|
BatchReduce = "batch_reduce"
|
|
|
|
StreamReduce = "stream_reduce"
|
|
|
|
|
2023-12-28 07:46:55 +00:00
|
|
|
Pending = "pending"
|
|
|
|
Executing = "executing"
|
|
|
|
Done = "done"
|
|
|
|
|
2024-10-09 06:41:20 +00:00
|
|
|
ImportStagePending = "pending"
|
|
|
|
ImportStagePreImport = "preimport"
|
|
|
|
ImportStageImport = "import"
|
|
|
|
ImportStageStats = "stats"
|
|
|
|
ImportStageBuildIndex = "build_index"
|
|
|
|
|
2023-12-28 07:46:55 +00:00
|
|
|
compactionTypeLabelName = "compaction_type"
|
2024-06-10 13:34:08 +00:00
|
|
|
isVectorFieldLabelName = "is_vector_field"
|
2024-07-08 11:54:15 +00:00
|
|
|
segmentPruneLabelName = "segment_prune_label"
|
2024-06-10 13:34:08 +00:00
|
|
|
stageLabelName = "compaction_stage"
|
2022-03-15 13:51:21 +00:00
|
|
|
nodeIDLabelName = "node_id"
|
2024-12-13 06:14:50 +00:00
|
|
|
nodeHostLabelName = "node_host"
|
2022-03-15 13:51:21 +00:00
|
|
|
statusLabelName = "status"
|
|
|
|
indexTaskStatusLabelName = "index_task_status"
|
|
|
|
msgTypeLabelName = "msg_type"
|
|
|
|
collectionIDLabelName = "collection_id"
|
|
|
|
channelNameLabelName = "channel_name"
|
|
|
|
functionLabelName = "function_name"
|
|
|
|
queryTypeLabelName = "query_type"
|
2022-10-18 11:17:27 +00:00
|
|
|
collectionName = "collection_name"
|
2024-04-01 02:21:21 +00:00
|
|
|
databaseLabelName = "db_name"
|
2024-12-13 06:14:50 +00:00
|
|
|
ResourceGroupLabelName = "rg"
|
2024-03-19 07:23:06 +00:00
|
|
|
indexName = "index_name"
|
|
|
|
isVectorIndex = "is_vector_index"
|
2022-04-27 15:03:47 +00:00
|
|
|
segmentStateLabelName = "segment_state"
|
2023-11-24 07:58:24 +00:00
|
|
|
segmentLevelLabelName = "segment_level"
|
2024-09-30 02:01:16 +00:00
|
|
|
segmentIsSortedLabelName = "segment_is_sorted"
|
2022-04-11 11:49:34 +00:00
|
|
|
usernameLabelName = "username"
|
2022-11-02 02:55:34 +00:00
|
|
|
roleNameLabelName = "role_name"
|
2022-04-27 15:03:47 +00:00
|
|
|
cacheNameLabelName = "cache_name"
|
|
|
|
cacheStateLabelName = "cache_state"
|
2024-09-28 09:31:15 +00:00
|
|
|
dataSourceLabelName = "data_source"
|
2024-10-09 06:41:20 +00:00
|
|
|
importStageLabelName = "import_stage"
|
2022-11-10 03:51:03 +00:00
|
|
|
requestScope = "scope"
|
2023-02-13 08:50:33 +00:00
|
|
|
fullMethodLabelName = "full_method"
|
2023-07-11 10:18:28 +00:00
|
|
|
reduceLevelName = "reduce_level"
|
2024-05-06 12:29:30 +00:00
|
|
|
reduceType = "reduce_type"
|
2023-08-03 07:03:06 +00:00
|
|
|
lockName = "lock_name"
|
|
|
|
lockSource = "lock_source"
|
|
|
|
lockType = "lock_type"
|
|
|
|
lockOp = "lock_op"
|
2024-03-08 07:39:02 +00:00
|
|
|
loadTypeName = "load_type"
|
2024-07-28 16:13:47 +00:00
|
|
|
pathLabelName = "path"
|
2024-11-07 02:06:25 +00:00
|
|
|
cgoNameLabelName = `cgo_name`
|
|
|
|
cgoTypeLabelName = `cgo_type`
|
2024-03-19 07:23:06 +00:00
|
|
|
|
|
|
|
// entities label
|
|
|
|
LoadedLabel = "loaded"
|
|
|
|
NumEntitiesAllLabel = "all"
|
2024-03-20 11:29:06 +00:00
|
|
|
|
2024-09-02 06:19:03 +00:00
|
|
|
taskTypeLabel = "task_type"
|
|
|
|
taskStateLabel = "task_state"
|
2022-03-03 08:05:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// buckets involves durations in milliseconds,
|
|
|
|
// [1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 1.31072e+05]
|
|
|
|
buckets = prometheus.ExponentialBuckets(1, 2, 18)
|
2023-06-26 09:52:44 +00:00
|
|
|
|
2023-09-22 10:47:25 +00:00
|
|
|
// longTaskBuckets provides long task duration in milliseconds
|
|
|
|
longTaskBuckets = []float64{1, 100, 500, 1000, 5000, 10000, 20000, 50000, 100000, 250000, 500000, 1000000, 3600000, 5000000, 10000000} // unit milliseconds
|
|
|
|
|
2024-01-26 02:53:02 +00:00
|
|
|
// size provides size in byte
|
|
|
|
sizeBuckets = []float64{10000, 100000, 1000000, 100000000, 500000000, 1024000000, 2048000000, 4096000000, 10000000000, 50000000000} // unit byte
|
|
|
|
|
2023-06-26 09:52:44 +00:00
|
|
|
NumNodes = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: milvusNamespace,
|
|
|
|
Name: "num_node",
|
|
|
|
Help: "number of nodes and coordinates",
|
|
|
|
}, []string{nodeIDLabelName, roleNameLabelName})
|
2023-08-03 07:03:06 +00:00
|
|
|
|
|
|
|
LockCosts = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: milvusNamespace,
|
|
|
|
Name: "lock_time_cost",
|
|
|
|
Help: "time cost for various kinds of locks",
|
|
|
|
}, []string{
|
|
|
|
lockName,
|
|
|
|
lockSource,
|
|
|
|
lockType,
|
|
|
|
lockOp,
|
|
|
|
})
|
2023-09-13 04:03:19 +00:00
|
|
|
|
|
|
|
metricRegisterer prometheus.Registerer
|
2021-06-01 08:10:32 +00:00
|
|
|
)
|
2023-06-26 09:52:44 +00:00
|
|
|
|
2023-09-13 04:03:19 +00:00
|
|
|
// GetRegisterer returns the global prometheus registerer
|
|
|
|
// metricsRegistry must be call after Register is called or no Register is called.
|
|
|
|
func GetRegisterer() prometheus.Registerer {
|
|
|
|
if metricRegisterer == nil {
|
|
|
|
return prometheus.DefaultRegisterer
|
|
|
|
}
|
|
|
|
return metricRegisterer
|
|
|
|
}
|
|
|
|
|
2023-06-26 09:52:44 +00:00
|
|
|
// Register serves prometheus http service
|
2023-09-13 04:03:19 +00:00
|
|
|
// Should be called by init function.
|
|
|
|
func Register(r prometheus.Registerer) {
|
2023-06-26 09:52:44 +00:00
|
|
|
r.MustRegister(NumNodes)
|
2023-08-03 07:03:06 +00:00
|
|
|
r.MustRegister(LockCosts)
|
2024-01-29 07:47:02 +00:00
|
|
|
r.MustRegister(BuildInfo)
|
|
|
|
r.MustRegister(RuntimeInfo)
|
2024-11-22 02:20:33 +00:00
|
|
|
r.MustRegister(ThreadNum)
|
2023-09-13 04:03:19 +00:00
|
|
|
metricRegisterer = r
|
2023-06-26 09:52:44 +00:00
|
|
|
}
|