Skip to content

Commit

Permalink
fix: nvidia plugin scrapes without qFields initialization (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored Feb 29, 2024
1 parent d65fa08 commit 9fcdccb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion inputs/nvidia_smi/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *GPUStats) buildQFieldToRFieldMap() ([]qField, map[qField]rField, error)
qFields = parsed
}

resultTable, err := s.scrape()
resultTable, err := s.scrape(qFields)

var rFields []rField

Expand Down
2 changes: 1 addition & 1 deletion inputs/nvidia_smi/nvidia_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *GPUStats) Gather(slist *types.SampleList) {
slist.PushFront(types.NewSample(inputName, "scrape_use_seconds", use))
}(begun)

currentTable, err := s.scrape()
currentTable, err := s.scrape(s.qFields)
if err != nil {
slist.PushFront(types.NewSample(inputName, "scraper_up", 0))
return
Expand Down
6 changes: 3 additions & 3 deletions inputs/nvidia_smi/scrape.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"flashcat.cloud/categraf/pkg/cmdx"
)

func (s *GPUStats) scrape() (*table, error) {
qFieldsJoined := strings.Join(QFieldSliceToStringSlice(s.qFields), ",")
func (s *GPUStats) scrape(qFields []qField) (*table, error) {
qFieldsJoined := strings.Join(QFieldSliceToStringSlice(qFields), ",")

cmdAndArgs := strings.Fields(s.NvidiaSmiCommand)
cmdAndArgs = append(cmdAndArgs, fmt.Sprintf("--query-gpu=%s", qFieldsJoined))
Expand All @@ -34,7 +34,7 @@ func (s *GPUStats) scrape() (*table, error) {
strings.Join(cmdAndArgs, " "), err, stdout.String(), stderr.String())
}

t, err := parseCSVIntoTable(strings.TrimSpace(stdout.String()), s.qFields)
t, err := parseCSVIntoTable(strings.TrimSpace(stdout.String()), qFields)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9fcdccb

Please sign in to comment.