Skip to content

Commit

Permalink
storagenode: fix disk monitoring for FreeBSD
Browse files Browse the repository at this point in the history
Change-Id: I0951a252e8bd77468296290dd76f23f931543a98
  • Loading branch information
egonelbre committed Apr 24, 2024
1 parent 7bfcb48 commit 448d663
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
34 changes: 34 additions & 0 deletions storagenode/diskmon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.

//go:build linux || windows || (darwin && cgo)

package storagenode

import (
"os"
"sync"

hw "github.com/jtolds/monkit-hw/v2"
"github.com/spacemonkeygo/monkit/v3"
"go.uber.org/zap"

"storj.io/storj/storagenode/load"
)

var (
onceInitializeDiskMon sync.Once
)

func init() {
hw.Register(monkit.Default)
mon.Chain(hw.CPU())
mon.Chain(hw.Load())
}

func initializeDiskMon(log *zap.Logger) {
onceInitializeDiskMon.Do(func() {
pid := os.Getpid()
mon.Chain(load.DiskIO(log.Named("diskio"), int32(pid)))
})
}
10 changes: 10 additions & 0 deletions storagenode/diskmon_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (C) 2024 Storj Labs, Inc.
// See LICENSE for copying information.

//go:build !(linux || windows || (darwin && cgo))

package storagenode

import "go.uber.org/zap"

func initializeDiskMon(log *zap.Logger) {}
20 changes: 2 additions & 18 deletions storagenode/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import (
"net"
"os"
"path/filepath"
"sync"
"time"

hw "github.com/jtolds/monkit-hw/v2"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/errs"
"go.uber.org/zap"
Expand Down Expand Up @@ -47,7 +45,6 @@ import (
"storj.io/storj/storagenode/healthcheck"
"storj.io/storj/storagenode/inspector"
"storj.io/storj/storagenode/internalpb"
"storj.io/storj/storagenode/load"
"storj.io/storj/storagenode/monitor"
"storj.io/storj/storagenode/multinode"
"storj.io/storj/storagenode/nodestats"
Expand All @@ -71,17 +68,7 @@ import (
snVersion "storj.io/storj/storagenode/version"
)

var (
mon = monkit.Package()

initDiskMon sync.Once
)

func init() {
hw.Register(monkit.Default)
mon.Chain(hw.CPU())
mon.Chain(hw.Load())
}
var mon = monkit.Package()

// Assets contains either the built admin/back-office/ui or it is nil.
var Assets fs.FS = emptyfs.FS{}
Expand Down Expand Up @@ -339,10 +326,7 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, revocationDB exten
Services: lifecycle.NewGroup(process.NamedLog(log, "services")),
}

initDiskMon.Do(func() {
pid := os.Getpid()
mon.Chain(load.DiskIO(log.Named("diskio"), int32(pid)))
})
initializeDiskMon(log)

{ // setup notification service.
peer.Notifications.Service = notifications.NewService(peer.Log, peer.DB.Notifications())
Expand Down

0 comments on commit 448d663

Please sign in to comment.