From e74b213fd68a85e1a69c30d151d3c9770414f9e8 Mon Sep 17 00:00:00 2001 From: jiangyong Date: Sun, 21 Jan 2024 23:03:18 +0800 Subject: [PATCH] duration --- metric/metric_test.go | 9 ++++++--- metric/service.go | 10 ++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/metric/metric_test.go b/metric/metric_test.go index 4e9a813..2800c66 100644 --- a/metric/metric_test.go +++ b/metric/metric_test.go @@ -8,11 +8,14 @@ import ( func TestName(t *testing.T) { 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 Init(c) 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", "c": "d", }) @@ -25,7 +28,7 @@ func TestMetric(t *testing.T) { c.Address = "https://monitor.batiao8.com" Init(c) - Metric("test.test1.test2", 12, map[string]string{ + Count("test.test.b", 12, map[string]string{ "a": "b", "c": "d", }) diff --git a/metric/service.go b/metric/service.go index 5afbc47..94acf45 100644 --- a/metric/service.go +++ b/metric/service.go @@ -130,8 +130,8 @@ func (s *service) report() { bp.Database = s.config.Database bp.Tags = s.defaultTags() - s.client.Write(bp) - fmt.Println("ok write") + _, err := s.client.Write(bp) + fmt.Println(err) s.megers = nil } @@ -147,17 +147,15 @@ func (s *service) getField(m *metric) map[string]interface{} { if m.Type == TypeCount { return map[string]interface{}{ - "count": m.Count, - "value": m.Value, + "count": m.Value, } } if m.Type == TypeDuration { - avgMs := float64(m.Value) / float64(m.Count) + avgMs := int64(float64(m.Value) / float64(m.Count)) return map[string]interface{}{ "avg": avgMs, "count": m.Count, - "value": m.Value, "max": m.Max, "min": m.Min, }