This commit is contained in:
jiangyong 2024-01-21 23:03:18 +08:00
parent d38dfb6f82
commit e74b213fd6
2 changed files with 10 additions and 9 deletions

View File

@ -8,11 +8,14 @@ import (
func TestName(t *testing.T) { func TestName(t *testing.T) {
c := NewConfg() c := NewConfg()
c.Address = "http://14.22.116.197:9305" c.Address = "http://influx.dev.batiao8.com"
c.Username = "batiao"
c.Password = "Batiao12B"
c.Interval = 1 c.Interval = 1
Init(c) Init(c)
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
Metric("test.test.b", float64(rand.Int()%100), map[string]string{ Duration("test.test.a1", int64(rand.Int()%100), map[string]string{
"a": "b", "a": "b",
"c": "d", "c": "d",
}) })
@ -25,7 +28,7 @@ func TestMetric(t *testing.T) {
c.Address = "https://monitor.batiao8.com" c.Address = "https://monitor.batiao8.com"
Init(c) Init(c)
Metric("test.test1.test2", 12, map[string]string{ Count("test.test.b", 12, map[string]string{
"a": "b", "a": "b",
"c": "d", "c": "d",
}) })

View File

@ -130,8 +130,8 @@ func (s *service) report() {
bp.Database = s.config.Database bp.Database = s.config.Database
bp.Tags = s.defaultTags() bp.Tags = s.defaultTags()
s.client.Write(bp) _, err := s.client.Write(bp)
fmt.Println("ok write") fmt.Println(err)
s.megers = nil s.megers = nil
} }
@ -147,17 +147,15 @@ func (s *service) getField(m *metric) map[string]interface{} {
if m.Type == TypeCount { if m.Type == TypeCount {
return map[string]interface{}{ return map[string]interface{}{
"count": m.Count, "count": m.Value,
"value": m.Value,
} }
} }
if m.Type == TypeDuration { if m.Type == TypeDuration {
avgMs := float64(m.Value) / float64(m.Count) avgMs := int64(float64(m.Value) / float64(m.Count))
return map[string]interface{}{ return map[string]interface{}{
"avg": avgMs, "avg": avgMs,
"count": m.Count, "count": m.Count,
"value": m.Value,
"max": m.Max, "max": m.Max,
"min": m.Min, "min": m.Min,
} }