dubbo.apache.org/dubbo-go/v3@v3.1.1/metrics/registry/event.go (about) 1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package registry 19 20 import ( 21 "time" 22 ) 23 24 import ( 25 "dubbo.apache.org/dubbo-go/v3/common/constant" 26 "dubbo.apache.org/dubbo-go/v3/metrics" 27 ) 28 29 // RegistryMetricsEvent contains info about register metrics 30 type RegistryMetricsEvent struct { 31 Name MetricName 32 Succ bool 33 Start time.Time 34 End time.Time 35 Attachment map[string]string 36 } 37 38 func (r RegistryMetricsEvent) Type() string { 39 return constant.MetricsRegistry 40 } 41 42 func (r *RegistryMetricsEvent) CostMs() float64 { 43 return float64(r.End.Sub(r.Start)) / float64(time.Millisecond) 44 } 45 46 // NewRegisterEvent for register metrics 47 func NewRegisterEvent(succ bool, start time.Time) metrics.MetricsEvent { 48 return &RegistryMetricsEvent{ 49 Name: Reg, 50 Succ: succ, 51 Start: start, 52 End: time.Now(), 53 } 54 } 55 56 // NewSubscribeEvent for subscribe metrics 57 func NewSubscribeEvent(succ bool) metrics.MetricsEvent { 58 return &RegistryMetricsEvent{ 59 Name: Sub, 60 Succ: succ, 61 } 62 } 63 64 // NewNotifyEvent for notify metrics 65 func NewNotifyEvent(start time.Time) metrics.MetricsEvent { 66 return &RegistryMetricsEvent{ 67 Name: Notify, 68 Start: start, 69 End: time.Now(), 70 } 71 } 72 73 // NewDirectoryEvent for directory metrics 74 func NewDirectoryEvent(dirTyp string) metrics.MetricsEvent { 75 return &RegistryMetricsEvent{ 76 Name: Directory, 77 Attachment: map[string]string{"DirTyp": dirTyp}, 78 } 79 } 80 81 // NewServerRegisterEvent for server register metrics 82 func NewServerRegisterEvent(succ bool, start time.Time) metrics.MetricsEvent { 83 return &RegistryMetricsEvent{ 84 Name: ServerReg, 85 Succ: succ, 86 Start: start, 87 End: time.Now(), 88 } 89 } 90 91 // NewServerSubscribeEvent for server subscribe metrics 92 func NewServerSubscribeEvent(succ bool) metrics.MetricsEvent { 93 return &RegistryMetricsEvent{ 94 Name: ServerSub, 95 Succ: succ, 96 } 97 }