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,35 +37,40 @@ 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()
ret.Cpu = new(info.CpuStats)
ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode
ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode
n := len(s.CpuStats.CpuUsage.PercpuUsage)
ret.Cpu.Usage.PerCpu = make([]uint64, n)
ret.Cpu.Usage.Total = 0 if s != nil {
for i := 0; i < n; i++ { ret.Cpu = new(info.CpuStats)
ret.Cpu.Usage.PerCpu[i] = s.CpuStats.CpuUsage.PercpuUsage[i] ret.Cpu.Usage.User = s.CpuStats.CpuUsage.UsageInUsermode
ret.Cpu.Usage.Total += s.CpuStats.CpuUsage.PercpuUsage[i] ret.Cpu.Usage.System = s.CpuStats.CpuUsage.UsageInKernelmode
} n := len(s.CpuStats.CpuUsage.PercpuUsage)
ret.Memory = new(info.MemoryStats) ret.Cpu.Usage.PerCpu = make([]uint64, n)
ret.Memory.Usage = s.MemoryStats.Usage
if v, ok := s.MemoryStats.Stats["pgfault"]; ok { ret.Cpu.Usage.Total = 0
ret.Memory.ContainerData.Pgfault = v for i := 0; i < n; i++ {
ret.Memory.HierarchicalData.Pgfault = v ret.Cpu.Usage.PerCpu[i] = s.CpuStats.CpuUsage.PercpuUsage[i]
} ret.Cpu.Usage.Total += s.CpuStats.CpuUsage.PercpuUsage[i]
if v, ok := s.MemoryStats.Stats["pgmajfault"]; ok { }
ret.Memory.ContainerData.Pgmajfault = v ret.Memory = new(info.MemoryStats)
ret.Memory.HierarchicalData.Pgmajfault = v ret.Memory.Usage = s.MemoryStats.Usage
} if v, ok := s.MemoryStats.Stats["pgfault"]; ok {
if v, ok := s.MemoryStats.Stats["total_inactive_anon"]; ok { ret.Memory.ContainerData.Pgfault = v
ret.Memory.WorkingSet = ret.Memory.Usage - v ret.Memory.HierarchicalData.Pgfault = v
if v, ok := s.MemoryStats.Stats["total_active_file"]; ok { }
ret.Memory.WorkingSet -= v if v, ok := s.MemoryStats.Stats["pgmajfault"]; ok {
ret.Memory.ContainerData.Pgmajfault = v
ret.Memory.HierarchicalData.Pgmajfault = v
}
if v, ok := s.MemoryStats.Stats["total_inactive_anon"]; ok {
ret.Memory.WorkingSet = ret.Memory.Usage - v
if v, ok := s.MemoryStats.Stats["total_active_file"]; ok {
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,153 +16,160 @@ 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">
<!-- Optional theme --> <!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/containers.css"> <link rel="stylesheet" href="/static/containers.css">
<!-- Latest compiled and minified JavaScript --> <!-- Latest compiled and minified JavaScript -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<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">
<div class="page-header"> <div class="page-header">
<h1>{{.ContainerName}}</h1> <h1>{{.ContainerName}}</h1>
</div> </div>
<ol class="breadcrumb"> <ol class="breadcrumb">
{{range $parentContainer := .ParentContainers}} {{range $parentContainer := .ParentContainers}}
<li>{{containerLink $parentContainer true ""}}</li> <li>{{containerLink $parentContainer true ""}}</li>
{{end}} {{end}}
</ol> </ol>
</div> </div>
{{if .Subcontainers}} {{if .Subcontainers}}
<div class="col-sm-12"> <div class="col-sm-12">
<div class="page-header"> <div class="page-header">
<h3>Subcontainers</h3> <h3>Subcontainers</h3>
</div> </div>
<div class="list-group"> <div class="list-group">
{{range $subcontainer := .Subcontainers}} {{range $subcontainer := .Subcontainers}}
{{containerLink $subcontainer false "list-group-item"}} {{containerLink $subcontainer false "list-group-item"}}
{{end}}
</div>
</div>
{{end}}
{{if .ResourcesAvailable}}
<div class="col-sm-12">
<div class="page-header">
<h3>Isolation</h3>
</div>
{{if .CpuAvailable}}
<ul class="list-group">
<li class="list-group-item active isolation-title panel-title">CPU</li>
{{if .Spec.Cpu.Limit}}
<li class="list-group-item"><span class="stat-label">Limit</span> {{printCores .Spec.Cpu.Limit}} <span class="unit-label">cores</span></li>
{{end}}
{{if .Spec.Cpu.MaxLimit}}
<li class="list-group-item"><span class="stat-label">Max Limit</span> {{printCores .Spec.Cpu.MaxLimit}} <span class="unit-label">cores</span></li>
{{end}}
{{if .Spec.Cpu.Mask}}
<li class="list-group-item"><span class="stat-label">Allowed Cores</span> {{printMask .Spec.Cpu.Mask .MachineInfo.NumCores}}</li>
{{end}}
</ul>
{{end}}
{{if .MemoryAvailable}}
<ul class="list-group">
<li class="list-group-item active isolation-title panel-title">Memory</li>
{{if .Spec.Memory.Reservation}}
<li class="list-group-item"><span class="stat-label">Reservation</span> {{printMegabytes .Spec.Memory.Reservation}} <span class="unit-label">MB</span></li>
{{end}}
{{if .Spec.Memory.Limit}}
<li class="list-group-item"><span class="stat-label">Limit</span> {{printMegabytes .Spec.Memory.Limit}} <span class="unit-label">MB</span></li>
{{end}}
{{if .Spec.Memory.SwapLimit}}
<li class="list-group-item"><span class="stat-label">Swap Limit</span> {{printMegabytes .Spec.Memory.SwapLimit}} <span class="unit-label">MB</span></li>
{{end}}
</ul>
{{end}}
</div>
<div class="col-sm-12">
<div class="page-header">
<h3>Usage</h3>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Overview</h3>
</div>
<div id="usage-gauge" class="panel-body">
</div>
</div>
{{if .CpuAvailable}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">CPU</h3>
</div>
<div class="panel-body">
<h4>Total Usage</h4>
<div id="cpu-total-usage-chart"></div>
<h4>Usage per Core</h4>
<div id="cpu-per-core-usage-chart"></div>
<h4>Usage Breakdown</h4>
<div id="cpu-usage-breakdown-chart"></div>
</div>
</div>
{{end}}
{{if .MemoryAvailable}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Memory</h3>
</div>
<div class="panel-body">
<h4>Total Usage</h4>
<div id="memory-usage-chart"></div>
<br/>
<div class="row col-sm-12">
<h4>Usage Breakdown</h4>
<div class="col-sm-9">
<div class="progress">
<div class="progress-bar progress-bar-danger" style="width: {{getHotMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Hot Memory</span>
</div>
<div class="progress-bar progress-bar-info" style="width: {{getColdMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Cold Memory</span>
</div>
</div>
</div>
<div class="col-sm-3">
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats .MachineInfo}}%)
</div>
</div>
<h4>Page Faults</h4>
<div id="memory-page-faults-chart"></div>
</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>
{{end}} {{end}}
</div> </div>
</div> <script type="text/javascript">
{{end}} startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}});
{{if .ResourcesAvailable}} </script>
<div class="col-sm-12"> </body>
<div class="page-header">
<h3>Isolation</h3>
</div>
{{if .CpuAvailable}}
<ul class="list-group">
<li class="list-group-item active isolation-title panel-title">CPU</li>
{{if .Spec.Cpu.Limit}}
<li class="list-group-item"><span class="stat-label">Limit</span> {{printCores .Spec.Cpu.Limit}} <span class="unit-label">cores</span></li>
{{end}}
{{if .Spec.Cpu.MaxLimit}}
<li class="list-group-item"><span class="stat-label">Max Limit</span> {{printCores .Spec.Cpu.MaxLimit}} <span class="unit-label">cores</span></li>
{{end}}
{{if .Spec.Cpu.Mask}}
<li class="list-group-item"><span class="stat-label">Allowed Cores</span> {{printMask .Spec.Cpu.Mask .MachineInfo.NumCores}}</li>
{{end}}
</ul>
{{end}}
{{if .MemoryAvailable}}
<ul class="list-group">
<li class="list-group-item active isolation-title panel-title">Memory</li>
{{if .Spec.Memory.Reservation}}
<li class="list-group-item"><span class="stat-label">Reservation</span> {{printMegabytes .Spec.Memory.Reservation}} <span class="unit-label">MB</span></li>
{{end}}
{{if .Spec.Memory.Limit}}
<li class="list-group-item"><span class="stat-label">Limit</span> {{printMegabytes .Spec.Memory.Limit}} <span class="unit-label">MB</span></li>
{{end}}
{{if .Spec.Memory.SwapLimit}}
<li class="list-group-item"><span class="stat-label">Swap Limit</span> {{printMegabytes .Spec.Memory.SwapLimit}} <span class="unit-label">MB</span></li>
{{end}}
</ul>
{{end}}
</div>
<div class="col-sm-12">
<div class="page-header">
<h3>Usage</h3>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Overview</h3>
</div>
<div id="usage-gauge" class="panel-body">
</div>
</div>
{{if .CpuAvailable}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">CPU</h3>
</div>
<div class="panel-body">
<h4>Total Usage</h4>
<div id="cpu-total-usage-chart"></div>
<h4>Usage per Core</h4>
<div id="cpu-per-core-usage-chart"></div>
<h4>Usage Breakdown</h4>
<div id="cpu-usage-breakdown-chart"></div>
</div>
</div>
{{end}}
{{if .MemoryAvailable}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Memory</h3>
</div>
<div class="panel-body">
<h4>Total Usage</h4>
<div id="memory-usage-chart"></div>
<br/>
<div class="row col-sm-12">
<h4>Usage Breakdown</h4>
<div class="col-sm-9">
<div class="progress">
<div class="progress-bar progress-bar-danger" style="width: {{getHotMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Hot Memory</span>
</div>
<div class="progress-bar progress-bar-info" style="width: {{getColdMemoryPercent .Spec .Stats .MachineInfo}}%">
<span class="sr-only">Cold Memory</span>
</div>
</div>
</div>
<div class="col-sm-3">
{{ getMemoryUsage .Stats }} MB ({{ getMemoryUsagePercent .Spec .Stats .MachineInfo}}%)
</div>
</div>
<h4>Page Faults</h4>
<div id="memory-page-faults-chart"></div>
</div>
</div>
{{end}}
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Network</h3>
</div>
<div class="panel-body">
<div id="network-bytes-chart"></div>
</div>
</div>
</div>
{{end}}
</div>
<script type="text/javascript">
startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}});
</script>
</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.