claude final draft
This commit is contained in:
104
shared/config.py
Normal file
104
shared/config.py
Normal file
@@ -0,0 +1,104 @@
|
||||
"""Shared configuration management using Pydantic Settings."""
|
||||
|
||||
from functools import lru_cache
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class BaseConfig(BaseSettings):
|
||||
"""Base configuration shared across all services."""
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=".env",
|
||||
env_file_encoding="utf-8",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
# Service identification
|
||||
service_name: str = "unknown"
|
||||
machine_id: str = "local"
|
||||
|
||||
# Logging
|
||||
log_level: str = "INFO"
|
||||
log_format: str = "json" # "json" or "console"
|
||||
|
||||
# Redis
|
||||
redis_url: str = "redis://localhost:6379"
|
||||
|
||||
# Events
|
||||
events_backend: str = "redis_pubsub"
|
||||
|
||||
|
||||
class CollectorConfig(BaseConfig):
|
||||
"""Collector service configuration."""
|
||||
|
||||
service_name: str = "collector"
|
||||
|
||||
# Aggregator connection
|
||||
aggregator_url: str = "localhost:50051"
|
||||
|
||||
# Collection settings
|
||||
collection_interval: int = 5 # seconds
|
||||
|
||||
# Metrics to collect
|
||||
collect_cpu: bool = True
|
||||
collect_memory: bool = True
|
||||
collect_disk: bool = True
|
||||
collect_network: bool = True
|
||||
collect_load: bool = True
|
||||
|
||||
|
||||
class AggregatorConfig(BaseConfig):
|
||||
"""Aggregator service configuration."""
|
||||
|
||||
service_name: str = "aggregator"
|
||||
|
||||
# gRPC server
|
||||
grpc_port: int = 50051
|
||||
|
||||
# TimescaleDB - can be set directly via TIMESCALE_URL
|
||||
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
|
||||
|
||||
|
||||
class GatewayConfig(BaseConfig):
|
||||
"""Gateway service configuration."""
|
||||
|
||||
service_name: str = "gateway"
|
||||
|
||||
# HTTP server
|
||||
http_port: int = 8000
|
||||
|
||||
# Aggregator connection
|
||||
aggregator_url: str = "localhost:50051"
|
||||
|
||||
# TimescaleDB - can be set directly via TIMESCALE_URL
|
||||
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
|
||||
|
||||
|
||||
class AlertsConfig(BaseConfig):
|
||||
"""Alerts service configuration."""
|
||||
|
||||
service_name: str = "alerts"
|
||||
|
||||
# TimescaleDB - can be set directly via TIMESCALE_URL or built from components
|
||||
timescale_url: str = "postgresql://monitor:monitor@localhost:5432/monitor"
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_collector_config() -> CollectorConfig:
|
||||
return CollectorConfig()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_aggregator_config() -> AggregatorConfig:
|
||||
return AggregatorConfig()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_gateway_config() -> GatewayConfig:
|
||||
return GatewayConfig()
|
||||
|
||||
|
||||
@lru_cache
|
||||
def get_alerts_config() -> AlertsConfig:
|
||||
return AlertsConfig()
|
||||
Reference in New Issue
Block a user