Skip to content

Commit

Permalink
node: add neofs_node_engine_capacity metric
Browse files Browse the repository at this point in the history
Expose metric for shard's capacity.

Closes #1794.

Signed-off-by: Andrey Butusov <[email protected]>
  • Loading branch information
End-rey committed Nov 22, 2024
1 parent 2bb903c commit 14b21ae
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- New `peapod-to-fstree` tool providing peapod-to-fstree data migration (#3013)
- Reloading node attributes with SIGHUP (#3005)
- Reloading pool sizes (#3018)
- Add metrics for shard's capacity (#3021)

### Fixed
- Do not search for tombstones when handling their expiration, use local indexes instead (#2929)
Expand Down
3 changes: 3 additions & 0 deletions cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func main() {

initApp(c)

err = c.setShardsCapacity()
fatalOnErr(err)

Check warning on line 66 in cmd/neofs-node/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/main.go#L64-L66

Added lines #L64 - L66 were not covered by tests
c.setHealthStatus(control.HealthStatus_STARTING)

bootUp(c)
Expand Down
37 changes: 37 additions & 0 deletions cmd/neofs-node/metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package main

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"

metricsconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/metrics"
httputil "github.com/nspcc-dev/neofs-node/pkg/util/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -25,3 +31,34 @@ func initMetrics(c *cfg) *httputil.Server {

return srv
}

func (c *cfg) setShardsCapacity() error {
for _, sh := range c.cfgObject.cfgLocalStorage.localStorage.DumpInfo().Shards {
paths := make([]string, 0, len(sh.BlobStorInfo.SubStorages))
for _, subStorage := range sh.BlobStorInfo.SubStorages {
path := subStorage.Path

for len(path) > 1 { // Dir returns / or . if nothing else left.
fi, err := os.Stat(path)
if err == nil && fi.IsDir() {
break

Check warning on line 44 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L35-L44

Added lines #L35 - L44 were not covered by tests
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("accessing %q: %w", path, err)
}
path = filepath.Dir(path)

Check warning on line 49 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L46-L49

Added lines #L46 - L49 were not covered by tests
}

paths = append(paths, path)

Check warning on line 52 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L52

Added line #L52 was not covered by tests
}

capacity, err := totalBytes(paths)
if err != nil {
return fmt.Errorf("calculating capacity on shard %s: %w", sh.ID.String(), err)
}

Check warning on line 58 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L55-L58

Added lines #L55 - L58 were not covered by tests

c.metricsCollector.SetCapacitySize(sh.ID.String(), capacity/(1<<30))

Check warning on line 60 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L60

Added line #L60 was not covered by tests
}

return nil

Check warning on line 63 in cmd/neofs-node/metrics.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/metrics.go#L63

Added line #L63 was not covered by tests
}
14 changes: 14 additions & 0 deletions pkg/metrics/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type (

containerSize prometheus.GaugeVec
payloadSize prometheus.GaugeVec
capacitySize prometheus.GaugeVec
}
)

Expand Down Expand Up @@ -121,6 +122,13 @@ func newEngineMetrics() engineMetrics {
Name: "payload_size",
Help: "Accumulated size of all objects in a shard",
}, []string{shardIDLabelKey})

capacitySize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: storageNodeNameSpace,
Subsystem: engineSubsystem,
Name: "capacity",
Help: "Contains the shard's capacity, GB",
}, []string{shardIDLabelKey})
)

return engineMetrics{
Expand All @@ -137,6 +145,7 @@ func newEngineMetrics() engineMetrics {
listObjectsDuration: listObjectsDuration,
containerSize: *containerSize,
payloadSize: *payloadSize,
capacitySize: *capacitySize,
}
}

Expand All @@ -154,6 +163,7 @@ func (m engineMetrics) register() {
prometheus.MustRegister(m.listObjectsDuration)
prometheus.MustRegister(m.containerSize)
prometheus.MustRegister(m.payloadSize)
prometheus.MustRegister(m.capacitySize)
}

func (m engineMetrics) AddListContainersDuration(d time.Duration) {
Expand Down Expand Up @@ -211,3 +221,7 @@ func (m engineMetrics) AddToContainerSize(cnrID string, size int64) {
func (m engineMetrics) AddToPayloadCounter(shardID string, size int64) {
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
}

func (m engineMetrics) SetCapacitySize(shardID string, capacity uint64) {
m.capacitySize.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(float64(capacity))

Check warning on line 226 in pkg/metrics/engine.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/engine.go#L225-L226

Added lines #L225 - L226 were not covered by tests
}

0 comments on commit 14b21ae

Please sign in to comment.