diff --git a/api/prometheus/prometheus.go b/api/prometheus/prometheus.go index 2e3d8e255..f24932917 100644 --- a/api/prometheus/prometheus.go +++ b/api/prometheus/prometheus.go @@ -16,7 +16,11 @@ package prometheus import ( + "context" "fmt" + "github.com/go-openapi/errors" + "github.com/loxilb-io/loxilb/options" + "net/http" "strings" "sync" "time" @@ -46,6 +50,8 @@ var ( PromethusDefaultPeriod = 10 * time.Second PromethusPartialPeriod = (PromethusDefaultPeriod / 6) PromethusLongPeriod = (PromethusDefaultPeriod * 600) // To reset Period + prometheusCtx context.Context + prometheusCancel context.CancelFunc activeConntrackCount = promauto.NewGauge( prometheus.GaugeOpts{ Name: "active_conntrack_count", @@ -143,215 +149,286 @@ func PrometheusRegister(hook cmn.NetHookInterface) { } func Init() { + prometheusCtx, prometheusCancel = context.WithCancel(context.Background()) + // Make Conntrack Statistic map ConntrackStats = make(map[ConntrackKey]Stats) mutex = &sync.Mutex{} - go RunGetConntrack() - go RunGetEndpoint() - go RunActiveConntrackCount() - go RunHostCount() - go RunProcessedStatistic() - go RunNewFlowCount() - go RunResetCounts() - go RunGetLBRule() - go RunLcusCalculator() + go RunGetConntrack(prometheusCtx) + go RunGetEndpoint(prometheusCtx) + go RunActiveConntrackCount(prometheusCtx) + go RunHostCount(prometheusCtx) + go RunProcessedStatistic(prometheusCtx) + go RunNewFlowCount(prometheusCtx) + go RunResetCounts(prometheusCtx) + go RunGetLBRule(prometheusCtx) + go RunLcusCalculator(prometheusCtx) +} + +func Off() error { + if !options.Opts.Prometheus { + return errors.New(http.StatusBadRequest, "already prometheus turned off") + } + options.Opts.Prometheus = false + prometheusCancel() + return nil +} + +func TurnOn() error { + if options.Opts.Prometheus { + return errors.New(http.StatusBadRequest, "already prometheus turned on") + } + options.Opts.Prometheus = true + Init() + return nil } func MakeConntrackKey(c cmn.CtInfo) (key ConntrackKey) { return ConntrackKey(fmt.Sprintf("%s|%05d|%s|%05d|%v", c.Sip, c.Sport, c.Dip, c.Dport, c.Proto)) } -func RunResetCounts() { +func RunResetCounts(ctx context.Context) { for { // Statistic reset time.Sleep(PromethusLongPeriod) - mutex.Lock() - ConntrackStats = map[ConntrackKey]Stats{} - mutex.Unlock() + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + ConntrackStats = map[ConntrackKey]Stats{} + mutex.Unlock() + } } } -func RunGetConntrack() { +func RunGetConntrack(ctx context.Context) { for { - mutex.Lock() - ConntrackInfo, err = hooks.NetCtInfoGet() - if err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) - } - - for _, ct := range ConntrackInfo { - k := MakeConntrackKey(ct) - var tmpStats Stats - _, ok := ConntrackStats[k] - if ok { - tmpStats = Stats{ - Bytes: ConntrackStats[k].Bytes + ct.Bytes, - Packets: ConntrackStats[k].Packets + ct.Pkts, - } - } else { - tmpStats = Stats{ - Bytes: ct.Bytes, - Packets: ct.Pkts, - } + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + ConntrackInfo, err = hooks.NetCtInfoGet() + if err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) } - ConntrackStats[k] = tmpStats + for _, ct := range ConntrackInfo { + k := MakeConntrackKey(ct) + var tmpStats Stats + _, ok := ConntrackStats[k] + if ok { + tmpStats = Stats{ + Bytes: ConntrackStats[k].Bytes + ct.Bytes, + Packets: ConntrackStats[k].Packets + ct.Pkts, + } + } else { + tmpStats = Stats{ + Bytes: ct.Bytes, + Packets: ct.Pkts, + } + } + ConntrackStats[k] = tmpStats + } + mutex.Unlock() } - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunGetEndpoint() { +func RunGetEndpoint(ctx context.Context) { for { - mutex.Lock() - EndPointInfo, err = hooks.NetEpHostGet() - if err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + EndPointInfo, err = hooks.NetEpHostGet() + if err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + mutex.Unlock() } - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunGetLBRule() { +func RunGetLBRule(ctx context.Context) { for { - mutex.Lock() - LBRuleInfo, err = hooks.NetLbRuleGet() - if err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + LBRuleInfo, err = hooks.NetLbRuleGet() + if err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + ruleCount.Set(float64(len(LBRuleInfo))) + mutex.Unlock() } - ruleCount.Set(float64(len(LBRuleInfo))) - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunActiveConntrackCount() { +func RunActiveConntrackCount(ctx context.Context) { for { - mutex.Lock() - // init Counts - activeFlowCountTcp.Set(0) - activeFlowCountUdp.Set(0) - activeFlowCountSctp.Set(0) - inActiveFlowCount.Set(0) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + // init Counts + activeFlowCountTcp.Set(0) + activeFlowCountUdp.Set(0) + activeFlowCountSctp.Set(0) + inActiveFlowCount.Set(0) - // Total flow count - activeConntrackCount.Set(float64(len(ConntrackInfo))) + // Total flow count + activeConntrackCount.Set(float64(len(ConntrackInfo))) - for _, ct := range ConntrackInfo { - // TCP flow count - if ct.Proto == "tcp" { - activeFlowCountTcp.Inc() - } - // UDP flow count - if ct.Proto == "udp" { - activeFlowCountUdp.Inc() - } - // SCTP flow count - if ct.Proto == "sctp" { - activeFlowCountSctp.Inc() - } - // Closed flow count - if ct.CState == "closed" { - inActiveFlowCount.Inc() + for _, ct := range ConntrackInfo { + // TCP flow count + if ct.Proto == "tcp" { + activeFlowCountTcp.Inc() + } + // UDP flow count + if ct.Proto == "udp" { + activeFlowCountUdp.Inc() + } + // SCTP flow count + if ct.Proto == "sctp" { + activeFlowCountSctp.Inc() + } + // Closed flow count + if ct.CState == "closed" { + inActiveFlowCount.Inc() + } } + mutex.Unlock() } - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunHostCount() { +func RunHostCount(ctx context.Context) { for { - mutex.Lock() - healthyHostCount.Set(0) - unHealthyHostCount.Set(0) - for _, ep := range EndPointInfo { - if ep.CurrState == "ok" { - healthyHostCount.Inc() - } - if ep.CurrState == "nok" { - unHealthyHostCount.Inc() + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + healthyHostCount.Set(0) + unHealthyHostCount.Set(0) + for _, ep := range EndPointInfo { + if ep.CurrState == "ok" { + healthyHostCount.Inc() + } + if ep.CurrState == "nok" { + unHealthyHostCount.Inc() + } } + mutex.Unlock() } - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunProcessedStatistic() { +func RunProcessedStatistic(ctx context.Context) { for { - mutex.Lock() - // Init Stats - processedPackets.Set(0) - processedBytes.Set(0) - processedTCPBytes.Set(0) - processedUDPBytes.Set(0) - processedSCTPBytes.Set(0) - for k, ct := range ConntrackStats { - if strings.Contains(string(k), "tcp") { - processedTCPBytes.Add(float64(ct.Bytes)) - } - if strings.Contains(string(k), "udp") { - processedUDPBytes.Add(float64(ct.Bytes)) - } - if strings.Contains(string(k), "sctp") { - processedSCTPBytes.Add(float64(ct.Bytes)) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + // Init Stats + processedPackets.Set(0) + processedBytes.Set(0) + processedTCPBytes.Set(0) + processedUDPBytes.Set(0) + processedSCTPBytes.Set(0) + for k, ct := range ConntrackStats { + if strings.Contains(string(k), "tcp") { + processedTCPBytes.Add(float64(ct.Bytes)) + } + if strings.Contains(string(k), "udp") { + processedUDPBytes.Add(float64(ct.Bytes)) + } + if strings.Contains(string(k), "sctp") { + processedSCTPBytes.Add(float64(ct.Bytes)) + } + processedPackets.Add(float64(ct.Packets)) + processedBytes.Add(float64(ct.Bytes)) } - processedPackets.Add(float64(ct.Packets)) - processedBytes.Add(float64(ct.Bytes)) + mutex.Unlock() } - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunNewFlowCount() { +func RunNewFlowCount(ctx context.Context) { PreFlowCounts = 0 for { - mutex.Lock() - // Total new flow count - CurrentFlowCounts := len(ConntrackInfo) - diff := CurrentFlowCounts - PreFlowCounts - if diff > 0 { - newFlowCount.Set(float64(diff)) - } else { - newFlowCount.Set(0) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + // Total new flow count + CurrentFlowCounts := len(ConntrackInfo) + diff := CurrentFlowCounts - PreFlowCounts + if diff > 0 { + newFlowCount.Set(float64(diff)) + } else { + newFlowCount.Set(0) + } + PreFlowCounts = CurrentFlowCounts + mutex.Unlock() } - PreFlowCounts = CurrentFlowCounts - mutex.Unlock() + time.Sleep(PromethusDefaultPeriod) } } -func RunLcusCalculator() { +func RunLcusCalculator(ctx context.Context) { for { time.Sleep(PromethusDefaultPeriod) - mutex.Lock() - var LCUNewFlowCount = &dto.Metric{} - var LCUActiveFlowCount = &dto.Metric{} - var LCURuleCount = &dto.Metric{} - var LCUProcessedBytes = &dto.Metric{} - if err := newFlowCount.Write(LCUNewFlowCount); err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) - } - if err := activeConntrackCount.Write(LCUActiveFlowCount); err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) - } - if err := ruleCount.Write(LCURuleCount); err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) - } - if err := processedBytes.Write(LCUProcessedBytes); err != nil { - tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + select { + case <-ctx.Done(): + return + default: + mutex.Lock() + var LCUNewFlowCount = &dto.Metric{} + var LCUActiveFlowCount = &dto.Metric{} + var LCURuleCount = &dto.Metric{} + var LCUProcessedBytes = &dto.Metric{} + if err := newFlowCount.Write(LCUNewFlowCount); err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + if err := activeConntrackCount.Write(LCUActiveFlowCount); err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + if err := ruleCount.Write(LCURuleCount); err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + if err := processedBytes.Write(LCUProcessedBytes); err != nil { + tk.LogIt(tk.LogDebug, "[Prometheus] Error occur : %v\n", err) + } + // LCU of accumulated Flow count = Flowcount / 2160000 + // LCU of Rule = ruleCount/1000 + // LCU of Byte = processedBytes(Gb)/1h + consumedLcus.Set(float64(len(ConntrackStats))/2160000 + + *LCURuleCount.Gauge.Value/1000 + + (*LCUProcessedBytes.Gauge.Value*8)/360000000000) // (byte * 8)/ (60*60*1G)/10 + mutex.Unlock() } - // LCU of accumulated Flow count = Flowcount / 2160000 - // LCU of Rule = ruleCount/1000 - // LCU of Byte = processedBytes(Gb)/1h - consumedLcus.Set(float64(len(ConntrackStats))/2160000 + - *LCURuleCount.Gauge.Value/1000 + - (*LCUProcessedBytes.Gauge.Value*8)/360000000000) // (byte * 8)/ (60*60*1G)/10 - mutex.Unlock() } } diff --git a/api/restapi/configure_loxilb_rest_api.go b/api/restapi/configure_loxilb_rest_api.go index 8d2735c45..1db9e93e1 100644 --- a/api/restapi/configure_loxilb_rest_api.go +++ b/api/restapi/configure_loxilb_rest_api.go @@ -158,6 +158,9 @@ func configureAPI(api *operations.LoxilbRestAPIAPI) http.Handler { // Prometheus api.GetMetricsHandler = operations.GetMetricsHandlerFunc(handler.ConfigGetPrometheusCounter) + api.GetConfigMetricsHandler = operations.GetConfigMetricsHandlerFunc(handler.ConfigGetPrometheusOption) + api.PostConfigMetricsHandler = operations.PostConfigMetricsHandlerFunc(handler.ConfigPostPrometheus) + api.DeleteConfigMetricsHandler = operations.DeleteConfigMetricsHandlerFunc(handler.ConfigDeletePrometheus) // BGP Peer api.GetConfigBgpNeighAllHandler = operations.GetConfigBgpNeighAllHandlerFunc(handler.ConfigGetBGPNeigh) diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index 2ea838773..7925fbcac 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -2281,6 +2281,107 @@ func init() { } } }, + "/config/metrics": { + "get": { + "summary": "Get prometheus config value", + "responses": { + "200": { + "description": "prometheus config value", + "schema": { + "$ref": "#/definitions/MetricsConfig" + } + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "summary": "turn on prometheus option", + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "summary": "turn off prometheus option", + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/mirror": { "post": { "description": "Create a new Mirror config.", @@ -5105,6 +5206,15 @@ func init() { } } }, + "MetricsConfig": { + "type": "object", + "properties": { + "prometheus": { + "description": "value for prometheus enable or not", + "type": "boolean" + } + } + }, "MirrorEntry": { "type": "object", "properties": { @@ -7992,6 +8102,107 @@ func init() { } } }, + "/config/metrics": { + "get": { + "summary": "Get prometheus config value", + "responses": { + "200": { + "description": "prometheus config value", + "schema": { + "$ref": "#/definitions/MetricsConfig" + } + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "post": { + "summary": "turn on prometheus option", + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + }, + "delete": { + "summary": "turn off prometheus option", + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintenance mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, "/config/mirror": { "post": { "description": "Create a new Mirror config.", @@ -11378,6 +11589,15 @@ func init() { } } }, + "MetricsConfig": { + "type": "object", + "properties": { + "prometheus": { + "description": "value for prometheus enable or not", + "type": "boolean" + } + } + }, "MirrorEntry": { "type": "object", "properties": { diff --git a/api/restapi/handler/prometheus.go b/api/restapi/handler/prometheus.go index 603a9a855..6fc1940b0 100644 --- a/api/restapi/handler/prometheus.go +++ b/api/restapi/handler/prometheus.go @@ -16,6 +16,8 @@ package handler import ( + "github.com/loxilb-io/loxilb/api/models" + "github.com/loxilb-io/loxilb/api/prometheus" "net/http" "github.com/go-openapi/runtime" @@ -35,3 +37,29 @@ func ConfigGetPrometheusCounter(params operations.GetMetricsParams) middleware.R promhttp.Handler().ServeHTTP(w, params.HTTPRequest) }) } + +func ConfigGetPrometheusOption(params operations.GetConfigMetricsParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] Prometheus %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + return operations.NewGetConfigMetricsOK().WithPayload(&models.MetricsConfig{Prometheus: options.Opts.Prometheus}) +} + +func ConfigPostPrometheus(params operations.PostConfigMetricsParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] Prometheus %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + err := prometheus.TurnOn() + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + return &ResultResponse{Result: "Success"} +} + +func ConfigDeletePrometheus(params operations.DeleteConfigMetricsParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] Prometheus %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + err := prometheus.Off() + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + + return &ResultResponse{Result: "Success"} +} diff --git a/api/restapi/operations/loxilb_rest_api_api.go b/api/restapi/operations/loxilb_rest_api_api.go index 4d0909b75..fa9d67095 100644 --- a/api/restapi/operations/loxilb_rest_api_api.go +++ b/api/restapi/operations/loxilb_rest_api_api.go @@ -81,6 +81,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { DeleteConfigLoadbalancerNameLbNameHandler: DeleteConfigLoadbalancerNameLbNameHandlerFunc(func(params DeleteConfigLoadbalancerNameLbNameParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigLoadbalancerNameLbName has not yet been implemented") }), + DeleteConfigMetricsHandler: DeleteConfigMetricsHandlerFunc(func(params DeleteConfigMetricsParams) middleware.Responder { + return middleware.NotImplemented("operation DeleteConfigMetrics has not yet been implemented") + }), DeleteConfigMirrorIdentIdentHandler: DeleteConfigMirrorIdentIdentHandlerFunc(func(params DeleteConfigMirrorIdentIdentParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigMirrorIdentIdent has not yet been implemented") }), @@ -144,6 +147,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { GetConfigLoadbalancerAllHandler: GetConfigLoadbalancerAllHandlerFunc(func(params GetConfigLoadbalancerAllParams) middleware.Responder { return middleware.NotImplemented("operation GetConfigLoadbalancerAll has not yet been implemented") }), + GetConfigMetricsHandler: GetConfigMetricsHandlerFunc(func(params GetConfigMetricsParams) middleware.Responder { + return middleware.NotImplemented("operation GetConfigMetrics has not yet been implemented") + }), GetConfigMirrorAllHandler: GetConfigMirrorAllHandlerFunc(func(params GetConfigMirrorAllParams) middleware.Responder { return middleware.NotImplemented("operation GetConfigMirrorAll has not yet been implemented") }), @@ -222,6 +228,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { PostConfigLoadbalancerHandler: PostConfigLoadbalancerHandlerFunc(func(params PostConfigLoadbalancerParams) middleware.Responder { return middleware.NotImplemented("operation PostConfigLoadbalancer has not yet been implemented") }), + PostConfigMetricsHandler: PostConfigMetricsHandlerFunc(func(params PostConfigMetricsParams) middleware.Responder { + return middleware.NotImplemented("operation PostConfigMetrics has not yet been implemented") + }), PostConfigMirrorHandler: PostConfigMirrorHandlerFunc(func(params PostConfigMirrorParams) middleware.Responder { return middleware.NotImplemented("operation PostConfigMirror has not yet been implemented") }), @@ -317,6 +326,8 @@ type LoxilbRestAPIAPI struct { DeleteConfigLoadbalancerHosturlHosturlExternalipaddressIPAddressPortPortProtocolProtoHandler DeleteConfigLoadbalancerHosturlHosturlExternalipaddressIPAddressPortPortProtocolProtoHandler // DeleteConfigLoadbalancerNameLbNameHandler sets the operation handler for the delete config loadbalancer name lb name operation DeleteConfigLoadbalancerNameLbNameHandler DeleteConfigLoadbalancerNameLbNameHandler + // DeleteConfigMetricsHandler sets the operation handler for the delete config metrics operation + DeleteConfigMetricsHandler DeleteConfigMetricsHandler // DeleteConfigMirrorIdentIdentHandler sets the operation handler for the delete config mirror ident ident operation DeleteConfigMirrorIdentIdentHandler DeleteConfigMirrorIdentIdentHandler // DeleteConfigNeighborIPAddressDevIfNameHandler sets the operation handler for the delete config neighbor IP address dev if name operation @@ -359,6 +370,8 @@ type LoxilbRestAPIAPI struct { GetConfigIpv4addressAllHandler GetConfigIpv4addressAllHandler // GetConfigLoadbalancerAllHandler sets the operation handler for the get config loadbalancer all operation GetConfigLoadbalancerAllHandler GetConfigLoadbalancerAllHandler + // GetConfigMetricsHandler sets the operation handler for the get config metrics operation + GetConfigMetricsHandler GetConfigMetricsHandler // GetConfigMirrorAllHandler sets the operation handler for the get config mirror all operation GetConfigMirrorAllHandler GetConfigMirrorAllHandler // GetConfigNeighborAllHandler sets the operation handler for the get config neighbor all operation @@ -411,6 +424,8 @@ type LoxilbRestAPIAPI struct { PostConfigIpv4addressHandler PostConfigIpv4addressHandler // PostConfigLoadbalancerHandler sets the operation handler for the post config loadbalancer operation PostConfigLoadbalancerHandler PostConfigLoadbalancerHandler + // PostConfigMetricsHandler sets the operation handler for the post config metrics operation + PostConfigMetricsHandler PostConfigMetricsHandler // PostConfigMirrorHandler sets the operation handler for the post config mirror operation PostConfigMirrorHandler PostConfigMirrorHandler // PostConfigNeighborHandler sets the operation handler for the post config neighbor operation @@ -549,6 +564,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.DeleteConfigLoadbalancerNameLbNameHandler == nil { unregistered = append(unregistered, "DeleteConfigLoadbalancerNameLbNameHandler") } + if o.DeleteConfigMetricsHandler == nil { + unregistered = append(unregistered, "DeleteConfigMetricsHandler") + } if o.DeleteConfigMirrorIdentIdentHandler == nil { unregistered = append(unregistered, "DeleteConfigMirrorIdentIdentHandler") } @@ -612,6 +630,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.GetConfigLoadbalancerAllHandler == nil { unregistered = append(unregistered, "GetConfigLoadbalancerAllHandler") } + if o.GetConfigMetricsHandler == nil { + unregistered = append(unregistered, "GetConfigMetricsHandler") + } if o.GetConfigMirrorAllHandler == nil { unregistered = append(unregistered, "GetConfigMirrorAllHandler") } @@ -690,6 +711,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.PostConfigLoadbalancerHandler == nil { unregistered = append(unregistered, "PostConfigLoadbalancerHandler") } + if o.PostConfigMetricsHandler == nil { + unregistered = append(unregistered, "PostConfigMetricsHandler") + } if o.PostConfigMirrorHandler == nil { unregistered = append(unregistered, "PostConfigMirrorHandler") } @@ -866,6 +890,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) } + o.handlers["DELETE"]["/config/metrics"] = NewDeleteConfigMetrics(o.context, o.DeleteConfigMetricsHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } o.handlers["DELETE"]["/config/mirror/ident/{ident}"] = NewDeleteConfigMirrorIdentIdent(o.context, o.DeleteConfigMirrorIdentIdentHandler) if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) @@ -950,6 +978,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) } + o.handlers["GET"]["/config/metrics"] = NewGetConfigMetrics(o.context, o.GetConfigMetricsHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } o.handlers["GET"]["/config/mirror/all"] = NewGetConfigMirrorAll(o.context, o.GetConfigMirrorAllHandler) if o.handlers["GET"] == nil { o.handlers["GET"] = make(map[string]http.Handler) @@ -1054,6 +1086,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) } + o.handlers["POST"]["/config/metrics"] = NewPostConfigMetrics(o.context, o.PostConfigMetricsHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } o.handlers["POST"]["/config/mirror"] = NewPostConfigMirror(o.context, o.PostConfigMirrorHandler) if o.handlers["POST"] == nil { o.handlers["POST"] = make(map[string]http.Handler) @@ -1136,6 +1172,6 @@ func (o *LoxilbRestAPIAPI) AddMiddlewareFor(method, path string, builder middlew } o.Init() if h, ok := o.handlers[um][path]; ok { - o.handlers[method][path] = builder(h) + o.handlers[um][path] = builder(h) } } diff --git a/api/swagger.yml b/api/swagger.yml index 2e930bfef..98ebff548 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2742,6 +2742,72 @@ paths: description: Metrics in prometheus text format schema: type: string + '/config/metrics': + get: + summary: Get prometheus config value + responses: + '200': + description: prometheus config value + schema: + $ref: '#/definitions/MetricsConfig' + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintenance mode + schema: + $ref: '#/definitions/Error' + post: + summary: turn on prometheus option + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintenance mode + schema: + $ref: '#/definitions/Error' + delete: + summary: turn off prometheus option + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintenance mode + schema: + $ref: '#/definitions/Error' #---------------------------------------------- # BFD @@ -4032,3 +4098,9 @@ definitions: type: integer format: uint8 description: Retry Count to detect failure + MetricsConfig: + type: object + properties: + prometheus: + type: boolean + description: value for prometheus enable or not