Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dc7599f3ee | |||
| f16cf7cb14 | |||
| 86b265c2a9 |
@@ -15,7 +15,7 @@ FRONTEND_WEB_SRC := $(shell find cmd/frontend/web/src -type f 2>/dev/null) \
|
|||||||
FRONTEND_WEB_DIST := cmd/frontend/web/dist/index.html
|
FRONTEND_WEB_DIST := cmd/frontend/web/dist/index.html
|
||||||
|
|
||||||
NATIVE_ARCH := $(shell go env GOARCH)
|
NATIVE_ARCH := $(shell go env GOARCH)
|
||||||
VERSION := 1.1.0
|
VERSION := 1.1.2
|
||||||
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
COMMIT_HASH := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
|
||||||
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||||
LDFLAGS := -X '$(MODULE)/cmd.version=$(VERSION)' \
|
LDFLAGS := -X '$(MODULE)/cmd.version=$(VERSION)' \
|
||||||
|
|||||||
+1
-1
@@ -150,7 +150,7 @@ func run() error {
|
|||||||
if vppClient != nil {
|
if vppClient != nil {
|
||||||
vppSrc = vppClient
|
vppSrc = vppClient
|
||||||
}
|
}
|
||||||
metrics.Register(reg, chkr, vppSrc)
|
metrics.Register(reg, chkr, vppSrc, cfg.SourceTag)
|
||||||
reg.MustRegister(grpcMetrics)
|
reg.MustRegister(grpcMetrics)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
|
|
||||||
// Config is the top-level parsed and validated configuration.
|
// Config is the top-level parsed and validated configuration.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
SourceTag string // this node's nginx source tag; defaults to the short hostname
|
||||||
HealthChecker HealthCheckerConfig
|
HealthChecker HealthCheckerConfig
|
||||||
VPP VPPConfig
|
VPP VPPConfig
|
||||||
HealthChecks map[string]HealthCheck
|
HealthChecks map[string]HealthCheck
|
||||||
@@ -163,6 +164,7 @@ type rawConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type rawMaglev struct {
|
type rawMaglev struct {
|
||||||
|
SourceTag string `yaml:"source-tag"`
|
||||||
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
|
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
|
||||||
VPP rawVPPCfg `yaml:"vpp"`
|
VPP rawVPPCfg `yaml:"vpp"`
|
||||||
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
|
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
|
||||||
@@ -299,6 +301,18 @@ func parse(data []byte) (*Config, error) {
|
|||||||
func convert(r *rawMaglev) (*Config, error) {
|
func convert(r *rawMaglev) (*Config, error) {
|
||||||
cfg := &Config{}
|
cfg := &Config{}
|
||||||
|
|
||||||
|
// ---- source-tag -----------------------------------------------------------
|
||||||
|
cfg.SourceTag = r.SourceTag
|
||||||
|
if cfg.SourceTag == "" {
|
||||||
|
if h, err := os.Hostname(); err == nil {
|
||||||
|
if dot := strings.IndexByte(h, '.'); dot > 0 {
|
||||||
|
cfg.SourceTag = h[:dot]
|
||||||
|
} else {
|
||||||
|
cfg.SourceTag = h
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ---- healthchecker --------------------------------------------------------
|
// ---- healthchecker --------------------------------------------------------
|
||||||
cfg.HealthChecker.Netns = r.HealthChecker.Netns
|
cfg.HealthChecker.Netns = r.HealthChecker.Netns
|
||||||
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
|
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
|
||||||
|
|||||||
@@ -131,9 +131,11 @@ var (
|
|||||||
// on each scrape. This avoids stale label sets when backends are added or
|
// on each scrape. This avoids stale label sets when backends are added or
|
||||||
// removed by a config reload.
|
// removed by a config reload.
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
src StateSource
|
src StateSource
|
||||||
vpp VPPSource // optional; nil when VPP integration is disabled
|
vpp VPPSource // optional; nil when VPP integration is disabled
|
||||||
|
sourceTag string
|
||||||
|
|
||||||
|
maglevInfo *prometheus.Desc
|
||||||
backendState *prometheus.Desc
|
backendState *prometheus.Desc
|
||||||
backendHealth *prometheus.Desc
|
backendHealth *prometheus.Desc
|
||||||
backendEnabled *prometheus.Desc
|
backendEnabled *prometheus.Desc
|
||||||
@@ -152,10 +154,16 @@ type Collector struct {
|
|||||||
// NewCollector creates a Collector backed by the given StateSource. vpp may
|
// NewCollector creates a Collector backed by the given StateSource. vpp may
|
||||||
// be nil when VPP integration is disabled; in that case vpp_* metrics are
|
// be nil when VPP integration is disabled; in that case vpp_* metrics are
|
||||||
// simply not emitted.
|
// simply not emitted.
|
||||||
func NewCollector(src StateSource, vpp VPPSource) *Collector {
|
func NewCollector(src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||||
return &Collector{
|
return &Collector{
|
||||||
src: src,
|
src: src,
|
||||||
vpp: vpp,
|
vpp: vpp,
|
||||||
|
sourceTag: sourceTag,
|
||||||
|
maglevInfo: prometheus.NewDesc(
|
||||||
|
"maglev_info",
|
||||||
|
"Static maglevd instance metadata. Always 1; metadata is conveyed via labels.",
|
||||||
|
[]string{"source_tag"}, nil,
|
||||||
|
),
|
||||||
backendState: prometheus.NewDesc(
|
backendState: prometheus.NewDesc(
|
||||||
"maglev_backend_state",
|
"maglev_backend_state",
|
||||||
"Current backend state (1 = active for the given state label).",
|
"Current backend state (1 = active for the given state label).",
|
||||||
@@ -216,6 +224,7 @@ func NewCollector(src StateSource, vpp VPPSource) *Collector {
|
|||||||
|
|
||||||
// Describe implements prometheus.Collector.
|
// Describe implements prometheus.Collector.
|
||||||
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
ch <- c.maglevInfo
|
||||||
ch <- c.backendState
|
ch <- c.backendState
|
||||||
ch <- c.backendHealth
|
ch <- c.backendHealth
|
||||||
ch <- c.backendEnabled
|
ch <- c.backendEnabled
|
||||||
@@ -231,6 +240,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
|||||||
|
|
||||||
// Collect implements prometheus.Collector.
|
// Collect implements prometheus.Collector.
|
||||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
ch <- prometheus.MustNewConstMetric(c.maglevInfo, prometheus.GaugeValue, 1.0, c.sourceTag)
|
||||||
|
|
||||||
states := []health.State{
|
states := []health.State{
|
||||||
health.StateUnknown,
|
health.StateUnknown,
|
||||||
health.StateUp,
|
health.StateUp,
|
||||||
@@ -343,8 +354,8 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
|
|
||||||
// Register registers all metrics with the given registry. vpp may be nil
|
// Register registers all metrics with the given registry. vpp may be nil
|
||||||
// to disable VPP-related metrics.
|
// to disable VPP-related metrics.
|
||||||
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource) *Collector {
|
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||||
coll := NewCollector(src, vpp)
|
coll := NewCollector(src, vpp, sourceTag)
|
||||||
reg.MustRegister(coll)
|
reg.MustRegister(coll)
|
||||||
reg.MustRegister(ProbeTotal)
|
reg.MustRegister(ProbeTotal)
|
||||||
reg.MustRegister(ProbeDuration)
|
reg.MustRegister(ProbeDuration)
|
||||||
|
|||||||
Reference in New Issue
Block a user