2023-04-07 15:14:31 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2023-04-10 09:22:11 +00:00
|
|
|
dto "github.com/prometheus/client_model/go"
|
2023-04-07 15:14:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var appMetricsDesc = map[string]map[string]Description{
|
|
|
|
poolSubsystem: {
|
|
|
|
overallErrorsMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: poolSubsystem,
|
|
|
|
Name: overallErrorsMetric,
|
|
|
|
Help: "Total number of errors in pool",
|
|
|
|
},
|
|
|
|
overallNodeErrorsMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: poolSubsystem,
|
|
|
|
Name: overallNodeErrorsMetric,
|
|
|
|
Help: "Total number of errors for connection in pool",
|
|
|
|
VariableLabels: []string{"node"},
|
|
|
|
},
|
|
|
|
overallNodeRequestsMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: poolSubsystem,
|
|
|
|
Name: overallNodeRequestsMetric,
|
|
|
|
Help: "Total number of requests to specific node in pool",
|
|
|
|
VariableLabels: []string{"node"},
|
|
|
|
},
|
|
|
|
currentErrorMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: poolSubsystem,
|
|
|
|
Name: currentErrorMetric,
|
|
|
|
Help: "Number of errors on current connections that will be reset after the threshold",
|
|
|
|
VariableLabels: []string{"node"},
|
|
|
|
},
|
|
|
|
avgRequestDurationMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: poolSubsystem,
|
|
|
|
Name: avgRequestDurationMetric,
|
|
|
|
Help: "Average request duration (in milliseconds) for specific method on node in pool",
|
|
|
|
VariableLabels: []string{"node", "method"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
stateSubsystem: {
|
|
|
|
healthMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: stateSubsystem,
|
|
|
|
Name: healthMetric,
|
|
|
|
Help: "Current HTTP gateway state",
|
|
|
|
},
|
|
|
|
versionInfoMetric: Description{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: dto.MetricType_GAUGE,
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: stateSubsystem,
|
|
|
|
Name: versionInfoMetric,
|
|
|
|
Help: "Version of current FrostFS HTTP Gate instance",
|
|
|
|
VariableLabels: []string{"version"},
|
|
|
|
},
|
|
|
|
},
|
2023-08-29 12:17:20 +00:00
|
|
|
serverSubsystem: {
|
|
|
|
healthMetric: Description{
|
|
|
|
Type: dto.MetricType_GAUGE,
|
|
|
|
Namespace: namespace,
|
|
|
|
Subsystem: serverSubsystem,
|
|
|
|
Name: healthMetric,
|
|
|
|
Help: "HTTP Server endpoint health",
|
|
|
|
VariableLabels: []string{"endpoint"},
|
|
|
|
},
|
|
|
|
},
|
2023-04-07 15:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Description struct {
|
2023-04-10 09:22:11 +00:00
|
|
|
Type dto.MetricType
|
2023-04-07 15:14:31 +00:00
|
|
|
Namespace string
|
|
|
|
Subsystem string
|
|
|
|
Name string
|
|
|
|
Help string
|
2023-04-19 12:18:15 +00:00
|
|
|
ConstantLabels prometheus.Labels
|
2023-04-07 15:14:31 +00:00
|
|
|
VariableLabels []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Description) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(&struct {
|
2023-04-19 12:18:15 +00:00
|
|
|
Type string `json:"type"`
|
|
|
|
FQName string `json:"name"`
|
|
|
|
Help string `json:"help"`
|
|
|
|
ConstantLabels prometheus.Labels `json:"constant_labels,omitempty"`
|
|
|
|
VariableLabels []string `json:"variable_labels,omitempty"`
|
2023-04-07 15:14:31 +00:00
|
|
|
}{
|
2023-04-10 09:22:11 +00:00
|
|
|
Type: d.Type.String(),
|
2023-04-07 15:14:31 +00:00
|
|
|
FQName: d.BuildFQName(),
|
|
|
|
Help: d.Help,
|
|
|
|
ConstantLabels: d.ConstantLabels,
|
|
|
|
VariableLabels: d.VariableLabels,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Description) BuildFQName() string {
|
|
|
|
return prometheus.BuildFQName(d.Namespace, d.Subsystem, d.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DescribeAll returns descriptions for metrics.
|
|
|
|
func DescribeAll() []Description {
|
|
|
|
var list []Description
|
|
|
|
for _, m := range appMetricsDesc {
|
|
|
|
for _, description := range m {
|
|
|
|
list = append(list, description)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
|
|
|
func newOpts(description Description) prometheus.Opts {
|
|
|
|
return prometheus.Opts{
|
|
|
|
Namespace: description.Namespace,
|
|
|
|
Subsystem: description.Subsystem,
|
|
|
|
Name: description.Name,
|
|
|
|
Help: description.Help,
|
2023-04-19 12:18:15 +00:00
|
|
|
ConstLabels: description.ConstantLabels,
|
2023-04-07 15:14:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-10 09:22:11 +00:00
|
|
|
func mustNewGauge(description Description) prometheus.Gauge {
|
|
|
|
if description.Type != dto.MetricType_GAUGE {
|
|
|
|
panic("invalid metric type")
|
|
|
|
}
|
2023-04-07 15:14:31 +00:00
|
|
|
return prometheus.NewGauge(
|
|
|
|
prometheus.GaugeOpts(newOpts(description)),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-04-10 09:22:11 +00:00
|
|
|
func mustNewGaugeVec(description Description) *prometheus.GaugeVec {
|
|
|
|
if description.Type != dto.MetricType_GAUGE {
|
|
|
|
panic("invalid metric type")
|
|
|
|
}
|
2023-04-07 15:14:31 +00:00
|
|
|
return prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts(newOpts(description)),
|
|
|
|
description.VariableLabels,
|
|
|
|
)
|
|
|
|
}
|