Skip to content

Commit

Permalink
remove dependency on proc_trace.html
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavDhulipala committed Dec 23, 2024
1 parent aa11877 commit 4d58487
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 55 deletions.
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

0 comments on commit 4d58487

Please sign in to comment.