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