func TestCanSend(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	defer h.Stop()

	m := &gmetric.Metric{
		Name:         "uint8_metric",
		Host:         "localhost",
		ValueType:    gmetric.ValueUint8,
		Units:        "count",
		Slope:        gmetric.SlopeBoth,
		TickInterval: 20 * time.Second,
		Lifetime:     24 * time.Hour,
	}
	const val = 10

	if err := h.Client.WriteMeta(m); err != nil {
		t.Fatal(err)
	}

	if err := h.Client.WriteValue(m, val); err != nil {
		t.Fatal(err)
	}

	h.ContainsMetric(&gmon.Metric{
		Name:  m.Name,
		Value: fmt.Sprint(val),
		Unit:  m.Units,
		Tn:    1,
		Tmax:  20,
		Slope: "both",
	})
}
Exemple #2
0
func TestNoName(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	defer h.Stop()

	m := &gmetric.Metric{}
	errContains(t, h.Client.WriteMeta(m), "gmetric: metric has no name")
	errContains(t, h.Client.WriteValue(m, "val"), "gmetric: metric has no name")
}
Exemple #3
0
func TestNoValueType(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	defer h.Stop()

	m := &gmetric.Metric{
		Name: "no_value_type_metric",
	}
	errContains(t, h.Client.WriteMeta(m), "gmetric: metric has no ValueType")
	errContains(t, h.Client.WriteValue(m, "val"), "gmetric: metric has no ValueType")
}
Exemple #4
0
func TestExtras(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	defer h.Stop()

	m := &gmetric.Metric{
		Name:         "extras_metric",
		Spoof:        "127.0.0.1:localhost_spoof",
		Title:        "the simple title",
		Description:  "the simple description",
		Host:         "localhost",
		Groups:       []string{"simple_group1", "simple_group2"},
		ValueType:    gmetric.ValueString,
		Units:        "count",
		Slope:        gmetric.SlopeBoth,
		TickInterval: 20 * time.Second,
		Lifetime:     24 * time.Hour,
	}
	const val = "hello"

	if err := h.Client.WriteMeta(m); err != nil {
		t.Fatal(err)
	}

	if err := h.Client.WriteValue(m, val); err != nil {
		t.Fatal(err)
	}

	h.ContainsMetric(&gmon.Metric{
		Name:  m.Name,
		Unit:  m.Units,
		Value: val,
		Tn:    1,
		Tmax:  20,
		Slope: "both",
		ExtraData: gmon.ExtraData{
			ExtraElements: []gmon.ExtraElement{
				gmon.ExtraElement{Name: "GROUP", Val: m.Groups[1]},
				gmon.ExtraElement{Name: "GROUP", Val: m.Groups[0]},
				gmon.ExtraElement{Name: "SPOOF_HOST", Val: m.Spoof},
				gmon.ExtraElement{Name: "DESC", Val: m.Description},
				gmon.ExtraElement{Name: "TITLE", Val: m.Title},
			},
		},
	})
}
Exemple #5
0
func TestSpoofFromClient(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	h.Client.Spoof = "127.0.0.1:localhost_spoof"
	defer h.Stop()

	m := &gmetric.Metric{
		Name:         "spoof_from_client_metric",
		Host:         "localhost",
		ValueType:    gmetric.ValueString,
		Units:        "count",
		Slope:        gmetric.SlopeBoth,
		TickInterval: 20 * time.Second,
		Lifetime:     24 * time.Hour,
	}
	const val = "hello"

	if err := h.Client.WriteMeta(m); err != nil {
		t.Fatal(err)
	}

	if err := h.Client.WriteValue(m, val); err != nil {
		t.Fatal(err)
	}

	h.ContainsMetric(&gmon.Metric{
		Name:  m.Name,
		Unit:  m.Units,
		Value: val,
		Tn:    1,
		Tmax:  20,
		Slope: "both",
		ExtraData: gmon.ExtraData{
			ExtraElements: []gmon.ExtraElement{
				gmon.ExtraElement{Name: "SPOOF_HOST", Val: h.Client.Spoof},
			},
		},
	})
}