Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Pulsectl when task is watched prints sorted metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
lmroz authored and jcooklin committed Oct 29, 2015
1 parent 1641913 commit a4b26f7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/pulsectl/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/signal"
"path/filepath"
"sort"
"strings"
"syscall"
"text/tabwriter"
Expand Down Expand Up @@ -332,6 +333,7 @@ func watchTask(ctx *cli.Context) {
case e := <-r.EventChan:
switch e.EventType {
case "metric-event":
sort.Sort(e.Event)
for _, event := range e.Event {
printFields(w, false, 0,
event.Namespace,
Expand Down
20 changes: 17 additions & 3 deletions mgmt/rest/rbody/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ func (s *ScheduledTaskWatchingEnded) ResponseBodyType() string {

type StreamedTaskEvent struct {
// Used to describe the event
EventType string `json:"type"`
Message string `json:"message"`
Event []StreamedMetric `json:"event,omitempty"`
EventType string `json:"type"`
Message string `json:"message"`
Event StreamedMetrics `json:"event,omitempty"`
}

func (s *StreamedTaskEvent) ToJSON() string {
Expand All @@ -254,3 +254,17 @@ type StreamedMetric struct {
Source string `json:"source"`
Timestamp time.Time `json:"timestamp"`
}

type StreamedMetrics []StreamedMetric

func (s StreamedMetrics) Len() int {
return len(s)
}

func (s StreamedMetrics) Less(i, j int) bool {
return fmt.Sprintf("%s:%s", s[i].Source, s[i].Namespace) < fmt.Sprintf("%s:%s", s[j].Source, s[j].Namespace)
}

func (s StreamedMetrics) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

0 comments on commit a4b26f7

Please sign in to comment.