Merge pull request #111 from vishh/network_stats1
Adding network tx & rx bytes to the UI.
This commit is contained in:
commit
784b6c8845
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
@ -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,12 +149,27 @@ const containersHtmlTemplate = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{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>
|
</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>
|
||||||
`
|
`
|
||||||
|
@ -219,6 +219,42 @@ function drawMemoryPageFaults(elementId, containerInfo) {
|
|||||||
drawLineChart(titles, data, elementId, "Faults");
|
drawLineChart(titles, data, elementId, "Faults");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw the graph for network tx/rx bytes.
|
||||||
|
function drawNetworkBytes(elementId, machineInfo, stats) {
|
||||||
|
var titles = ["Time", "Tx bytes", "Rx bytes"];
|
||||||
|
var data = [];
|
||||||
|
for (var i = 1; i < stats.stats.length; i++) {
|
||||||
|
var cur = stats.stats[i];
|
||||||
|
var prev = stats.stats[i - 1];
|
||||||
|
|
||||||
|
// TODO(vmarmol): This assumes we sample every second, use the timestamps.
|
||||||
|
var elements = [];
|
||||||
|
elements.push(cur.timestamp);
|
||||||
|
elements.push(cur.network.tx_bytes - prev.network.tx_bytes);
|
||||||
|
elements.push(cur.network.rx_bytes - prev.network.rx_bytes);
|
||||||
|
data.push(elements);
|
||||||
|
}
|
||||||
|
drawLineChart(titles, data, elementId, "Bytes per second");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the graph for network errors
|
||||||
|
function drawNetworkErrors(elementId, machineInfo, stats) {
|
||||||
|
var titles = ["Time", "Tx", "Rx"];
|
||||||
|
var data = [];
|
||||||
|
for (var i = 1; i < stats.stats.length; i++) {
|
||||||
|
var cur = stats.stats[i];
|
||||||
|
var prev = stats.stats[i - 1];
|
||||||
|
|
||||||
|
// TODO(vmarmol): This assumes we sample every second, use the timestamps.
|
||||||
|
var elements = [];
|
||||||
|
elements.push(cur.timestamp);
|
||||||
|
elements.push(cur.network.tx_errors - prev.network.tx_errors);
|
||||||
|
elements.push(cur.network.rx_errors - prev.network.rx_errors);
|
||||||
|
data.push(elements);
|
||||||
|
}
|
||||||
|
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.
|
||||||
// This function returns asynchronously
|
// This function returns asynchronously
|
||||||
function stepExecute(steps) {
|
function stepExecute(steps) {
|
||||||
@ -264,6 +300,14 @@ function drawCharts(machineInfo, containerInfo) {
|
|||||||
drawMemoryPageFaults("memory-page-faults-chart", containerInfo);
|
drawMemoryPageFaults("memory-page-faults-chart", containerInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Network.
|
||||||
|
steps.push(function() {
|
||||||
|
drawNetworkBytes("network-bytes-chart", machineInfo, containerInfo);
|
||||||
|
});
|
||||||
|
steps.push(function() {
|
||||||
|
drawNetworkErrors("network-errors-chart", machineInfo, containerInfo);
|
||||||
|
});
|
||||||
|
|
||||||
stepExecute(steps);
|
stepExecute(steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user