Skip to content

Commit

Permalink
Merge pull request #1125 from weaveworks/1057-sorting
Browse files Browse the repository at this point in the history
Treat pid as numeric and sort by #containers
  • Loading branch information
paulbellamy committed Mar 4, 2016
2 parents 3183561 + 60f5a5e commit 657af33
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
5 changes: 3 additions & 2 deletions render/detailed/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

var (
processNodeMetadata = []MetadataRowTemplate{
Latest{ID: process.PID, Prime: true},
Latest{ID: process.PID, Prime: true, Datatype: number},
Latest{ID: process.Cmdline, Prime: true},
Latest{ID: process.PPID, Prime: true},
Latest{ID: process.Threads, Prime: true},
Expand Down Expand Up @@ -63,6 +63,7 @@ type Latest struct {
ID string
Truncate int // If > 0, truncate the value to this length.
Prime bool // Whether the row should be shown by default
Datatype string
}

// MetadataRows implements MetadataRowTemplate
Expand All @@ -71,7 +72,7 @@ func (l Latest) MetadataRows(n report.Node) []MetadataRow {
if l.Truncate > 0 && len(val) > l.Truncate {
val = val[:l.Truncate]
}
return []MetadataRow{{ID: l.ID, Value: val, Prime: l.Prime}}
return []MetadataRow{{ID: l.ID, Value: val, Prime: l.Prime, Datatype: l.Datatype}}
}
return nil
}
Expand Down
62 changes: 49 additions & 13 deletions render/detailed/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,55 @@ var (
topologyID string
NodeSummaryGroup
}{
{report.Host, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []Column{
MakeColumn(host.CPUUsage), MakeColumn(host.MemoryUsage),
}}},
{report.Pod, NodeSummaryGroup{TopologyID: "pods", Label: "Pods"}},
{report.Container, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []Column{
MakeColumn(docker.CPUTotalUsage), MakeColumn(docker.MemoryUsage),
}}},
{report.Process, NodeSummaryGroup{TopologyID: "processes", Label: "Processes", Columns: []Column{
MakeColumn(process.PID), MakeColumn(process.CPUUsage), MakeColumn(process.MemoryUsage),
}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []Column{
MakeColumn(render.ContainersKey),
}}},
{
topologyID: report.Host,
NodeSummaryGroup: NodeSummaryGroup{
TopologyID: "hosts",
Label: "Hosts",
Columns: []Column{
MakeColumn(host.CPUUsage),
MakeColumn(host.MemoryUsage),
},
},
},
{
topologyID: report.Pod,
NodeSummaryGroup: NodeSummaryGroup{
TopologyID: "pods",
Label: "Pods",
},
},
{
topologyID: report.Container,
NodeSummaryGroup: NodeSummaryGroup{
TopologyID: "containers",
Label: "Containers", Columns: []Column{
MakeColumn(docker.CPUTotalUsage),
MakeColumn(docker.MemoryUsage),
},
},
},
{
topologyID: report.Process,
NodeSummaryGroup: NodeSummaryGroup{
TopologyID: "processes",
Label: "Processes", Columns: []Column{
{ID: process.PID, Label: Label(process.PID)},
MakeColumn(process.CPUUsage),
MakeColumn(process.MemoryUsage),
},
},
},
{
topologyID: report.ContainerImage,
NodeSummaryGroup: NodeSummaryGroup{
TopologyID: "containers-by-image",
Label: "Container Images",
Columns: []Column{
{ID: render.ContainersKey, Label: Label(render.ContainersKey), DefaultSort: true},
},
},
},
}
)

Expand Down
8 changes: 5 additions & 3 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ func TestMakeDetailedHostNode(t *testing.T) {
{
Label: "Container Images",
TopologyID: "containers-by-image",
Columns: []detailed.Column{detailed.MakeColumn(render.ContainersKey)},
Nodes: []detailed.NodeSummary{containerImageNodeSummary},
Columns: []detailed.Column{
{ID: render.ContainersKey, Label: detailed.Label(render.ContainersKey), DefaultSort: true},
},
Nodes: []detailed.NodeSummary{containerImageNodeSummary},
},
},
Connections: []detailed.NodeSummaryGroup{
Expand Down Expand Up @@ -201,7 +203,7 @@ func TestMakeDetailedContainerNode(t *testing.T) {
Label: "apache",
Linkable: true,
Metadata: []detailed.MetadataRow{
{ID: process.PID, Value: fixture.ServerPID, Prime: true},
{ID: process.PID, Value: fixture.ServerPID, Prime: true, Datatype: "number"},
},
Metrics: []detailed.MetricRow{},
},
Expand Down

0 comments on commit 657af33

Please sign in to comment.