/
hwloc.go
114 lines (95 loc) · 2.66 KB
/
hwloc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Copyright 2023 Lawrence Livermore National Security, LLC
(c.f. AUTHORS, NOTICE.LLNS, COPYING)
SPDX-License-Identifier: MIT
*/
package sys
import (
"fmt"
api "github.com/converged-computing/metrics-operator/api/v1alpha2"
"github.com/converged-computing/metrics-operator/pkg/metadata"
metrics "github.com/converged-computing/metrics-operator/pkg/metrics"
"github.com/converged-computing/metrics-operator/pkg/specs"
"k8s.io/apimachinery/pkg/util/intstr"
)
const (
hwlocIdentifier = "sys-hwloc"
hwlocSummary = "install hwloc for inspecting hardware locality"
hwlocContainer = "ghcr.io/converged-computing/metric-hwloc:latest"
)
type Hwloc struct {
metrics.SingleApplication
// Custom Options
commands []string
}
func (m Hwloc) Url() string {
return "https://www.open-mpi.org/projects/hwloc/tutorials/20120702-POA-hwloc-tutorial.html"
}
func (m *Hwloc) Famliy() string {
return metrics.SystemFamily
}
// Set custom options / attributes for the metric
func (m *Hwloc) SetOptions(metric *api.Metric) {
m.Identifier = hwlocIdentifier
m.Summary = hwlocSummary
m.Container = hwlocContainer
// Defaults for lstopo command
m.ResourceSpec = &metric.Resources
m.AttributeSpec = &metric.Attributes
m.commands = []string{"lstopo architecture.png", "hwloc-ls machine.xml"}
cmd, ok := metric.ListOptions["command"]
if ok {
m.commands = []string{}
for _, val := range cmd {
m.commands = append(m.commands, val.StrVal)
}
}
}
func (m Hwloc) ListOptions() map[string][]intstr.IntOrString {
opts := map[string][]intstr.IntOrString{}
for _, val := range m.commands {
opts["commands"] = append(opts["commands"], intstr.FromString(val))
}
return opts
}
func (m Hwloc) PrepareContainers(
spec *api.MetricSet,
metric *metrics.Metric,
) []*specs.ContainerSpec {
// Metadata to add to beginning of run
meta := metrics.Metadata(spec, metric)
// Assemble commands into separate things
commands := ""
for _, cmd := range m.commands {
commands += fmt.Sprintf("\necho %s\n%s\n echo '%s'", cmd, cmd, metadata.Separator)
}
preBlock := `#!/bin/bash
echo "%s"
. /root/.profile
export PATH=/opt/view/bin:$PATH
echo "%s"
%s
echo "%s"
ls
`
interactive := metadata.Interactive(spec.Spec.Logging.Interactive)
preBlock = fmt.Sprintf(
preBlock,
meta,
metadata.CollectionStart,
commands,
metadata.CollectionEnd,
)
postBlock := fmt.Sprintf("\n%s\n", interactive)
return m.ApplicationContainerSpec(preBlock, "", postBlock)
}
func init() {
base := metrics.BaseMetric{
Identifier: hwlocIdentifier,
Summary: hwlocSummary,
Container: hwlocContainer,
}
app := metrics.SingleApplication{BaseMetric: base}
Hwloc := Hwloc{SingleApplication: app}
metrics.Register(&Hwloc)
}