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) {
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",
})

View File

@ -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,
}