2022-12-23 12:28:30 +00:00
|
|
|
package api
|
2020-07-16 12:42:06 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/internal/version"
|
2020-07-16 12:42:06 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stats struct {
|
|
|
|
desc *prometheus.Desc
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
versionInfo = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
2022-12-20 08:38:58 +00:00
|
|
|
Namespace: "frostfs_s3",
|
2020-07-16 12:42:06 +00:00
|
|
|
Name: "version_info",
|
2022-12-20 08:38:58 +00:00
|
|
|
Help: "Version of current FrostFS S3 Gate instance",
|
2020-07-16 12:42:06 +00:00
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
// current version
|
|
|
|
"version",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
statsMetrics = &stats{
|
2022-12-20 08:38:58 +00:00
|
|
|
desc: prometheus.NewDesc("frostfs_s3_stats", "Statistics exposed by FrostFS S3 Gate instance", nil, nil),
|
2020-07-16 12:42:06 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
prometheus.MustRegister(versionInfo)
|
|
|
|
prometheus.MustRegister(statsMetrics)
|
|
|
|
prometheus.MustRegister(httpRequestsDuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
func collectNetworkMetrics(ch chan<- prometheus.Metric) {
|
|
|
|
// Network Sent/Received Bytes (Outbound)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2022-12-20 08:38:58 +00:00
|
|
|
prometheus.BuildFQName("frostfs_s3", "tx", "bytes_total"),
|
|
|
|
"Total number of bytes sent by current FrostFS S3 Gate instance",
|
2020-07-16 12:42:06 +00:00
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(httpStatsMetric.getInputBytes()),
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2022-12-20 08:38:58 +00:00
|
|
|
prometheus.BuildFQName("frostfs_s3", "rx", "bytes_total"),
|
|
|
|
"Total number of bytes received by current FrostFS S3 Gate instance",
|
2020-07-16 12:42:06 +00:00
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(httpStatsMetric.getOutputBytes()),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stats) Describe(ch chan<- *prometheus.Desc) {
|
|
|
|
ch <- s.desc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stats) Collect(ch chan<- prometheus.Metric) {
|
|
|
|
// Expose current version information
|
2021-05-20 12:41:32 +00:00
|
|
|
versionInfo.WithLabelValues(version.Version).Set(1.0)
|
2020-07-16 12:42:06 +00:00
|
|
|
|
|
|
|
// connect collectors
|
|
|
|
collectHTTPMetrics(ch)
|
|
|
|
collectNetworkMetrics(ch)
|
|
|
|
}
|