Make all link relative - part 2.
Added missing docker page handling.
This commit is contained in:
parent
bc66d8d5dc
commit
5bd6f601a4
@ -195,12 +195,14 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
||||
return err
|
||||
}
|
||||
|
||||
rootDir := getRootDir(containerName)
|
||||
|
||||
// Make a list of the parent containers and their links
|
||||
pathParts := strings.Split(string(cont.Name), "/")
|
||||
parentContainers := make([]link, 0, len(pathParts))
|
||||
parentContainers = append(parentContainers, link{
|
||||
Text: "root",
|
||||
Link: ContainersPage,
|
||||
Link: path.Join(rootDir, ContainersPage),
|
||||
})
|
||||
for i := 1; i < len(pathParts); i++ {
|
||||
// Skip empty parts.
|
||||
@ -209,7 +211,7 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
||||
}
|
||||
parentContainers = append(parentContainers, link{
|
||||
Text: pathParts[i],
|
||||
Link: path.Join(ContainersPage, path.Join(pathParts[1:i+1]...)),
|
||||
Link: path.Join(rootDir, ContainersPage, path.Join(pathParts[1:i+1]...)),
|
||||
})
|
||||
}
|
||||
|
||||
@ -221,7 +223,7 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
||||
}
|
||||
subcontainerLinks = append(subcontainerLinks, link{
|
||||
Text: getContainerDisplayName(sub),
|
||||
Link: path.Join(ContainersPage, sub.Name),
|
||||
Link: path.Join(rootDir, ContainersPage, sub.Name),
|
||||
})
|
||||
}
|
||||
|
||||
@ -239,6 +241,7 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
||||
MemoryAvailable: cont.Spec.HasMemory,
|
||||
NetworkAvailable: cont.Spec.HasNetwork,
|
||||
FsAvailable: cont.Spec.HasFilesystem,
|
||||
Root: rootDir,
|
||||
}
|
||||
err = pageTemplate.Execute(w, data)
|
||||
if err != nil {
|
||||
@ -248,3 +251,10 @@ func serveContainersPage(m manager.Manager, w http.ResponseWriter, u *url.URL) e
|
||||
glog.V(5).Infof("Request took %s", time.Since(start))
|
||||
return nil
|
||||
}
|
||||
|
||||
// Build a relative path to the root of the container page.
|
||||
func getRootDir(containerName string) string {
|
||||
// The root is at: container depth
|
||||
levels := (strings.Count(containerName, "/"))
|
||||
return strings.Repeat("../", levels)
|
||||
}
|
||||
|
@ -19,23 +19,23 @@ const containersHtmlTemplate = `
|
||||
<head>
|
||||
<title>cAdvisor - {{.DisplayName}}</title>
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="/static/bootstrap-3.1.1.min.css">
|
||||
<link rel="stylesheet" href="{{.Root}}static/bootstrap-3.1.1.min.css">
|
||||
|
||||
<!-- Optional theme -->
|
||||
<link rel="stylesheet" href="/static/bootstrap-theme-3.1.1.min.css">
|
||||
<link rel="stylesheet" href="{{.Root}}static/bootstrap-theme-3.1.1.min.css">
|
||||
|
||||
<link rel="stylesheet" href="/static/containers.css">
|
||||
<link rel="stylesheet" href="{{.Root}}static/containers.css">
|
||||
|
||||
<!-- Latest compiled and minified JavaScript -->
|
||||
<script src="/static/jquery-1.10.2.min.js"></script>
|
||||
<script src="/static/bootstrap-3.1.1.min.js"></script>
|
||||
<script type="text/javascript" src="/static/google-jsapi.js"></script>
|
||||
<script src="{{.Root}}static/jquery-1.10.2.min.js"></script>
|
||||
<script src="{{.Root}}static/bootstrap-3.1.1.min.js"></script>
|
||||
<script type="text/javascript" src="{{.Root}}static/google-jsapi.js"></script>
|
||||
|
||||
<script type="text/javascript" src="/static/containers.js"></script>
|
||||
<script type="text/javascript" src="{{.Root}}static/containers.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container theme-showcase" >
|
||||
<a href="/" class="col-sm-12" id="logo">
|
||||
<a href="{{.Root}}" class="col-sm-12" id="logo">
|
||||
</a>
|
||||
<div class="col-sm-12">
|
||||
<div class="page-header">
|
||||
@ -49,7 +49,7 @@ const containersHtmlTemplate = `
|
||||
</div>
|
||||
{{if .IsRoot}}
|
||||
<div class="col-sm-12">
|
||||
<h4><a href="/docker">Docker Containers</a></h4>
|
||||
<h4><a href="../docker">Docker Containers</a></h4>
|
||||
</div>
|
||||
{{end}}
|
||||
{{if .Subcontainers}}
|
||||
@ -179,7 +179,7 @@ const containersHtmlTemplate = `
|
||||
{{end}}
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}});
|
||||
startPage({{.ContainerName}}, {{.CpuAvailable}}, {{.MemoryAvailable}}, {{.Root}});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -34,6 +34,7 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error
|
||||
|
||||
// The container name is the path after the handler
|
||||
containerName := u.Path[len(DockerPage):]
|
||||
rootDir := getRootDir(u.Path)
|
||||
|
||||
var data *pageData
|
||||
if containerName == "" {
|
||||
@ -62,6 +63,7 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error
|
||||
Link: DockerPage,
|
||||
}},
|
||||
Subcontainers: subcontainers,
|
||||
Root: rootDir,
|
||||
}
|
||||
} else {
|
||||
// Get the container.
|
||||
@ -103,6 +105,7 @@ func serveDockerPage(m manager.Manager, w http.ResponseWriter, u *url.URL) error
|
||||
MemoryAvailable: cont.Spec.HasMemory,
|
||||
NetworkAvailable: cont.Spec.HasNetwork,
|
||||
FsAvailable: cont.Spec.HasFilesystem,
|
||||
Root: rootDir,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,7 @@ type pageData struct {
|
||||
MemoryAvailable bool
|
||||
NetworkAvailable bool
|
||||
FsAvailable bool
|
||||
Root string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -1518,21 +1518,21 @@ function drawGauges(elementId, gauges) {
|
||||
}
|
||||
|
||||
// Get the machine info.
|
||||
function getMachineInfo(callback) {
|
||||
$.getJSON("/api/v1.0/machine", function(data) {
|
||||
function getMachineInfo(rootDir, callback) {
|
||||
$.getJSON(rootDir + "api/v1.0/machine", function(data) {
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
|
||||
// Get the container stats for the specified container.
|
||||
function getStats(containerName, callback) {
|
||||
function getStats(rootDir, containerName, callback) {
|
||||
// Request 60s of container history and no samples.
|
||||
var request = JSON.stringify({
|
||||
// Update main.statsRequestedByUI while updating "num_stats" here.
|
||||
"num_stats": 60,
|
||||
"num_samples": 0
|
||||
});
|
||||
$.post("/api/v1.0/containers" + containerName, request, function(data) {
|
||||
$.post(rootDir + "api/v1.0/containers" + containerName, request, function(data) {
|
||||
callback(data);
|
||||
}, "json");
|
||||
}
|
||||
@ -1891,7 +1891,7 @@ function drawCharts(machineInfo, containerInfo) {
|
||||
}
|
||||
|
||||
// Executed when the page finishes loading.
|
||||
function startPage(containerName, hasCpu, hasMemory) {
|
||||
function startPage(containerName, hasCpu, hasMemory, rootDir) {
|
||||
// Don't fetch data if we don't have any resource.
|
||||
if (!hasCpu && !hasMemory) {
|
||||
return;
|
||||
@ -1902,9 +1902,9 @@ function startPage(containerName, hasCpu, hasMemory) {
|
||||
window.cadvisor.firstRun = true;
|
||||
|
||||
// Get machine info, then get the stats every 1s.
|
||||
getMachineInfo(function(machineInfo) {
|
||||
getMachineInfo(rootDir, function(machineInfo) {
|
||||
setInterval(function() {
|
||||
getStats(containerName, function(containerInfo){
|
||||
getStats(rootDir, containerName, function(containerInfo){
|
||||
if (window.cadvisor.firstRun && containerInfo.spec.has_filesystem) {
|
||||
window.cadvisor.firstRun = false;
|
||||
startFileSystemUsage("filesystem-usage", machineInfo, containerInfo);
|
||||
|
Loading…
Reference in New Issue
Block a user