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 25, 2024
1 parent 2bb903c commit 11c9289
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 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
29 changes: 18 additions & 11 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,17 +935,9 @@ func writeSystemAttributes(c *cfg) error {
var paths []string
for _, sh := range c.applicationConfiguration.engine.shards {
for _, subStorage := range sh.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
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("accessing %q: %w", path, err)
}
path = filepath.Dir(path)
path, err := getInitPath(subStorage.Path)
if err != nil {
return err
}

paths = append(paths, path)
Expand All @@ -961,3 +953,18 @@ func writeSystemAttributes(c *cfg) error {

return nil
}

func getInitPath(path string) (string, error) {
for len(path) > 1 { // Dir returns / or . if nothing else left.
fi, err := os.Stat(path)
if err == nil && fi.IsDir() {
break
}
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("accessing %q: %w", path, err)
}
path = filepath.Dir(path)
}

return path, nil
}
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)

c.setHealthStatus(control.HealthStatus_STARTING)

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

import (
"fmt"

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 +27,26 @@ 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, err := getInitPath(subStorage.Path)
if err != nil {
return err
}

paths = append(paths, path)
}

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

c.metricsCollector.SetCapacitySize(sh.ID.String(), capacity)
}

return nil
}
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",
}, []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))
}

0 comments on commit 11c9289

Please sign in to comment.