Fixed network stats handling. The UI now reports network errors.

This commit is contained in:
Vishnu Kannan 2014-07-23 21:39:41 +00:00
parent 106787f850
commit 41d9275b51
5 changed files with 199 additions and 177 deletions

View File

@ -37,6 +37,8 @@ func toContainerStats(libcontainerStats *libcontainer.ContainerStats) *info.Cont
s := libcontainerStats.CgroupStats s := libcontainerStats.CgroupStats
ret := new(info.ContainerStats) ret := new(info.ContainerStats)
ret.Timestamp = time.Now() ret.Timestamp = time.Now()
if s != nil {
ret.Cpu = new(info.CpuStats) ret.Cpu = new(info.CpuStats)
ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode
ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode
@ -64,8 +66,11 @@ func toContainerStats(libcontainerStats *libcontainer.ContainerStats) *info.Cont
ret.Memory.WorkingSet -= v ret.Memory.WorkingSet -= v
} }
} }
}
// TODO(vishh): Perform a deep copy or alias libcontainer network stats. // TODO(vishh): Perform a deep copy or alias libcontainer network stats.
ret.Network = (*info.NetworkStats)(&libcontainerStats.NetworkStats) if libcontainerStats.NetworkStats != nil {
ret.Network = (*info.NetworkStats)(libcontainerStats.NetworkStats)
}
return ret return ret
} }

View File

@ -241,21 +241,21 @@ type MemoryStatsMemoryData struct {
type NetworkStats struct { type NetworkStats struct {
// Cumulative count of bytes received. // Cumulative count of bytes received.
RxBytes uint64 `json:"rx_bytes,omitempty"` RxBytes uint64 `json:"rx_bytes"`
// Cumulative count of packets received. // Cumulative count of packets received.
RxPackets uint64 `json:"rx_packets,omitempty"` RxPackets uint64 `json:"rx_packets"`
// Cumulative count of receive errors encountered. // Cumulative count of receive errors encountered.
RxErrors uint64 `json:"rx_errors,omitempty"` RxErrors uint64 `json:"rx_errors"`
// Cumulative count of packets dropped while receiving. // Cumulative count of packets dropped while receiving.
RxDropped uint64 `json:"rx_dropped,omitempty"` RxDropped uint64 `json:"rx_dropped"`
// Cumulative count of bytes transmitted. // Cumulative count of bytes transmitted.
TxBytes uint64 `json:"tx_bytes,omitempty"` TxBytes uint64 `json:"tx_bytes"`
// Cumulative count of packets transmitted. // Cumulative count of packets transmitted.
TxPackets uint64 `json:"tx_packets,omitempty"` TxPackets uint64 `json:"tx_packets"`
// Cumulative count of transmit errors encountered. // Cumulative count of transmit errors encountered.
TxErrors uint64 `json:"tx_errors,omitempty"` TxErrors uint64 `json:"tx_errors"`
// Cumulative count of packets dropped while transmitting. // Cumulative count of packets dropped while transmitting.
TxDropped uint64 `json:"tx_dropped,omitempty"` TxDropped uint64 `json:"tx_dropped"`
} }
type ContainerStats struct { type ContainerStats struct {

View File

@ -57,6 +57,7 @@ type pageData struct {
ResourcesAvailable bool ResourcesAvailable bool
CpuAvailable bool CpuAvailable bool
MemoryAvailable bool MemoryAvailable bool
NetworkAvailable bool
} }
func init() { func init() {
@ -204,6 +205,14 @@ func ServerContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL)
} }
} }
networkStatsAvailable := false
for _, stat := range cont.Stats {
if stat.Network != nil {
networkStatsAvailable = true
break
}
}
data := &pageData{ data := &pageData{
ContainerName: displayName, ContainerName: displayName,
// TODO(vmarmol): Only use strings for this. // TODO(vmarmol): Only use strings for this.
@ -215,6 +224,7 @@ func ServerContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL)
ResourcesAvailable: cont.Spec.Cpu != nil || cont.Spec.Memory != nil, ResourcesAvailable: cont.Spec.Cpu != nil || cont.Spec.Memory != nil,
CpuAvailable: cont.Spec.Cpu != nil, CpuAvailable: cont.Spec.Cpu != nil,
MemoryAvailable: cont.Spec.Memory != nil, MemoryAvailable: cont.Spec.Memory != nil,
NetworkAvailable: networkStatsAvailable,
} }
err = pageTemplate.Execute(w, data) err = pageTemplate.Execute(w, data)
if err != nil { if err != nil {

View File

@ -16,7 +16,7 @@ package pages
const containersHtmlTemplate = ` const containersHtmlTemplate = `
<html> <html>
<head> <head>
<title>cAdvisor - Container {{.ContainerName}}</title> <title>cAdvisor - Container {{.ContainerName}}</title>
<!-- Latest compiled and minified CSS --> <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
@ -32,9 +32,9 @@ const containersHtmlTemplate = `
<script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="/static/containers.js"></script> <script type="text/javascript" src="/static/containers.js"></script>
</head> </head>
<body> <body>
<div class="container theme-showcase" > <div class="container theme-showcase" >
<div class="col-sm-12" id="logo"> <div class="col-sm-12" id="logo">
</div> </div>
<div class="col-sm-12"> <div class="col-sm-12">
@ -149,20 +149,27 @@ const containersHtmlTemplate = `
</div> </div>
</div> </div>
{{end}} {{end}}
{{if .NetworkAvailable}}
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">Network</h3> <h3 class="panel-title">Network</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
<h4>Throughput</h4>
<div id="network-bytes-chart"></div> <div id="network-bytes-chart"></div>
</div> </div>
<div class="panel-body">
<h4>Errors</h4>
<div id="network-errors-chart"></div>
</div> </div>
</div> </div>
{{end}} {{end}}
</div> </div>
<script type="text/javascript"> {{end}}
</div>
<script type="text/javascript">
startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}}); startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}});
</script> </script>
</body> </body>
</html> </html>
` `

View File

@ -234,7 +234,7 @@ function drawNetworkBytes(elementId, machineInfo, stats) {
elements.push(cur.network.rx_bytes - prev.network.rx_bytes); elements.push(cur.network.rx_bytes - prev.network.rx_bytes);
data.push(elements); data.push(elements);
} }
drawLineChart(titles, data, elementId, "Bytes"); drawLineChart(titles, data, elementId, "Bytes per second");
} }
// Draw the graph for network errors // Draw the graph for network errors
@ -252,7 +252,7 @@ function drawNetworkErrors(elementId, machineInfo, stats) {
elements.push(cur.network.rx_errors - prev.network.rx_errors); elements.push(cur.network.rx_errors - prev.network.rx_errors);
data.push(elements); data.push(elements);
} }
drawLineChart(titles, data, elementId, "Errors"); drawLineChart(titles, data, elementId, "Errors per second");
} }
// Expects an array of closures to call. After each execution the JS runtime is given control back before continuing. // Expects an array of closures to call. After each execution the JS runtime is given control back before continuing.