forked from TrueCloudLab/frostfs-node
[#451] metrics: Move to internal
`metrics` don't look like something others want to import. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
11a38a0a84
commit
81ea91de52
35 changed files with 14 additions and 14 deletions
89
internal/metrics/mode.go
Normal file
89
internal/metrics/mode.go
Normal file
|
@ -0,0 +1,89 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type shardIDModeValue struct {
|
||||
modeValue *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func newShardIDMode(subsystem, name, help string) *shardIDModeValue {
|
||||
return &shardIDModeValue{
|
||||
modeValue: metrics.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
}, []string{shardIDLabel, modeLabel}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *shardIDModeValue) SetMode(shardID, mode string) {
|
||||
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
})
|
||||
|
||||
m.modeValue.With(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
modeLabel: mode,
|
||||
}).Set(1)
|
||||
}
|
||||
|
||||
func (m *shardIDModeValue) Delete(shardID string) {
|
||||
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
})
|
||||
}
|
||||
|
||||
type shardIDPathModeValue struct {
|
||||
modeValue *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func newShardIDPathMode(subsystem, name, help string) *shardIDPathModeValue {
|
||||
return &shardIDPathModeValue{
|
||||
modeValue: metrics.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: name,
|
||||
Help: help,
|
||||
}, []string{shardIDLabel, pathLabel, modeLabel}),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *shardIDPathModeValue) SetMode(shardID, path, mode string) {
|
||||
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
pathLabel: path,
|
||||
})
|
||||
|
||||
m.modeValue.With(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
pathLabel: path,
|
||||
modeLabel: mode,
|
||||
}).Set(1)
|
||||
}
|
||||
|
||||
func (m *shardIDPathModeValue) Delete(shardID, path string) {
|
||||
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
pathLabel: path,
|
||||
})
|
||||
}
|
||||
|
||||
func (m *shardIDPathModeValue) DeleteByShardID(shardID string) {
|
||||
m.modeValue.DeletePartialMatch(prometheus.Labels{
|
||||
shardIDLabel: shardID,
|
||||
})
|
||||
}
|
||||
|
||||
func modeFromBool(readOnly bool) string {
|
||||
modeValue := readWriteMode
|
||||
if readOnly {
|
||||
modeValue = readOnlyMode
|
||||
}
|
||||
return modeValue
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue