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

fix: Set the default value correctly #9980

Merged
merged 7 commits into from
Nov 8, 2021
Merged
Changes from 1 commit
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
20 changes: 15 additions & 5 deletions plugins/inputs/nvidia_smi/nvidia_smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package nvidia_smi

import (
"encoding/xml"
"fmt"
"errors"
srebhan marked this conversation as resolved.
Show resolved Hide resolved
"os"
"os/exec"
"strconv"
Expand Down Expand Up @@ -39,12 +39,23 @@ func (smi *NvidiaSMI) SampleConfig() string {
`
}

// Gather implements the telegraf interface
func (smi *NvidiaSMI) Gather(acc telegraf.Accumulator) error {
func (smi *NvidiaSMI) Init() error {
Hipska marked this conversation as resolved.
Show resolved Hide resolved
if len(smi.BinPath) == 0 {
since1986 marked this conversation as resolved.
Show resolved Hide resolved
var err error
smi.BinPath, err = exec.LookPath("nvidia-smi")
if err != nil {
return errors.New("nvidia-smi not found: verify that nvidia-smi is installed and that nvidia-smi is in your PATH")
}
}
if _, err := os.Stat(smi.BinPath); os.IsNotExist(err) {
return fmt.Errorf("nvidia-smi binary not at path %s, cannot gather GPU data", smi.BinPath)
return errors.New("nvidia-smi binary not at path " + smi.BinPath)
Hipska marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
}

// Gather implements the telegraf interface
func (smi *NvidiaSMI) Gather(acc telegraf.Accumulator) error {
data, err := smi.pollSMI()
if err != nil {
return err
Expand All @@ -61,7 +72,6 @@ func (smi *NvidiaSMI) Gather(acc telegraf.Accumulator) error {
func init() {
inputs.Add("nvidia_smi", func() telegraf.Input {
return &NvidiaSMI{
BinPath: "/usr/bin/nvidia-smi",
Timeout: config.Duration(5 * time.Second),
}
})
Expand Down