Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[exporter/trace] remove dependency on proc_trace.html #111

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ builds:
nfpms:
- vendor: rivosinc
maintainer: abhinavDhulipala
contents:
- src: exporter/templates
dst: /usr/share/prometheus-slurm-exporter/templates
file_info:
mode: 0644
group: root
owner: root
formats:
- apk
- deb
Expand All @@ -29,6 +22,3 @@ nfpms:
- archlinux
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}'
files:
- src: ./exporter/templates/*
dst: templates
33 changes: 0 additions & 33 deletions exporter/templates/proc_traces.html

This file was deleted.

46 changes: 34 additions & 12 deletions exporter/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
Expand All @@ -20,10 +19,39 @@ import (
"log/slog"
)

// cleanup on add if greater than this threshold
const (
cleanupThreshold uint64 = 1_000
templateDirName string = "templates"
// cleanup on add if greater than this threshold
cleanupThreshold uint64 = 1_000
templateDirName string = "templates"
proctraceTemplate string = `
<html lang="en">
<body>
<table>
<tr>
<th> Job Id </th>
<th> Process Id </th>
<th> Cpu % </th>
<th> I/O Wait </th>
<th> Memory Usage </th>
<th> Username </th>
<th> Hostname </th>
</tr>
{{ range . }}
<tr>
<td> {{ .JobId }} </td>
<td> {{ .Pid}} </td>
<td> {{ .Cpus }} </td>
<td> {{ .WriteBytes }} </td>
<td> {{ .ReadBytes }} </td>
<td> {{ .Mem }} </td>
<td> {{ .Username }} </td>
<td> {{ .Hostname }} </td>
</tr>
{{ end }}
</table>
</body>
</html>
`
)

// store a jobs published proc stats
Expand Down Expand Up @@ -94,7 +122,6 @@ type TraceCollector struct {
ProcessFetcher *AtomicProcFetcher
squeueFetcher SlurmMetricFetcher[JobMetric]
fallback bool
templatesDir string
// actual proc monitoring
jobAllocMem *prometheus.Desc
jobAllocCpus *prometheus.Desc
Expand All @@ -108,16 +135,10 @@ type TraceCollector struct {

func NewTraceCollector(config *Config) *TraceCollector {
traceConfig := config.TraceConf
traceDir := detectTraceTemplatePath()
if traceDir == "" {
log.Fatal("no template found")
}
slog.Debug("using trace template path: " + traceDir)
return &TraceCollector{
ProcessFetcher: NewAtomicProFetcher(traceConfig.rate),
squeueFetcher: traceConfig.sharedFetcher,
fallback: config.cliOpts.fallback,
templatesDir: traceDir,
// add for job id correlation
jobAllocMem: prometheus.NewDesc("slurm_job_mem_alloc", "running job mem allocated", []string{"jobid"}, nil),
jobAllocCpus: prometheus.NewDesc("slurm_job_cpu_alloc", "running job cpus allocated", []string{"jobid"}, nil),
Expand Down Expand Up @@ -178,7 +199,8 @@ func (c *TraceCollector) uploadTrace(w http.ResponseWriter, r *http.Request) {
}
}
if r.Method == http.MethodGet {
tmpl := template.Must(template.ParseFiles(filepath.Join(c.templatesDir, "proc_traces.html")))

tmpl := template.Must(template.New("proc_traces").Parse(proctraceTemplate))
procs := c.ProcessFetcher.Fetch()
traces := make([]TraceInfo, 0, len(procs))
for _, info := range procs {
Expand Down
Loading