rabbitmq_management_client/api/
node.rs1use crate::api::_generic::handle_response;
2use crate::api::overview::{RabbitMqContext, RabbitMqExchangeType};
3use crate::errors::RabbitMqClientError;
4use crate::RabbitMqClient;
5use async_trait::async_trait;
6use serde::Deserialize;
7
8#[async_trait]
9pub trait NodeApi {
10 async fn list_nodes(&self) -> Result<Vec<RabbitMqNode>, RabbitMqClientError>;
11
12 async fn get_node(&self, node: String) -> Result<RabbitMqNode, RabbitMqClientError>;
13
14 async fn get_node_memory(
15 &self,
16 node: String,
17 ) -> Result<RabbitMqNodeMemory, RabbitMqClientError>;
18}
19
20#[async_trait]
21impl NodeApi for RabbitMqClient {
22 async fn list_nodes(&self) -> Result<Vec<RabbitMqNode>, RabbitMqClientError> {
23 let response = self
24 .client
25 .request(reqwest::Method::GET, format!("{}/api/nodes", self.api_url))
26 .send()
27 .await?;
28
29 handle_response(response).await
30 }
31
32 async fn get_node(&self, node: String) -> Result<RabbitMqNode, RabbitMqClientError> {
33 let response = self
34 .client
35 .request(
36 reqwest::Method::GET,
37 format!("{}/api/nodes/{}", self.api_url, node),
38 )
39 .send()
40 .await?;
41
42 handle_response(response).await
43 }
44
45 async fn get_node_memory(
46 &self,
47 node: String,
48 ) -> Result<RabbitMqNodeMemory, RabbitMqClientError> {
49 let response = self
50 .client
51 .request(
52 reqwest::Method::GET,
53 format!("{}/api/nodes/{}/memory", self.api_url, node),
54 )
55 .send()
56 .await?;
57
58 let wrapper: RabbitMqNodeMemoryWrapper = handle_response(response).await?;
59
60 Ok(wrapper.memory)
61 }
62}
63
64#[derive(Debug, Deserialize)]
65pub struct RabbitMqNode {
66 pub os_pid: String,
67 pub fd_total: i64,
68 pub sockets_total: i64,
69 pub mem_limit: i64,
70 pub mem_alarm: bool,
71 pub disk_free_limit: i64,
72 pub disk_free_alarm: bool,
73 pub proc_total: i64,
74 pub rates_mode: String,
75 pub uptime: i64,
76 pub run_queue: i64,
77 pub processors: i64,
78 pub exchange_types: Vec<RabbitMqExchangeType>,
79 pub auth_mechanisms: Vec<RabbitMqNodeAuthMechanism>,
80 pub applications: Vec<RabbitMqNodeApplication>,
81 pub contexts: Vec<RabbitMqContext>,
82 pub log_files: Vec<String>,
83 pub db_dir: String,
84 pub config_files: Vec<String>,
85 pub net_ticktime: i64,
86 pub enabled_plugins: Vec<String>,
87 pub mem_calculation_strategy: String,
88 pub name: String,
89 pub running: bool,
90 #[serde(rename = "type")]
91 pub kind: String,
92 pub mem_used: i64,
93}
94
95#[derive(Debug, Deserialize)]
96pub struct RabbitMqNodeAuthMechanism {
97 pub name: String,
98 pub description: String,
99 pub enabled: bool,
100}
101
102#[derive(Debug, Deserialize)]
103pub struct RabbitMqNodeApplication {
104 pub name: String,
105 pub description: String,
106 pub version: String,
107}
108
109#[derive(Debug, Deserialize)]
110pub struct RabbitMqNodeMemoryWrapper {
111 memory: RabbitMqNodeMemory,
112}
113
114#[derive(Debug, Deserialize)]
115pub struct RabbitMqNodeMemory {
116 pub connection_readers: i64,
117 pub connection_writers: i64,
118 pub connection_channels: i64,
119 pub connection_other: i64,
120 pub queue_procs: i64,
121 pub queue_slave_procs: i64,
122 pub quorum_queue_procs: i64,
123 pub quorum_queue_dlx_procs: i64,
124 pub stream_queue_procs: i64,
125 pub stream_queue_replica_reader_procs: i64,
126 pub stream_queue_coordinator_procs: i64,
127 pub plugins: i64,
128 pub other_proc: i64,
129 pub metrics: i64,
130 pub mgmt_db: i64,
131 pub mnesia: i64,
132 pub quorum_ets: i64,
133 pub other_ets: i64,
134 pub binary: i64,
135 pub msg_index: i64,
136 pub code: i64,
137 pub atom: i64,
138 pub other_system: i64,
139 pub allocated_unused: i64,
140 pub reserved_unallocated: i64,
141 pub strategy: String,
142 pub total: RabbitMqNodeMemoryTotal,
143}
144
145#[derive(Debug, Deserialize)]
146pub struct RabbitMqNodeMemoryTotal {
147 pub erlang: i64,
148 pub rss: i64,
149 pub allocated: i64,
150}