(stats *management.EventStreamStats)
| 451 | } |
| 452 | |
| 453 | func (r *Renderer) RenderEventStreamStats(stats *management.EventStreamStats) { |
| 454 | if r.Format == OutputFormatJSON { |
| 455 | r.JSONResult(stats) |
| 456 | return |
| 457 | } |
| 458 | |
| 459 | v := &eventStreamStatsView{ |
| 460 | ID: stats.GetID(), |
| 461 | Name: stats.GetName(), |
| 462 | From: stats.Window.GetDateFrom().Format(time.RFC3339), |
| 463 | To: stats.Window.GetDateTo().Format(time.RFC3339), |
| 464 | Interval: fmt.Sprintf("%ds", stats.Window.BucketInterval.GetScaleFactor()), |
| 465 | raw: stats, |
| 466 | } |
| 467 | |
| 468 | r.Newline() |
| 469 | fmt.Println(ansi.Bold(ansi.Cyan("Event Stream Stats"))) |
| 470 | r.Result(v) |
| 471 | |
| 472 | // Metric buckets. |
| 473 | metricMap := extractMetricMap(stats.Metrics) |
| 474 | |
| 475 | success := metricMap[MetricSuccessfulDeliveries] |
| 476 | fail := metricMap[MetricFailedDeliveries] |
| 477 | |
| 478 | var rows []View |
| 479 | for i, bucket := range stats.Buckets { |
| 480 | timestamp := bucket.Format("2006-01-02 15:04") |
| 481 | row := &eventStreamStatsRowView{ |
| 482 | Timestamp: timestamp, |
| 483 | Success: safeMetric(success, i), |
| 484 | Failure: safeMetric(fail, i), |
| 485 | raw: nil, |
| 486 | } |
| 487 | rows = append(rows, row) |
| 488 | } |
| 489 | |
| 490 | r.Newline() |
| 491 | fmt.Println(ansi.Bold(ansi.Cyan("Delivery Metrics"))) |
| 492 | r.Results(rows) |
| 493 | |
| 494 | // Metric Totals + Types. |
| 495 | r.Newline() |
| 496 | if success != nil { |
| 497 | s := findMetric(stats.Metrics, MetricSuccessfulDeliveries) |
| 498 | if s != nil { |
| 499 | fmt.Printf(" Successful Deliveries: Total = %d, Type = %s\n", s.GetWindowTotal(), s.GetType()) |
| 500 | } |
| 501 | } |
| 502 | if fail != nil { |
| 503 | f := findMetric(stats.Metrics, MetricFailedDeliveries) |
| 504 | if f != nil { |
| 505 | fmt.Printf(" Failed Deliveries: Total = %d, Type = %s\n", f.GetWindowTotal(), f.GetType()) |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | func findMetric(metrics []*management.StatsMetric, name string) *management.StatsMetric { |
no test coverage detected