vector/sources/mongodb_metrics/
types.rs

1use std::collections::HashMap;
2
3use mongodb::bson::DateTime;
4use serde::{Deserialize, Serialize};
5
6/// Type of mongo instance.
7/// Can be determined with `isMaster` command, see `CommandIsMaster`.
8#[derive(Debug, PartialEq, Eq)]
9pub enum NodeType {
10    Mongod,  // MongoDB daemon
11    Mongos,  // Mongo sharding server
12    Replset, // <https://docs.mongodb.com/manual/reference/glossary/#term-replica-set>
13}
14
15/// <https://docs.mongodb.com/manual/reference/command/isMaster/>
16#[derive(Debug, Deserialize)]
17#[serde(rename_all = "camelCase")]
18pub struct CommandIsMaster {
19    pub msg: Option<String>,
20    pub set_name: Option<String>,
21    pub hosts: Option<Vec<String>>,
22}
23
24/// <https://docs.mongodb.com/manual/reference/command/buildInfo/>
25#[derive(Debug, Deserialize, Serialize)]
26#[serde(rename_all = "camelCase")]
27pub struct CommandBuildInfo {
28    pub version: String,
29    pub git_version: String,
30    pub bits: i64,
31    pub debug: bool,
32    pub max_bson_object_size: i64,
33}
34
35/// <https://docs.mongodb.com/manual/reference/command/serverStatus/>
36#[derive(Debug, Deserialize)]
37#[serde(rename_all = "camelCase")]
38pub struct CommandServerStatus {
39    #[serde(flatten)]
40    pub instance: CommandServerStatusInstance,
41    pub asserts: CommandServerStatusAsserts,
42    pub connections: CommandServerStatusConnections,
43    #[serde(rename = "extra_info")]
44    pub extra_info: CommandServerStatusExtraInfo,
45    #[serde(rename = "mem")]
46    pub memory: CommandServerStatusMem,
47    pub global_lock: CommandServerStatusGlobalLock,
48    pub locks: HashMap<String, CommandServerStatusLock>,
49    pub metrics: CommandServerStatusMetrics,
50    pub op_latencies: HashMap<String, CommandServerStatusOpLatenciesStat>,
51    pub storage_engine: CommandServerStatusStorageEngine,
52    pub wired_tiger: Option<CommandServerStatusWiredTiger>,
53    pub network: CommandServerStatusNetwork,
54    pub opcounters: HashMap<String, i64>,
55    pub opcounters_repl: HashMap<String, i64>,
56}
57
58#[derive(Debug, Deserialize)]
59#[serde(rename_all = "camelCase")]
60pub struct CommandServerStatusInstance {
61    pub uptime: f64,
62    pub uptime_estimate: i64,
63    pub local_time: DateTime,
64}
65
66#[derive(Debug, Deserialize)]
67#[serde(rename_all = "camelCase")]
68pub struct CommandServerStatusAsserts {
69    pub regular: i64,
70    pub warning: i64,
71    pub msg: i64,
72    pub user: i64,
73    pub rollovers: i64,
74}
75
76#[derive(Debug, Deserialize)]
77#[serde(rename_all = "camelCase")]
78pub struct CommandServerStatusConnections {
79    pub active: i64,
80    pub available: i64,
81    pub current: i64,
82}
83
84#[derive(Debug, Deserialize)]
85pub struct CommandServerStatusExtraInfo {
86    pub heap_usage_bytes: Option<i64>,
87    pub page_faults: i64,
88}
89
90#[derive(Debug, Deserialize)]
91#[serde(rename_all = "camelCase")]
92pub struct CommandServerStatusMem {
93    pub resident: i64,
94    pub r#virtual: i64,
95    pub mapped: Option<i64>,
96    pub mapped_with_journal: Option<i64>,
97}
98
99#[derive(Debug, Deserialize)]
100#[serde(rename_all = "camelCase")]
101pub struct CommandServerStatusGlobalLock {
102    pub total_time: i64,
103    pub active_clients: CommandServerStatusGlobalLockInner,
104    pub current_queue: CommandServerStatusGlobalLockInner,
105}
106
107#[derive(Debug, Deserialize)]
108pub struct CommandServerStatusGlobalLockInner {
109    pub total: i64,
110    pub readers: i64,
111    pub writers: i64,
112}
113
114#[derive(Debug, Deserialize)]
115#[serde(rename_all = "camelCase")]
116pub struct CommandServerStatusLock {
117    pub time_acquiring_micros: Option<CommandServerStatusLockModes>,
118}
119
120#[derive(Debug, Deserialize)]
121#[serde(rename_all = "camelCase")]
122pub struct CommandServerStatusLockModes {
123    #[serde(rename = "r")]
124    pub read: Option<i64>,
125    #[serde(rename = "w")]
126    pub write: Option<i64>,
127}
128
129#[derive(Debug, Deserialize)]
130#[serde(rename_all = "camelCase")]
131pub struct CommandServerStatusMetrics {
132    pub cursor: CommandServerStatusMetricsCursor,
133    pub document: CommandServerStatusMetricsDocument,
134    pub get_last_error: CommandServerStatusMetricsGetLastError,
135    pub operation: CommandServerStatusMetricsOperation,
136    pub query_executor: CommandServerStatusMetricsQueryExecutor,
137    pub record: Option<CommandServerStatusMetricsRecord>,
138    pub repl: CommandServerStatusMetricsRepl,
139    pub ttl: CommandServerStatusMetricsReplTtl,
140}
141
142#[derive(Debug, Deserialize)]
143pub struct CommandServerStatusMetricsCursor {
144    #[serde(rename = "timedOut")]
145    pub timed_out: i64,
146    pub open: CommandServerStatusMetricsCursorOpen,
147}
148
149#[derive(Debug, Deserialize)]
150#[serde(rename_all = "camelCase")]
151pub struct CommandServerStatusMetricsCursorOpen {
152    pub no_timeout: i64,
153    pub pinned: i64,
154    pub total: i64,
155    // Only mongos
156    // pub single_target: Option<i64>,
157    // pub multi_target: Option<i64>,
158}
159
160#[derive(Debug, Deserialize)]
161pub struct CommandServerStatusMetricsDocument {
162    pub deleted: i64,
163    pub inserted: i64,
164    pub returned: i64,
165    pub updated: i64,
166}
167
168#[derive(Debug, Deserialize)]
169pub struct CommandServerStatusMetricsGetLastError {
170    pub wtime: CommandServerStatusMetricsGetLastErrorWtime,
171    pub wtimeouts: i64,
172}
173
174#[derive(Debug, Deserialize)]
175#[serde(rename_all = "camelCase")]
176pub struct CommandServerStatusMetricsGetLastErrorWtime {
177    pub num: i64,
178    pub total_millis: i64,
179}
180
181#[derive(Debug, Deserialize)]
182#[serde(rename_all = "camelCase")]
183pub struct CommandServerStatusMetricsOperation {
184    pub scan_and_order: i64,
185    pub write_conflicts: i64,
186}
187
188#[derive(Debug, Deserialize)]
189#[serde(rename_all = "camelCase")]
190pub struct CommandServerStatusMetricsQueryExecutor {
191    pub scanned: i64,
192    pub scanned_objects: i64,
193    pub collection_scans: Option<CommandServerStatusMetricsQueryExecutorCollections>,
194}
195
196#[derive(Debug, Deserialize)]
197pub struct CommandServerStatusMetricsQueryExecutorCollections {
198    pub total: i64,
199}
200
201#[derive(Debug, Deserialize)]
202pub struct CommandServerStatusMetricsRecord {
203    pub moves: i64,
204}
205
206#[derive(Debug, Deserialize)]
207pub struct CommandServerStatusMetricsRepl {
208    pub apply: CommandServerStatusMetricsReplApply,
209    pub buffer: CommandServerStatusMetricsReplBuffer,
210    pub executor: CommandServerStatusMetricsReplExecutor,
211    pub network: CommandServerStatusMetricsReplNetwork,
212}
213
214#[derive(Debug, Deserialize)]
215pub struct CommandServerStatusMetricsReplApply {
216    pub batches: CommandServerStatusMetricsReplApplyBatches,
217    pub ops: i64,
218}
219
220#[derive(Debug, Deserialize)]
221#[serde(rename_all = "camelCase")]
222pub struct CommandServerStatusMetricsReplApplyBatches {
223    pub num: i64,
224    pub total_millis: i64,
225}
226
227#[derive(Debug, Deserialize)]
228#[serde(rename_all = "camelCase")]
229pub struct CommandServerStatusMetricsReplBuffer {
230    pub count: i64,
231    pub max_size_bytes: i64,
232    pub size_bytes: i64,
233}
234
235#[derive(Debug, Deserialize)]
236#[serde(rename_all = "camelCase")]
237pub struct CommandServerStatusMetricsReplExecutor {
238    pub queues: CommandServerStatusMetricsReplExecutorQueues,
239    pub unsignaled_events: i64,
240}
241
242#[derive(Debug, Deserialize)]
243#[serde(rename_all = "camelCase")]
244pub struct CommandServerStatusMetricsReplExecutorQueues {
245    pub network_in_progress: i64,
246    pub sleepers: i64,
247}
248
249#[derive(Debug, Deserialize)]
250#[serde(rename_all = "camelCase")]
251pub struct CommandServerStatusMetricsReplNetwork {
252    pub bytes: i64,
253    pub getmores: CommandServerStatusMetricsReplNetworkGetmores,
254    pub ops: i64,
255    pub readers_created: i64,
256}
257
258#[derive(Debug, Deserialize)]
259#[serde(rename_all = "camelCase")]
260pub struct CommandServerStatusMetricsReplNetworkGetmores {
261    pub num: i64,
262    pub total_millis: i64,
263}
264
265#[derive(Debug, Deserialize)]
266#[serde(rename_all = "camelCase")]
267pub struct CommandServerStatusMetricsReplTtl {
268    pub deleted_documents: i64,
269    pub passes: i64,
270}
271
272/// <https://docs.mongodb.com/manual/reference/operator/aggregation/collStats/#latency-stats-document>
273#[derive(Debug, Deserialize)]
274#[serde(rename_all = "camelCase")]
275pub struct CommandServerStatusOpLatenciesStat {
276    pub latency: i64,
277    pub ops: i64,
278    pub histogram: Vec<CommandServerStatusOpLatenciesStatHistBucket>,
279}
280
281#[derive(Debug, Deserialize)]
282pub struct CommandServerStatusOpLatenciesStatHistBucket {
283    pub(crate) micros: i64,
284    pub count: i64,
285}
286
287#[derive(Debug, Deserialize)]
288pub struct CommandServerStatusStorageEngine {
289    pub name: String,
290}
291
292#[derive(Debug, Deserialize)]
293#[serde(rename_all = "camelCase")]
294pub struct CommandServerStatusWiredTiger {
295    #[serde(rename = "block-manager")]
296    pub block_manager: CommandServerStatusWiredTigerBlockManager,
297    pub cache: CommandServerStatusWiredTigerCache,
298    pub concurrent_transactions: CommandServerStatusWiredTigerConcurrentTransactions,
299    pub log: CommandServerStatusWiredTigerLog,
300    pub session: CommandServerStatusWiredTigerSession,
301    pub transaction: CommandServerStatusWiredTigerTransaction,
302}
303
304#[derive(Debug, Deserialize)]
305pub struct CommandServerStatusWiredTigerBlockManager {
306    #[serde(rename = "blocks pre-loaded")]
307    pub blocks_pre_loaded: i64,
308    #[serde(rename = "blocks read")]
309    pub blocks_read: i64,
310    #[serde(rename = "blocks written")]
311    pub blocks_written: i64,
312    #[serde(rename = "bytes read")]
313    pub bytes_read: i64,
314    #[serde(rename = "bytes written")]
315    pub bytes_written: i64,
316    #[serde(rename = "mapped blocks read")]
317    pub mapped_blocks_read: i64,
318    #[serde(rename = "mapped bytes read")]
319    pub mapped_bytes_read: i64,
320}
321
322#[derive(Debug, Deserialize)]
323pub struct CommandServerStatusWiredTigerCache {
324    #[serde(rename = "bytes currently in the cache")]
325    pub bytes_total: i64,
326    #[serde(rename = "maximum bytes configured")]
327    pub max_bytes: f64,
328    #[serde(rename = "modified pages evicted")]
329    pub evicted_modified: i64,
330    #[serde(rename = "pages currently held in the cache")]
331    pub pages_total: i64,
332    #[serde(rename = "pages read into cache")]
333    pub pages_read_into: i64,
334    #[serde(rename = "pages written from cache")]
335    pub pages_written_from: i64,
336    #[serde(rename = "percentage overhead")]
337    pub percent_overhead: i64,
338    #[serde(rename = "tracked bytes belonging to internal pages in the cache")]
339    pub bytes_internal_pages: i64,
340    #[serde(rename = "tracked bytes belonging to leaf pages in the cache")]
341    pub bytes_leaf_pages: i64,
342    #[serde(rename = "tracked dirty bytes in the cache")]
343    pub bytes_dirty: i64,
344    #[serde(rename = "tracked dirty pages in the cache")]
345    pub pages_dirty: i64,
346    #[serde(rename = "unmodified pages evicted")]
347    pub evicted_unmodified: i64,
348}
349
350#[derive(Debug, Deserialize)]
351pub struct CommandServerStatusWiredTigerConcurrentTransactions {
352    pub write: CommandServerStatusWiredTigerConcurrentTransactionsStats,
353    pub read: CommandServerStatusWiredTigerConcurrentTransactionsStats,
354}
355
356#[derive(Debug, Deserialize)]
357#[serde(rename_all = "camelCase")]
358pub struct CommandServerStatusWiredTigerConcurrentTransactionsStats {
359    pub out: i64,
360    pub available: i64,
361    pub total_tickets: i64,
362}
363
364#[derive(Debug, Deserialize)]
365pub struct CommandServerStatusWiredTigerLog {
366    #[serde(rename = "log bytes of payload data")]
367    pub bytes_payload_data: i64,
368    #[serde(rename = "log bytes written")]
369    pub bytes_written: i64,
370    #[serde(rename = "log flush operations")]
371    pub log_flushes: i64,
372    #[serde(rename = "log records compressed")]
373    pub records_compressed: i64,
374    #[serde(rename = "log records not compressed")]
375    pub records_uncompressed: i64,
376    #[serde(rename = "log scan operations")]
377    pub log_scans: i64,
378    #[serde(rename = "log scan records requiring two reads")]
379    pub log_scans_double: i64,
380    #[serde(rename = "log sync operations")]
381    pub log_syncs: i64,
382    #[serde(rename = "log sync_dir operations")]
383    pub log_sync_dirs: i64,
384    #[serde(rename = "log write operations")]
385    pub log_writes: i64,
386    #[serde(rename = "records processed by log scan")]
387    pub records_processed_log_scan: i64,
388}
389
390#[derive(Debug, Deserialize)]
391pub struct CommandServerStatusWiredTigerSession {
392    #[serde(rename = "open session count")]
393    pub sessions: i64,
394}
395
396#[derive(Debug, Deserialize)]
397pub struct CommandServerStatusWiredTigerTransaction {
398    #[serde(rename = "transaction begins")]
399    pub begins: i64,
400    #[serde(rename = "transaction checkpoints")]
401    pub checkpoints: i64,
402    #[serde(rename = "transaction checkpoint currently running")]
403    pub checkpoints_running: i64,
404    #[serde(rename = "transaction checkpoint max time (msecs)")]
405    pub checkpoint_max_ms: i64,
406    #[serde(rename = "transaction checkpoint min time (msecs)")]
407    pub checkpoint_min_ms: i64,
408    #[serde(rename = "transaction checkpoint total time (msecs)")]
409    pub checkpoint_total_ms: i64,
410    #[serde(rename = "transactions committed")]
411    pub committed: i64,
412    #[serde(rename = "transactions rolled back")]
413    pub rolled_back: i64,
414}
415
416#[derive(Debug, Deserialize)]
417#[serde(rename_all = "camelCase")]
418pub struct CommandServerStatusNetwork {
419    pub bytes_in: i64,
420    pub bytes_out: i64,
421    pub num_requests: i64,
422}