Rename metrics

This commit is contained in:
9seconds
2021-03-29 11:03:54 +03:00
parent 4c3f42e264
commit 36d695118e
5 changed files with 75 additions and 100 deletions
+7 -42
View File
@@ -1,51 +1,16 @@
package stats
import (
"net"
"strconv"
"time"
import statsd "github.com/smira/go-statsd"
statsd "github.com/smira/go-statsd"
)
type streamInfo map[string]string
type streamInfo struct {
startTime time.Time
tags map[string]string
func (s streamInfo) T(key string) statsd.Tag {
return statsd.StringTag(key, s[key])
}
func (s *streamInfo) SetStartTime(tme time.Time) {
s.startTime = tme
}
func (s *streamInfo) SetClientIP(ip net.IP) {
if ip.To4() != nil {
s.tags[TagIPFamily] = TagIPFamilyIPv4
} else {
s.tags[TagIPFamily] = TagIPFamilyIPv6
}
}
func (s *streamInfo) SetTelegramIP(ip net.IP) {
s.tags[TagTelegramIP] = ip.String()
}
func (s *streamInfo) SetDC(dc int) {
s.tags[TagDC] = strconv.Itoa(dc)
}
func (s *streamInfo) V(key string) string {
return s.tags[key]
}
func (s *streamInfo) TV(key string) statsd.Tag {
return statsd.StringTag(key, s.tags[key])
}
func (s *streamInfo) Reset() {
s.startTime = time.Time{}
for k := range s.tags {
delete(s.tags, k)
func (s streamInfo) Reset() {
for k := range s {
delete(s, k)
}
}