mirror of
https://github.com/outbackdingo/openlan-cgw.git
synced 2026-01-27 10:19:56 +00:00
Add env variable for metrics port
This commit is contained in:
@@ -71,6 +71,7 @@ CGW_DB_PASS - PSQL DB password (credentials) to use upon connect to
|
||||
CGW_REDIS_DB_IP - IP of remote redis-db server to connect to
|
||||
CGW_REDIS_DB_PORT - PORT of remote redis-db server to connect to
|
||||
CGW_LOG_LEVEL - Log level to start CGW application with (debug, info)
|
||||
CGW_METRICS_PORT - PORT of metrics to connect to
|
||||
CGW_CERTS_PATH - Path to certificates located on host machine
|
||||
CGW_ALLOW_CERT_MISMATCH - Allow client certificate CN and device MAC address mismatch (used for OWLS)
|
||||
```
|
||||
@@ -89,6 +90,7 @@ declare -x CGW_KAFKA_IP="127.0.0.1" # Kafka is located at the local host
|
||||
declare -x CGW_KAFKA_PORT="9092"
|
||||
declare -x CGW_LOG_LEVEL="debug"
|
||||
declare -x CGW_REDIS_DB_IP="127.0.0.1" # Redis server can be found at the local host
|
||||
declare -x CGW_METRICS_PORT="8080"
|
||||
declare -x CGW_WSS_IP="0.0.0.0" # Accept WSS connections at all interfaces / subnets
|
||||
declare -x CGW_WSS_PORT="15002"
|
||||
declare -x CGW_WSS_CAS="cas.pem"
|
||||
|
||||
@@ -31,6 +31,8 @@ DEFAULT_DB_PASW="123"
|
||||
DEFAULT_REDIS_DB_IP="127.0.0.1"
|
||||
DEFAULT_REDIS_DB_PORT=6379
|
||||
|
||||
DEFAULT_METRICS_PORT=8080
|
||||
|
||||
CONTAINTER_CERTS_VOLUME="/etc/cgw/certs"
|
||||
|
||||
DEFAULT_ALLOW_CERT_MISMATCH="no"
|
||||
@@ -56,6 +58,7 @@ export CGW_DB_USERNAME="${CGW_DB_USER:-$DEFAULT_DB_USER}"
|
||||
export CGW_DB_PASSWORD="${CGW_DB_PASS:-$DEFAULT_DB_PASW}"
|
||||
export CGW_REDIS_IP="${CGW_REDIS_DB_IP:-$DEFAULT_REDIS_DB_IP}"
|
||||
export CGW_REDIS_PORT="${CGW_REDIS_DB_PORT:-$DEFAULT_REDIS_DB_PORT}"
|
||||
export CGW_METRICS_PORT="${CGW_METRICS_PORT:-$DEFAULT_METRICS_PORT}"
|
||||
export CGW_CERTS_PATH="${CGW_CERTS_PATH:-$DEFAULT_CERTS_PATH}"
|
||||
export CGW_ALLOW_CERT_MISMATCH="${CGW_ALLOW_CERT_MISMATCH:-$DEFAULT_ALLOW_CERT_MISMATCH}"
|
||||
|
||||
@@ -73,6 +76,7 @@ echo "CGW KAFKA TOPIC : $CGW_KAFKA_CONSUME_TOPIC:$CGW_KAFKA_PRODUCE_TOPIC
|
||||
echo "CGW DB NAME : $CGW_DB_NAME"
|
||||
echo "CGW DB IP/PORT : $CGW_DB_IP:$CGW_DB_PORT"
|
||||
echo "CGW REDIS : $CGW_REDIS_IP:$CGW_REDIS_PORT"
|
||||
echo "CGW METRICS PORT : $CGW_METRICS_PORT"
|
||||
echo "CGW CERTS PATH : $CGW_CERTS_PATH"
|
||||
echo "CGW ALLOW CERT MISMATCH: $CGW_ALLOW_CERT_MISMATCH"
|
||||
|
||||
@@ -99,5 +103,6 @@ docker run \
|
||||
-e CGW_DB_PASSWORD \
|
||||
-e CGW_REDIS_IP \
|
||||
-e CGW_REDIS_PORT \
|
||||
-e CGW_METRICS_PORT \
|
||||
-e CGW_ALLOW_CERT_MISMATCH \
|
||||
-d -t --network=host --name $2 $1 ucentral-cgw
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::cgw_errors::Result;
|
||||
use crate::AppArgs;
|
||||
|
||||
use prometheus::{IntGauge, Registry};
|
||||
use std::{collections::HashMap, fmt, sync::Arc};
|
||||
@@ -117,7 +116,7 @@ impl CGWMetrics {
|
||||
&CGW_METRICS
|
||||
}
|
||||
|
||||
pub async fn start(&self, _app_args: &AppArgs) -> Result<()> {
|
||||
pub async fn start(&self, port: u16) -> Result<()> {
|
||||
let mut started = self.started.lock().await;
|
||||
|
||||
if *started {
|
||||
@@ -162,7 +161,7 @@ impl CGWMetrics {
|
||||
let health_route = warp::path!("health").and_then(health_handler);
|
||||
|
||||
let routes = warp::get().and(metrics_route.or(health_route));
|
||||
warp::serve(routes).run(([0, 0, 0, 0], 8080)).await;
|
||||
warp::serve(routes).run(([0, 0, 0, 0], port)).await;
|
||||
});
|
||||
|
||||
debug!("Metrics engine's been started!");
|
||||
|
||||
12
src/main.rs
12
src/main.rs
@@ -92,6 +92,7 @@ const CGW_DEFAULT_DB_PASSWORD: &str = "123";
|
||||
const CGW_DEFAULT_REDIS_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
|
||||
const CGW_DEFAULT_REDIS_PORT: u16 = 5432;
|
||||
const CGW_DEFAULT_ALLOW_CERT_MISMATCH: &str = "no";
|
||||
const CGW_DEFAULT_METRICS_PORT: u16 = 8080;
|
||||
|
||||
/// CGW server
|
||||
pub struct AppArgs {
|
||||
@@ -148,6 +149,9 @@ pub struct AppArgs {
|
||||
|
||||
/// Allow Missmatch
|
||||
allow_mismatch: bool,
|
||||
|
||||
// PORT to connect to Metrics
|
||||
metrics_port: u16,
|
||||
}
|
||||
|
||||
impl AppArgs {
|
||||
@@ -236,6 +240,11 @@ impl AppArgs {
|
||||
.unwrap_or(CGW_DEFAULT_ALLOW_CERT_MISMATCH.to_string());
|
||||
let allow_mismatch = mismatch == "yes";
|
||||
|
||||
let metrics_port: u16 = match env::var("CGW_METRICS_PORT") {
|
||||
Ok(val) => val.parse().ok().unwrap_or(CGW_DEFAULT_METRICS_PORT),
|
||||
Err(_) => CGW_DEFAULT_METRICS_PORT,
|
||||
};
|
||||
|
||||
AppArgs {
|
||||
log_level,
|
||||
cgw_id,
|
||||
@@ -259,6 +268,7 @@ impl AppArgs {
|
||||
redis_db_ip,
|
||||
redis_db_port,
|
||||
allow_mismatch,
|
||||
metrics_port,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -458,7 +468,7 @@ async fn main() -> Result<()> {
|
||||
|
||||
// Make sure metrics are available <before> any of the components
|
||||
// starts up;
|
||||
CGWMetrics::get_ref().start(&args).await?;
|
||||
CGWMetrics::get_ref().start(args.metrics_port).await?;
|
||||
let app = Arc::new(AppCore::new(args).await?);
|
||||
|
||||
app.run(shutdown_notify).await;
|
||||
|
||||
Reference in New Issue
Block a user