archivist_lib/logs/
stats.rs1use diagnostics_data::Severity;
6use fuchsia_inspect::{IntProperty, Node, NumericProperty, Property, StringProperty, UintProperty};
7use fuchsia_inspect_derive::Inspect;
8
9#[derive(Debug, Default, Inspect)]
10pub struct LogStreamStats {
11 sockets_opened: UintProperty,
12 sockets_closed: UintProperty,
13 last_timestamp: IntProperty,
14 total: LogCounter,
15 rolled_out: LogCounter,
16 fatal: LogCounter,
17 error: LogCounter,
18 warn: LogCounter,
19 info: LogCounter,
20 debug: LogCounter,
21 trace: LogCounter,
22 url: StringProperty,
23 invalid: LogCounter,
24 inspect_node: Node,
25}
26
27impl LogStreamStats {
28 pub fn set_url(&self, url: &str) {
29 self.url.set(url);
30 }
31
32 pub fn open_socket(&self) {
33 self.sockets_opened.add(1);
34 }
35
36 pub fn close_socket(&self) {
37 self.sockets_closed.add(1);
38 }
39
40 pub fn increment_rolled_out(&self, msg_len: usize) {
41 self.rolled_out.increment_bytes(msg_len);
42 }
43
44 pub fn increment_invalid(&self, bytes: usize) {
45 self.invalid.increment_bytes(bytes);
46 }
47
48 pub fn ingest_message(&self, bytes: usize, severity: Severity) {
49 self.total.count(bytes);
50 match severity {
51 Severity::Trace => self.trace.count(bytes),
52 Severity::Debug => self.debug.count(bytes),
53 Severity::Info => self.info.count(bytes),
54 Severity::Warn => self.warn.count(bytes),
55 Severity::Error => self.error.count(bytes),
56 Severity::Fatal => self.fatal.count(bytes),
57 }
58 }
59}
60
61#[derive(Debug, Default, Inspect)]
62struct LogCounter {
63 number: UintProperty,
64 bytes: UintProperty,
65
66 inspect_node: Node,
67}
68
69impl LogCounter {
70 fn count(&self, bytes: usize) {
71 self.number.add(1);
72 self.bytes.add(bytes as u64);
73 }
74
75 fn increment_bytes(&self, bytes: usize) {
76 self.number.add(1);
77 self.bytes.add(bytes as u64);
78 }
79}