Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
health_monitor.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
17#pragma once
18
21
22#include <atomic>
23#include <chrono>
24#include <condition_variable>
25#include <functional>
26#include <map>
27#include <mutex>
28#include <string>
29#include <thread>
30#include <vector>
31
32namespace entropic {
33
39 std::string server_name;
40 std::string old_status;
41 std::string new_status;
42 std::vector<std::string> added_tools;
43 std::vector<std::string> removed_tools;
44};
45
56public:
61 using StatusCallback = std::function<void(const HealthEvent&)>;
62
70 uint32_t health_check_interval_ms = 0);
71
73
80 void watch(const std::string& name, ExternalMCPClient* client);
81
87 void unwatch(const std::string& name);
88
95
100 void start();
101
106 void stop();
107
112 void process_events();
113
114private:
115 ReconnectPolicy policy_;
116 uint32_t health_check_interval_ms_;
117 StatusCallback status_callback_;
118
123 struct WatchEntry {
124 ExternalMCPClient* client;
125 std::string status;
126 uint32_t reconnect_attempt;
127 std::chrono::steady_clock::time_point next_action;
128 };
129
130 std::map<std::string, WatchEntry> watched_;
131 std::mutex watched_mutex_;
132
133 std::vector<HealthEvent> event_queue_;
134 std::mutex event_mutex_;
135
136 std::thread monitor_thread_;
137 std::atomic<bool> running_{false};
138 std::condition_variable wake_cv_;
139 std::mutex wake_mutex_;
140
146 void monitor_loop();
147
155 void check_server(const std::string& name, WatchEntry& entry);
156
164 void attempt_reconnect(const std::string& name,
165 WatchEntry& entry);
166
178 void on_reconnect_success(const std::string& name,
179 WatchEntry& entry);
180
189 void post_event(const std::string& name,
190 const std::string& old_status,
191 const std::string& new_status);
192};
193
194} // namespace entropic
Client for an external MCP server (stdio or SSE).
Monitors external server connections and handles reconnection.
void start()
Start the monitoring thread.
void watch(const std::string &name, ExternalMCPClient *client)
Start monitoring a server.
void stop()
Stop monitoring and all reconnection attempts.
std::function< void(const HealthEvent &)> StatusCallback
Callback invoked on engine thread when processing events.
void process_events()
Drain event queue, invoke callbacks (call on engine thread).
~HealthMonitor()
Destructor — stops monitor if running.
void set_status_callback(StatusCallback cb)
Set callback for status change events.
void unwatch(const std::string &name)
Stop monitoring a server.
Exponential backoff with jitter for reconnection attempts.
Client for communicating with external MCP servers.
Activate model on GPU (WARM → ACTIVE).
Exponential backoff reconnection policy.
Status change event posted by the monitor thread.
std::vector< std::string > added_tools
Tools added on refresh.
std::string server_name
Which server changed.
std::string old_status
Previous status.
std::string new_status
New status.
std::vector< std::string > removed_tools
Tools removed on refresh.