func testIngestedSpansMetricsImpl(t *testing.T, usePacked bool) { htraceBld := &MiniHTracedBuilder{Name: "TestIngestedSpansMetrics", DataDirs: make([]string, 2), } ht, err := htraceBld.Build() if err != nil { t.Fatalf("failed to create datastore: %s", err.Error()) } defer ht.Close() var hcl *htrace.Client hcl, err = htrace.NewClient(ht.ClientConf(), &htrace.TestHooks{ HrpcDisabled: !usePacked, }) if err != nil { t.Fatalf("failed to create client: %s", err.Error()) } NUM_TEST_SPANS := 12 allSpans := createRandomTestSpans(NUM_TEST_SPANS) err = hcl.WriteSpans(allSpans) if err != nil { t.Fatalf("WriteSpans failed: %s\n", err.Error()) } for { var stats *common.ServerStats stats, err = hcl.GetServerStats() if err != nil { t.Fatalf("GetServerStats failed: %s\n", err.Error()) } if stats.IngestedSpans == uint64(NUM_TEST_SPANS) { break } time.Sleep(1 * time.Millisecond) } }
// Print information retrieved from an htraced server via /server/info as JSON func printServerStatsJson(hcl *htrace.Client) int { stats, err := hcl.GetServerStats() if err != nil { fmt.Println(err.Error()) return EXIT_FAILURE } buf, err := json.MarshalIndent(stats, "", " ") if err != nil { fmt.Printf("Error marshalling server stats: %s", err.Error()) return EXIT_FAILURE } fmt.Printf("%s\n", string(buf)) return EXIT_SUCCESS }
// Print information retrieved from an htraced server via /server/info func printServerStats(hcl *htrace.Client) int { stats, err := hcl.GetServerStats() if err != nil { fmt.Println(err.Error()) return EXIT_FAILURE } w := new(tabwriter.Writer) w.Init(os.Stdout, 0, 8, 0, '\t', 0) fmt.Fprintf(w, "HTRACED SERVER STATS\n") fmt.Fprintf(w, "Datastore Start\t%s\n", common.UnixMsToTime(stats.LastStartMs).Format(time.RFC3339)) fmt.Fprintf(w, "Server Time\t%s\n", common.UnixMsToTime(stats.CurMs).Format(time.RFC3339)) fmt.Fprintf(w, "Spans reaped\t%d\n", stats.ReapedSpans) fmt.Fprintf(w, "Spans ingested\t%d\n", stats.IngestedSpans) fmt.Fprintf(w, "Spans written\t%d\n", stats.WrittenSpans) fmt.Fprintf(w, "Spans dropped by server\t%d\n", stats.ServerDroppedSpans) dur := time.Millisecond * time.Duration(stats.AverageWriteSpansLatencyMs) fmt.Fprintf(w, "Average WriteSpan Latency\t%s\n", dur.String()) dur = time.Millisecond * time.Duration(stats.MaxWriteSpansLatencyMs) fmt.Fprintf(w, "Maximum WriteSpan Latency\t%s\n", dur.String()) fmt.Fprintf(w, "Number of leveldb directories\t%d\n", len(stats.Dirs)) w.Flush() fmt.Println("") for i := range stats.Dirs { dir := stats.Dirs[i] fmt.Printf("==== %s ===\n", dir.Path) fmt.Printf("Approximate number of bytes: %d\n", dir.ApproximateBytes) stats := strings.Replace(dir.LevelDbStats, "\\n", "\n", -1) fmt.Printf("%s\n", stats) } w = new(tabwriter.Writer) w.Init(os.Stdout, 0, 8, 0, '\t', 0) fmt.Fprintf(w, "HOST SPAN METRICS\n") mtxMap := stats.HostSpanMetrics keys := make(sort.StringSlice, len(mtxMap)) i := 0 for k, _ := range mtxMap { keys[i] = k i++ } sort.Sort(keys) for k := range keys { mtx := mtxMap[keys[k]] fmt.Fprintf(w, "%s\twritten: %d\tserver dropped: %d\n", keys[k], mtx.Written, mtx.ServerDropped) } w.Flush() return EXIT_SUCCESS }
// Print information retrieved from an htraced server via /server/info func printServerStats(hcl *htrace.Client) int { stats, err := hcl.GetServerStats() if err != nil { fmt.Println(err.Error()) return EXIT_FAILURE } fmt.Printf("HTraced server stats:\n") fmt.Printf("%d leveldb shards.\n", len(stats.Shards)) for i := range stats.Shards { shard := stats.Shards[i] fmt.Printf("==== %s ===\n", shard.Path) fmt.Printf("Approximate number of spans: %d\n", shard.ApproxNumSpans) stats := strings.Replace(shard.LevelDbStats, "\\n", "\n", -1) fmt.Printf("%s\n", stats) } return EXIT_SUCCESS }