Skip to main content

do_memory_mcp/server/tools/
monitoring.rs

1// Monitoring tool handlers
2//!
3//! This module contains health_check and get_metrics tool handlers.
4
5use anyhow::Result;
6
7impl crate::server::MemoryMCPServer {
8    /// Execute the health_check tool
9    ///
10    /// # Returns
11    ///
12    /// Returns health check results
13    pub async fn health_check(&self) -> Result<serde_json::Value> {
14        self.track_tool_usage("health_check").await;
15
16        // Start monitoring request
17        let request_id = format!(
18            "health_check_{}",
19            std::time::SystemTime::now()
20                .duration_since(std::time::UNIX_EPOCH)
21                .unwrap_or_default()
22                .as_nanos()
23        );
24        self.monitoring
25            .start_request(request_id.clone(), "health_check".to_string())
26            .await;
27
28        let result = self.monitoring_endpoints.health_check().await?;
29
30        // End monitoring request
31        self.monitoring.end_request(&request_id, true, None).await;
32
33        Ok(result)
34    }
35
36    /// Execute the get_metrics tool
37    ///
38    /// # Arguments
39    ///
40    /// * `metric_type` - Type of metrics to retrieve
41    ///
42    /// # Returns
43    ///
44    /// Returns monitoring metrics
45    pub async fn get_metrics(&self, metric_type: Option<String>) -> Result<serde_json::Value> {
46        self.track_tool_usage("get_metrics").await;
47
48        // Start monitoring request
49        let request_id = format!(
50            "get_metrics_{}",
51            std::time::SystemTime::now()
52                .duration_since(std::time::UNIX_EPOCH)
53                .unwrap_or_default()
54                .as_nanos()
55        );
56        self.monitoring
57            .start_request(request_id.clone(), "get_metrics".to_string())
58            .await;
59
60        let result = match metric_type.as_deref() {
61            Some("performance") => self.monitoring_endpoints.performance_metrics().await,
62            Some("episodes") => self.monitoring_endpoints.episode_metrics().await,
63            Some("system") => self.monitoring_endpoints.system_info().await,
64            _ => self.monitoring_endpoints.metrics().await,
65        };
66
67        // End monitoring request
68        self.monitoring
69            .end_request(&request_id, result.is_ok(), None)
70            .await;
71
72        result
73    }
74}