Skip to content

Commit

Permalink
Move client scraping and metric aggregation into a separate thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpeshansky committed Jul 28, 2024
1 parent b779893 commit c91caf6
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 224 deletions.
7 changes: 6 additions & 1 deletion receiver/dcgmreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package dcgmreceiver
import (
"errors"
"fmt"
"sync"
"time"

"github.com/NVIDIA/go-dcgm/pkg/dcgm"
Expand Down Expand Up @@ -65,6 +66,7 @@ type dcgmMetric struct {
var dcgmInit = func(args ...string) (func(), error) {
return dcgm.Init(dcgm.Standalone, args...)
}
var dcgmInitMutex sync.Mutex

var dcgmGetLatestValuesForFields = dcgm.GetLatestValuesForFields

Expand Down Expand Up @@ -126,7 +128,10 @@ func newClient(settings *dcgmClientSettings, logger *zap.Logger) (*dcgmClient, e
// only if the connection is initialized successfully without error
func initializeDcgm(endpoint string, logger *zap.Logger) (func(), error) {
isSocket := "0"
dcgmCleanup, err := dcgmInit(endpoint, isSocket)
dcgmInitMutex.Lock()
dcgmInitFunc := dcgmInit
dcgmInitMutex.Unlock()
dcgmCleanup, err := dcgmInitFunc(endpoint, isSocket)
if err != nil {
msg := fmt.Sprintf("Unable to connect to DCGM daemon at %s on %v; Is the DCGM daemon running?", endpoint, err)
logger.Sugar().Warn(msg)
Expand Down
Loading

0 comments on commit c91caf6

Please sign in to comment.