2021-06-01 11:20:03 +00:00
|
|
|
package metricsconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-07-13 09:26:40 +00:00
|
|
|
subsection = "prometheus"
|
|
|
|
subsectionOld = "metrics"
|
2021-06-01 11:20:03 +00:00
|
|
|
|
2021-06-02 12:44:41 +00:00
|
|
|
// ShutdownTimeoutDefault is a default value for metrics HTTP service timeout.
|
2021-06-01 11:20:03 +00:00
|
|
|
ShutdownTimeoutDefault = 30 * time.Second
|
2021-06-02 12:44:41 +00:00
|
|
|
|
|
|
|
// AddressDefault is a default value for metrics HTTP service endpoint.
|
2022-07-13 09:17:37 +00:00
|
|
|
AddressDefault = "localhost:9090"
|
2021-06-01 11:20:03 +00:00
|
|
|
)
|
|
|
|
|
2022-07-13 09:17:37 +00:00
|
|
|
// Enabled returns the value of "enabled" config parameter
|
|
|
|
// from "metrics" section.
|
|
|
|
//
|
|
|
|
// Returns false if the value is missing or invalid.
|
|
|
|
func Enabled(c *config.Config) bool {
|
2022-07-13 09:26:40 +00:00
|
|
|
s := c.Sub(subsection)
|
|
|
|
s.SetDefault(c.Sub(subsectionOld))
|
|
|
|
|
|
|
|
return config.BoolSafe(s, "enabled")
|
2022-07-13 09:17:37 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// ShutdownTimeout returns the value of "shutdown_timeout" config parameter
|
2021-06-01 11:20:03 +00:00
|
|
|
// from "metrics" section.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns ShutdownTimeoutDefault if the value is not positive duration.
|
2021-06-01 11:20:03 +00:00
|
|
|
func ShutdownTimeout(c *config.Config) time.Duration {
|
2022-07-13 09:26:40 +00:00
|
|
|
s := c.Sub(subsection)
|
|
|
|
s.SetDefault(c.Sub(subsectionOld))
|
|
|
|
|
|
|
|
v := config.DurationSafe(s, "shutdown_timeout")
|
2021-06-02 12:44:41 +00:00
|
|
|
if v > 0 {
|
2021-06-01 11:20:03 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return ShutdownTimeoutDefault
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Address returns the value of "address" config parameter
|
2021-06-01 11:20:03 +00:00
|
|
|
// from "metrics" section.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns AddressDefault if the value is not set.
|
2021-06-01 11:20:03 +00:00
|
|
|
func Address(c *config.Config) string {
|
2022-07-13 09:26:40 +00:00
|
|
|
s := c.Sub(subsection)
|
|
|
|
s.SetDefault(c.Sub(subsectionOld))
|
|
|
|
|
|
|
|
v := config.StringSafe(s, "address")
|
2021-06-01 11:20:03 +00:00
|
|
|
if v != "" {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return AddressDefault
|
|
|
|
}
|