2022-03-25 11:24:23 +08:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/xtls/xray-core/app/metrics"
|
2024-06-29 14:32:57 -04:00
|
|
|
"github.com/xtls/xray-core/common/errors"
|
2022-03-25 11:24:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type MetricsConfig struct {
|
2025-02-18 19:32:48 +08:00
|
|
|
Tag string `json:"tag"`
|
|
|
|
Listen string `json:"listen"`
|
2022-03-25 11:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MetricsConfig) Build() (*metrics.Config, error) {
|
2025-02-18 19:32:48 +08:00
|
|
|
if c.Listen == "" && c.Tag == "" {
|
|
|
|
return nil, errors.New("Metrics must have a tag or listen address.")
|
|
|
|
}
|
|
|
|
// If the tag is empty but have "listen" set a default "Metrics" for compatibility.
|
2022-03-25 11:24:23 +08:00
|
|
|
if c.Tag == "" {
|
2025-02-18 19:32:48 +08:00
|
|
|
c.Tag = "Metrics"
|
2022-03-25 11:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return &metrics.Config{
|
2025-02-18 19:32:48 +08:00
|
|
|
Tag: c.Tag,
|
|
|
|
Listen: c.Listen,
|
2022-03-25 11:24:23 +08:00
|
|
|
}, nil
|
|
|
|
}
|