-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to expose Prometheus metrics via http/s server
Signed-off-by: Botond Szirtes <botond.szirtes@est.tech>
- Loading branch information
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright (c) 2024 Nordix Foundation. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package stats | ||
|
||
import ( | ||
"sync" | ||
|
||
prom "github.com/networkservicemesh/sdk/pkg/tools/prometheus" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
var ( | ||
prometheusInitOnce sync.Once | ||
|
||
// Total received bytes by client | ||
ClientRxBytes = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "client_rx_bytes_total", | ||
Help: "Total received bytes by client", | ||
}, | ||
) | ||
// Total transmitted bytes by client | ||
ClientTxBytes = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "client_tx_bytes_total", | ||
Help: "Total transmitted bytes by client", | ||
}, | ||
) | ||
// Total received packets by client | ||
ClientRxPackets = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "client_rx_packets_total", | ||
Help: "Total received packets by client", | ||
}, | ||
) | ||
// Total transmitted packets by client | ||
ClientTxPackets = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "client_tx_packets_total", | ||
Help: "Total transmitted packets by client", | ||
}, | ||
) | ||
// Total drops by client | ||
ClientDrops = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "client_drops_total", | ||
Help: "Total drops by client", | ||
}, | ||
) | ||
// Total received bytes by server | ||
ServerRxBytes = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "server_rx_bytes_total", | ||
Help: "Total received bytes by server", | ||
}, | ||
) | ||
// Total transmitted bytes by server | ||
ServerTxBytes = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "server_tx_bytes_total", | ||
Help: "Total transmitted bytes by server", | ||
}, | ||
) | ||
// Total received packets by server | ||
ServerRxPackets = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "server_rx_packets_total", | ||
Help: "Total received packets by server", | ||
}, | ||
) | ||
// Total transmitted packets by server | ||
ServerTxPackets = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "server_tx_packets_total", | ||
Help: "Total transmitted packets by server", | ||
}, | ||
) | ||
// Total drops by server | ||
ServerDrops = prometheus.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "server_drops_total", | ||
Help: "Total drops by server", | ||
}, | ||
) | ||
) | ||
|
||
func registerMetrics() { | ||
if prom.IsEnabled() { | ||
prometheus.MustRegister(ClientRxBytes) | ||
prometheus.MustRegister(ClientTxBytes) | ||
prometheus.MustRegister(ClientRxPackets) | ||
prometheus.MustRegister(ClientTxPackets) | ||
prometheus.MustRegister(ClientDrops) | ||
prometheus.MustRegister(ServerRxBytes) | ||
prometheus.MustRegister(ServerTxBytes) | ||
prometheus.MustRegister(ServerRxPackets) | ||
prometheus.MustRegister(ServerTxPackets) | ||
prometheus.MustRegister(ServerDrops) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters