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
ret := new(info.ContainerStats)
ret.Timestamp = time.Now()
if s != nil {
ret.Cpu = new(info.CpuStats)
ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode
ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode
@ -64,8 +66,11 @@ func toContainerStats(libcontainerStats *libcontainer.ContainerStats) *info.Cont
ret.Memory.WorkingSet -= v
}
}
}
// 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
}

View File

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

View File

@ -57,6 +57,7 @@ type pageData struct {
ResourcesAvailable bool
CpuAvailable bool
MemoryAvailable bool
NetworkAvailable bool
}
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{
ContainerName: displayName,
// 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,
CpuAvailable: cont.Spec.Cpu != nil,
MemoryAvailable: cont.Spec.Memory != nil,
NetworkAvailable: networkStatsAvailable,
}
err = pageTemplate.Execute(w, data)
if err != nil {

View File

@ -16,7 +16,7 @@ package pages
const containersHtmlTemplate = `
<html>
<head>
<head>
<title>cAdvisor - Container {{.ContainerName}}</title>
<!-- Latest compiled and minified 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="/static/containers.js"></script>
</head>
<body>
<div class="container theme-showcase" >
</head>
<body>
<div class="container theme-showcase" >
<div class="col-sm-12" id="logo">
</div>
<div class="col-sm-12">
@ -149,20 +149,27 @@ const containersHtmlTemplate = `
</div>
</div>
{{end}}
{{if .NetworkAvailable}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Network</h3>
</div>
<div class="panel-body">
<h4>Throughput</h4>
<div id="network-bytes-chart"></div>
</div>
<div class="panel-body">
<h4>Errors</h4>
<div id="network-errors-chart"></div>
</div>
</div>
{{end}}
</div>
<script type="text/javascript">
</div>
{{end}}
</div>
<script type="text/javascript">
startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}});
</script>
</body>
</script>
</body>
</html>
`

View File

@ -234,7 +234,7 @@ function drawNetworkBytes(elementId, machineInfo, stats) {
elements.push(cur.network.rx_bytes - prev.network.rx_bytes);
data.push(elements);
}
drawLineChart(titles, data, elementId, "Bytes");
drawLineChart(titles, data, elementId, "Bytes per second");
}
// 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);
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.