Re-enable /monitoring/systems and /monitoring/node

This commit is contained in:
Lou Knauer 2022-02-02 10:12:16 +01:00
parent 7b61582b42
commit 3d5aa9f904
6 changed files with 89 additions and 129 deletions

171
server.go
View File

@ -415,55 +415,56 @@ func prepareRoute(r *http.Request) (map[string]interface{}, map[string]interface
return conf, infos, nil return conf, infos, nil
} }
func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) { func buildFilterPresets(query url.Values) map[string]interface{} {
buildFilterPresets := func(query url.Values) map[string]interface{} { filterPresets := map[string]interface{}{}
filterPresets := map[string]interface{}{}
if query.Get("cluster") != "" { if query.Get("cluster") != "" {
filterPresets["cluster"] = query.Get("cluster") filterPresets["cluster"] = query.Get("cluster")
}
if query.Get("partition") != "" {
filterPresets["partition"] = query.Get("partition")
}
if query.Get("project") != "" {
filterPresets["project"] = query.Get("project")
filterPresets["projectMatch"] = "eq"
}
if query.Get("state") != "" && schema.JobState(query.Get("state")).Valid() {
filterPresets["state"] = query.Get("state")
}
if rawtags, ok := query["tag"]; ok {
tags := make([]int, len(rawtags))
for i, tid := range rawtags {
var err error
tags[i], err = strconv.Atoi(tid)
if err != nil {
tags[i] = -1
}
}
filterPresets["tags"] = tags
}
if query.Get("numNodes") != "" {
parts := strings.Split(query.Get("numNodes"), "-")
if len(parts) == 2 {
a, e1 := strconv.Atoi(parts[0])
b, e2 := strconv.Atoi(parts[1])
if e1 == nil && e2 == nil {
filterPresets["numNodes"] = map[string]int{"from": a, "to": b}
}
}
}
if query.Get("jobId") != "" {
filterPresets["jobId"] = query.Get("jobId")
}
if query.Get("arrayJobId") != "" {
if num, err := strconv.Atoi(query.Get("arrayJobId")); err == nil {
filterPresets["arrayJobId"] = num
}
}
return filterPresets
} }
if query.Get("partition") != "" {
filterPresets["partition"] = query.Get("partition")
}
if query.Get("project") != "" {
filterPresets["project"] = query.Get("project")
filterPresets["projectMatch"] = "eq"
}
if query.Get("state") != "" && schema.JobState(query.Get("state")).Valid() {
filterPresets["state"] = query.Get("state")
}
if rawtags, ok := query["tag"]; ok {
tags := make([]int, len(rawtags))
for i, tid := range rawtags {
var err error
tags[i], err = strconv.Atoi(tid)
if err != nil {
tags[i] = -1
}
}
filterPresets["tags"] = tags
}
if query.Get("numNodes") != "" {
parts := strings.Split(query.Get("numNodes"), "-")
if len(parts) == 2 {
a, e1 := strconv.Atoi(parts[0])
b, e2 := strconv.Atoi(parts[1])
if e1 == nil && e2 == nil {
filterPresets["numNodes"] = map[string]int{"from": a, "to": b}
}
}
}
if query.Get("jobId") != "" {
filterPresets["jobId"] = query.Get("jobId")
}
if query.Get("arrayJobId") != "" {
if num, err := strconv.Atoi(query.Get("arrayJobId")); err == nil {
filterPresets["arrayJobId"] = num
}
}
return filterPresets
}
func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) {
router.HandleFunc("/monitoring/jobs/", func(rw http.ResponseWriter, r *http.Request) { router.HandleFunc("/monitoring/jobs/", func(rw http.ResponseWriter, r *http.Request) {
conf, infos, err := prepareRoute(r) conf, infos, err := prepareRoute(r)
@ -559,49 +560,12 @@ func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) {
}) })
}) })
router.HandleFunc("/monitoring/analysis/", func(rw http.ResponseWriter, r *http.Request) {
conf, infos, err := prepareRoute(r)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
filterPresets := map[string]interface{}{}
query := r.URL.Query()
if query.Get("cluster") != "" {
filterPresets["clusterId"] = query.Get("cluster")
}
templates.Render(rw, r, "monitoring/analysis.tmpl", &templates.Page{
Title: "Analysis View - ClusterCockpit",
Config: conf,
Infos: infos,
FilterPresets: filterPresets,
})
})
router.HandleFunc("/monitoring/systems/", func(rw http.ResponseWriter, r *http.Request) { router.HandleFunc("/monitoring/systems/", func(rw http.ResponseWriter, r *http.Request) {
conf, infos, err := prepareRoute(r) // TODO: List all clusters?
if err != nil { http.Redirect(rw, r, "/", http.StatusTemporaryRedirect)
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
filterPresets := map[string]interface{}{}
query := r.URL.Query()
if query.Get("cluster") != "" {
filterPresets["clusterId"] = query.Get("cluster")
}
templates.Render(rw, r, "monitoring/systems.tmpl", &templates.Page{
Title: "System View - ClusterCockpit",
Config: conf,
Infos: infos,
FilterPresets: filterPresets,
})
}) })
router.HandleFunc("/monitoring/node/{clusterId}/{nodeId}", func(rw http.ResponseWriter, r *http.Request) { router.HandleFunc("/monitoring/systems/{cluster}", func(rw http.ResponseWriter, r *http.Request) {
conf, infos, err := prepareRoute(r) conf, infos, err := prepareRoute(r)
if err != nil { if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError) http.Error(rw, err.Error(), http.StatusInternalServerError)
@ -609,11 +573,38 @@ func monitoringRoutes(router *mux.Router, resolver *graph.Resolver) {
} }
vars := mux.Vars(r) vars := mux.Vars(r)
infos["nodeId"] = vars["nodeId"] infos["cluster"] = vars["cluster"]
infos["clusterId"] = vars["clusterId"] from, to := r.URL.Query().Get("from"), r.URL.Query().Get("to")
if from != "" || to != "" {
infos["from"] = from
infos["to"] = to
}
templates.Render(rw, r, "monitoring/systems.tmpl", &templates.Page{
Title: fmt.Sprintf("Cluster %s - ClusterCockpit", vars["cluster"]),
Config: conf,
Infos: infos,
})
})
router.HandleFunc("/monitoring/node/{cluster}/{hostname}", func(rw http.ResponseWriter, r *http.Request) {
conf, infos, err := prepareRoute(r)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
vars := mux.Vars(r)
infos["cluster"] = vars["cluster"]
infos["hostname"] = vars["hostname"]
from, to := r.URL.Query().Get("from"), r.URL.Query().Get("to")
if from != "" || to != "" {
infos["from"] = from
infos["to"] = to
}
templates.Render(rw, r, "monitoring/node.tmpl", &templates.Page{ templates.Render(rw, r, "monitoring/node.tmpl", &templates.Page{
Title: fmt.Sprintf("Node %s - ClusterCockpit", vars["nodeId"]), Title: fmt.Sprintf("Host %s - ClusterCockpit", vars["hostname"]),
Config: conf, Config: conf,
Infos: infos, Infos: infos,
}) })

View File

@ -38,7 +38,7 @@
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Jobs</th> <th>Jobs</th>
<!-- <th>System View</th> --> <th>System View</th>
<!-- <th>Analysis View</th> --> <!-- <th>Analysis View</th> -->
</tr> </tr>
</thead> </thead>
@ -47,7 +47,7 @@
<tr> <tr>
<td>{{.Name}}</td> <td>{{.Name}}</td>
<td><a href="/monitoring/jobs/?cluster={{.Name}}">Jobs</a></td> <td><a href="/monitoring/jobs/?cluster={{.Name}}">Jobs</a></td>
<!-- <td><a href="/monitoring/systems/?cluster={{.Name}}">System View</a></td> --> <td><a href="/monitoring/systems/{{.Name}}">System View</a></td>
<!-- <td><a href="/monitoring/analysis/?cluster={{.Name}}">Analysis View</a></td> --> <!-- <td><a href="/monitoring/analysis/?cluster={{.Name}}">Analysis View</a></td> -->
</tr> </tr>
{{end}} {{end}}

View File

@ -1,18 +0,0 @@
{{define "content"}}
<div id="svelte-app"></div>
{{end}}
{{define "stylesheets"}}
<link rel='stylesheet' href='/build/analysis.css'>
{{end}}
{{define "javascript"}}
<script>
const filterPresets = {{ .FilterPresets }};
const clusterCockpitConfigPromise = Promise.resolve({
plot_view_plotsPerRow: {{ .Config.plot_view_plotsPerRow }},
analysis_view_histogramMetrics: {{ .Config.analysis_view_histogramMetrics }},
analysis_view_scatterPlotMetrics: {{ .Config.analysis_view_scatterPlotMetrics }}
});
</script>
<script src='/build/analysis.js'></script>
{{end}}

View File

@ -7,15 +7,8 @@
{{end}} {{end}}
{{define "javascript"}} {{define "javascript"}}
<script> <script>
const nodeInfos = { const infos = {{ .Infos }};
nodeId: "{{ .Infos.nodeId }}", const clusterCockpitConfig = {{ .Config }};
clusterId: "{{ .Infos.clusterId }}"
};
const clusterCockpitConfigPromise = Promise.resolve({
plot_general_colorscheme: {{ .Config.plot_general_colorscheme }},
plot_general_lineWidth: {{ .Config.plot_general_lineWidth }},
plot_general_colorBackground: {{ .Config.plot_general_colorBackground }},
});
</script> </script>
<script src='/build/node.js'></script> <script src='/build/node.js'></script>
{{end}} {{end}}

View File

@ -7,13 +7,8 @@
{{end}} {{end}}
{{define "javascript"}} {{define "javascript"}}
<script> <script>
const filterPresets = {{ .FilterPresets }}; const infos = {{ .Infos }};
const clusterCockpitConfigPromise = Promise.resolve({ const clusterCockpitConfig = {{ .Config }};
plot_view_plotsPerRow: {{ .Config.plot_view_plotsPerRow }},
plot_general_colorscheme: {{ .Config.plot_general_colorscheme }},
plot_general_lineWidth: {{ .Config.plot_general_lineWidth }},
plot_general_colorBackground: {{ .Config.plot_general_colorBackground }},
});
</script> </script>
<script src='/build/systems.js'></script> <script src='/build/systems.js'></script>
{{end}} {{end}}

View File

@ -34,9 +34,8 @@ func init() {
"monitoring/job.tmpl", "monitoring/job.tmpl",
"monitoring/list.tmpl", "monitoring/list.tmpl",
"monitoring/user.tmpl", "monitoring/user.tmpl",
// "monitoring/analysis.tmpl", "monitoring/systems.tmpl",
// "monitoring/systems.tmpl", "monitoring/node.tmpl",
// "monitoring/node.tmpl",
} }
for _, file := range files { for _, file := range files {