1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use std::collections::BTreeSet;
use std::sync::{Arc, Mutex};
use opcua_client::prelude::ServerDiagnosticsSummaryDataType;
use crate::{
subscriptions::subscription::Subscription,
session::Session,
};
pub struct Runtime {
running_components: Arc<Mutex<BTreeSet<String>>>,
}
impl Default for Runtime {
fn default() -> Self {
Self {
running_components: Arc::new(Mutex::new(BTreeSet::new())),
}
}
}
impl Runtime {
pub fn components(&self) -> Vec<String> {
let running_components = trace_lock_unwrap!(self.running_components);
running_components.iter().map(|k| k.clone()).collect()
}
pub fn register_component<T>(&self, name: T) where T: Into<String> {
let mut running_components = trace_lock_unwrap!(self.running_components);
let key = name.into();
if running_components.contains(&key) {
error!("Shouldn't be registering component {} more than once", key);
}
running_components.insert(key);
}
pub fn deregister_component<T>(&self, name: T) where T: Into<String> {
let mut running_components = trace_lock_unwrap!(self.running_components);
let key = name.into();
if !running_components.contains(&key) {
error!("Shouldn't be deregistering component {} which doesn't exist", key);
}
running_components.remove(&key);
}
}
#[derive(Clone, Serialize, Debug)]
pub struct ServerDiagnostics {
server_diagnostics_summary: ServerDiagnosticsSummaryDataType,
}
const SERVER_DIAGNOSTICS: &'static str = "ServerDiagnostics";
impl Default for ServerDiagnostics {
fn default() -> Self {
register_runtime_component!(SERVER_DIAGNOSTICS);
Self {
server_diagnostics_summary: ServerDiagnosticsSummaryDataType::default(),
}
}
}
impl Drop for ServerDiagnostics {
fn drop(&mut self) {
deregister_runtime_component!(SERVER_DIAGNOSTICS);
}
}
impl ServerDiagnostics {
pub fn server_diagnostics_summary(&self) -> &ServerDiagnosticsSummaryDataType {
&self.server_diagnostics_summary
}
pub fn on_rejected_security_session(&mut self) {
self.server_diagnostics_summary.security_rejected_session_count += 1;
}
pub fn on_rejected_session(&mut self) {
self.server_diagnostics_summary.rejected_session_count += 1;
}
pub fn on_create_session(&mut self, _session: &Session) {
self.server_diagnostics_summary.current_session_count += 1;
self.server_diagnostics_summary.cumulated_session_count += 1;
}
pub fn on_destroy_session(&mut self, _session: &Session) {
self.server_diagnostics_summary.current_session_count -= 1;
}
pub fn on_create_subscription(&mut self, _subscription: &Subscription) {
self.server_diagnostics_summary.current_subscription_count += 1;
self.server_diagnostics_summary.cumulated_subscription_count += 1;
}
pub fn on_destroy_subscription(&mut self, _subscription: &Subscription) {
self.server_diagnostics_summary.current_subscription_count -= 1;
}
pub fn on_session_timeout(&mut self) {
self.server_diagnostics_summary.session_timeout_count += 1;
}
pub fn on_server_view(&mut self, _session: &Session) {
self.server_diagnostics_summary.server_view_count += 1;
unimplemented!();
}
pub fn on_session_abort(&mut self, _session: &Session) {
self.server_diagnostics_summary.session_abort_count += 1;
unimplemented!()
}
pub fn on_publishing_interval(&mut self) {
self.server_diagnostics_summary.publishing_interval_count += 1;
unimplemented!()
}
pub fn on_security_rejected_request(&mut self) {
self.server_diagnostics_summary.security_rejected_requests_count += 1;
unimplemented!()
}
pub fn on_rejected_request(&mut self) {
self.server_diagnostics_summary.rejected_requests_count += 1;
unimplemented!()
}
}