Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ sha2 = "0.10.9"
uuid = { version = "1.18.1", features = ["v4"] }
bb8-redis = "0.24"
redis-macros = "0.5.6"
redis = "0.32.7"
redis = "0.32.7"
axum-prometheus = "0.9.0"
26 changes: 25 additions & 1 deletion server/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ services:
restart: always
ports:
- "6379:6379"


prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- "9091:9090"
command: --config.file=/etc/prometheus/prometheus.yml
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
extra_hosts:
- "hosts.docker.internal:host-gateway"

grafana:
image: grafana/grafana:latest
container_name: grafana
restart: always
ports:
- "3000:3000"
environment:
GF_SECURITY_ADMIN_USER: "${GRAFANA_ADMIN_USER}"
GF_SECURITY_ADMIN_PASSWORD: "${GRAFANA_ADMIN_PASSWORD}"
depends_on:
- prometheus


volumes:
pgdata:
8 changes: 8 additions & 0 deletions server/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global:
scrape_interval: 5s
evaluation_interval: 30s

scrape_configs:
- job_name: "paymesh_app_monitoring"
static_configs:
- targets: ["host.docker.internal:8080"]
7 changes: 6 additions & 1 deletion server/src/libs/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use axum::{
http::{
HeaderName, Method, StatusCode,
header::{AUTHORIZATION, CONTENT_TYPE},
},
}, routing::get,
};
use axum_prometheus::PrometheusMetricLayer;
use tower_http::cors::CorsLayer;
use utoipa::OpenApi;
use utoipa_axum::router::OpenApiRouter;
Expand All @@ -29,13 +30,17 @@ pub fn router(state: AppState) -> Router {
HeaderName::from_static("paymesh-api-key"),
]);

let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair();

let (router, api) = OpenApiRouter::with_openapi(ApiDoc::openapi())
.routes(routes!(health::health_check))
.nest("/users", routes::user::router())
.nest("/groups", routes::groups::router())
.nest("/admin", routes::admin::router())
.nest("/crowdfunding", routes::crowd_funding::router())
.route("/metrics", get(|| async move { metric_handle.render() }))
.with_state(state)
.layer(prometheus_layer)
.layer(cors)
.fallback(|| async { (StatusCode::UNAUTHORIZED, "UNAUTHORIZED ORIGIN") })
.split_for_parts();
Expand Down