Exemplo n.º 1
0
func TestStringMetric(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	defer h.Stop()

	m := &gmetric.Metric{
		Name:         "string_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",
	})
}
Exemplo n.º 2
0
func TestHostnameFromClient(t *testing.T) {
	t.Parallel()
	h := gmondtest.NewHarness(t)
	h.Client.Host = "localhost"
	defer h.Stop()

	m := &gmetric.Metric{
		Name:         "hostname_from_client_metric",
		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",
	})
}
Exemplo n.º 3
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")
}
Exemplo n.º 4
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")
}
Exemplo n.º 5
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},
			},
		},
	})
}
Exemplo n.º 6
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},
			},
		},
	})
}