// Test that the parser parses kafka messages into points func TestRunParserAndGather(t *testing.T) { k, in := NewTestKafka() defer close(k.done) go k.parser() in <- saramaMsg(testMsg) time.Sleep(time.Millisecond) acc := testutil.Accumulator{} k.Gather(&acc) assert.Equal(t, len(acc.Points), 1) acc.AssertContainsFields(t, "cpu_load_short", map[string]interface{}{"value": float64(23422)}) }
func TestExec(t *testing.T) { e := &Exec{ runner: newRunnerMock([]byte(validJson), nil), Command: "testcommand arg1", } var acc testutil.Accumulator err := e.Gather(&acc) require.NoError(t, err) assert.Equal(t, acc.NFields(), 4, "non-numeric measurements should be ignored") fields := map[string]interface{}{ "num_processes": float64(82), "cpu_used": float64(8234), "cpu_free": float64(32), "percent": float64(0.81), } acc.AssertContainsFields(t, "exec", fields) }
func TestHTTPApache(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) fmt.Fprintln(w, apacheStatus) })) defer ts.Close() a := Apache{ Urls: []string{ts.URL}, } var acc testutil.Accumulator err := a.Gather(&acc) require.NoError(t, err) fields := map[string]interface{}{ "TotalAccesses": float64(1.29811861e+08), "TotalkBytes": float64(5.213701865e+09), "CPULoad": float64(6.51929), "Uptime": float64(941553), "ReqPerSec": float64(137.87), "BytesPerSec": float64(5.67024e+06), "BytesPerReq": float64(41127.4), "BusyWorkers": float64(270), "IdleWorkers": float64(630), "ConnsTotal": float64(1451), "ConnsAsyncWriting": float64(32), "ConnsAsyncKeepAlive": float64(945), "ConnsAsyncClosing": float64(205), "scboard_waiting": float64(630), "scboard_starting": float64(0), "scboard_reading": float64(157), "scboard_sending": float64(113), "scboard_keepalive": float64(0), "scboard_dnslookup": float64(0), "scboard_closing": float64(0), "scboard_logging": float64(0), "scboard_finishing": float64(0), "scboard_idle_cleanup": float64(0), "scboard_open": float64(2850), } acc.AssertContainsFields(t, "apache", fields) }
func TestTrig(t *testing.T) { s := &Trig{ Amplitude: 10.0, } for i := 0.0; i < 10.0; i++ { var acc testutil.Accumulator sine := math.Sin((i*math.Pi)/5.0) * s.Amplitude cosine := math.Cos((i*math.Pi)/5.0) * s.Amplitude s.Gather(&acc) fields := make(map[string]interface{}) fields["sine"] = sine fields["cosine"] = cosine acc.AssertContainsFields(t, "trig", fields) } }
func TestPrometheusWritePointTag(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } p := &prometheus.Prometheus{ Urls: []string{"http://localhost:9126/metrics"}, } tags := make(map[string]string) tags["testtag"] = "testvalue" pt1, _ := client.NewPoint( "test_point_3", tags, map[string]interface{}{"value": 0.0}) pt2, _ := client.NewPoint( "test_point_4", tags, map[string]interface{}{"value": 1.0}) var points = []*client.Point{ pt1, pt2, } require.NoError(t, pTesting.Write(points)) expected := []struct { name string value float64 }{ {"test_point_3", 0.0}, {"test_point_4", 1.0}, } var acc testutil.Accumulator require.NoError(t, p.Gather(&acc)) for _, e := range expected { acc.AssertContainsFields(t, "prometheus_"+e.name, map[string]interface{}{"value": e.value}) } }
func TestDisqueCanPullStatsFromMultipleServers(t *testing.T) { if testing.Short() { t.Skip("Skipping integration test in short mode") } l, err := net.Listen("tcp", "localhost:0") require.NoError(t, err) defer l.Close() go func() { c, err := l.Accept() if err != nil { return } buf := bufio.NewReader(c) for { line, err := buf.ReadString('\n') if err != nil { return } if line != "info\r\n" { return } fmt.Fprintf(c, "$%d\n", len(testOutput)) c.Write([]byte(testOutput)) } }() addr := fmt.Sprintf("disque://%s", l.Addr().String()) r := &Disque{ Servers: []string{addr}, } var acc testutil.Accumulator err = r.Gather(&acc) require.NoError(t, err) fields := map[string]interface{}{ "uptime": uint64(1452705), "clients": uint64(31), "blocked_clients": uint64(13), "used_memory": uint64(1840104), "used_memory_rss": uint64(3227648), "used_memory_peak": uint64(89603656), "total_connections_received": uint64(5062777), "total_commands_processed": uint64(12308396), "instantaneous_ops_per_sec": uint64(18), "latest_fork_usec": uint64(1644), "registered_jobs": uint64(360), "registered_queues": uint64(12), "mem_fragmentation_ratio": float64(1.75), "used_cpu_sys": float64(19585.73), "used_cpu_user": float64(11255.96), "used_cpu_sys_children": float64(1.75), "used_cpu_user_children": float64(1.91), } acc.AssertContainsFields(t, "disque", fields) }