opcua_server/diagnostics.rs
1// OPCUA for Rust
2// SPDX-License-Identifier: MPL-2.0
3// Copyright (C) 2017-2022 Adam Lock
4
5//! Provides diagnostics structures and functions for gathering information about the running
6//! state of a server.
7use opcua_types::service_types::ServerDiagnosticsSummaryDataType;
8
9use opcua_core::RUNTIME;
10
11use crate::{session::Session, subscriptions::subscription::Subscription};
12
13/// Structure that captures di agnostics information for the server
14#[derive(Clone, Serialize, Debug)]
15pub struct ServerDiagnostics {
16 /// This is a live summary of the server diagnostics
17 server_diagnostics_summary: ServerDiagnosticsSummaryDataType,
18}
19
20const SERVER_DIAGNOSTICS: &str = "ServerDiagnostics";
21
22impl Default for ServerDiagnostics {
23 fn default() -> Self {
24 register_runtime_component!(SERVER_DIAGNOSTICS);
25 Self {
26 server_diagnostics_summary: ServerDiagnosticsSummaryDataType::default(),
27 }
28 }
29}
30
31impl Drop for ServerDiagnostics {
32 fn drop(&mut self) {
33 deregister_runtime_component!(SERVER_DIAGNOSTICS);
34 }
35}
36
37impl ServerDiagnostics {
38 /// Return a completed summary of the server diagnostics as they stand. This structure
39 /// is used to fill the address space stats about the server.
40 pub fn server_diagnostics_summary(&self) -> &ServerDiagnosticsSummaryDataType {
41 &self.server_diagnostics_summary
42 }
43
44 /// Increment the number of requests that were rejected due to security constraints since the server was
45 /// started (or restarted). The requests include all Services defined in Part 4, also requests
46 /// to create sessions.
47 pub(crate) fn on_rejected_security_session(&mut self) {
48 self.server_diagnostics_summary
49 .security_rejected_session_count += 1;
50 }
51
52 /// Increment the number of requests that were rejected since the server was started (or restarted). The
53 /// requests include all Services defined in Part 4, also requests to create sessions. This
54 /// number includes the securityRejectedRequestsCount.
55 pub(crate) fn on_rejected_session(&mut self) {
56 self.server_diagnostics_summary.rejected_session_count += 1;
57 }
58
59 /// Increment the number of client sessions currently established in the server.
60 pub(crate) fn on_create_session(&mut self, _session: &Session) {
61 self.server_diagnostics_summary.current_session_count += 1;
62 self.server_diagnostics_summary.cumulated_session_count += 1;
63 debug!(
64 "Incrementing current session count to {}",
65 self.server_diagnostics_summary.current_session_count
66 );
67 }
68
69 /// Decrement the number of client sessions currently established in the server.
70 pub(crate) fn on_destroy_session(&mut self, _session: &Session) {
71 self.server_diagnostics_summary.current_session_count -= 1;
72 debug!(
73 "Decrementing current session count to {}",
74 self.server_diagnostics_summary.current_session_count
75 );
76 }
77
78 /// Increment the number of subscriptions currently established in the server.
79 pub(crate) fn on_create_subscription(&mut self, _subscription: &Subscription) {
80 self.server_diagnostics_summary.current_subscription_count += 1;
81 self.server_diagnostics_summary.cumulated_subscription_count += 1;
82 }
83
84 /// Decrement the number of subscriptions currently established in the server.
85 pub(crate) fn on_destroy_subscription(&mut self, _subscription: &Subscription) {
86 self.server_diagnostics_summary.current_subscription_count -= 1;
87 }
88
89 /// Increment the number of client sessions that were closed due to timeout since the server was started (or restarted).
90 pub(crate) fn on_session_timeout(&mut self) {
91 self.server_diagnostics_summary.session_timeout_count += 1;
92 }
93
94 // --- These are not yet called by anything
95
96 /*
97 /// Increment the number of server-created views in the server.
98 pub(crate) fn on_server_view(&mut self, _session: &Session) {
99 self.server_diagnostics_summary.server_view_count += 1;
100 unimplemented!();
101 }
102
103 /// Increment the number of client sessions that were closed due to errors since the server was started (or restarted).
104 pub(crate) fn on_session_abort(&mut self, _session: &Session) {
105 self.server_diagnostics_summary.session_abort_count += 1;
106 unimplemented!()
107 }
108
109 /// Increment the number of publishing intervals currently supported in the server.
110 pub(crate) fn on_publishing_interval(&mut self) {
111 self.server_diagnostics_summary.publishing_interval_count += 1;
112 unimplemented!()
113 }
114
115 /// Increment the number of requests that were rejected due to security constraints since the server was
116 /// started (or restarted). The requests include all Services defined in Part 4, also requests
117 /// to create sessions.
118 pub fn on_security_rejected_request(&mut self) {
119 self.server_diagnostics_summary.security_rejected_requests_count += 1;
120 unimplemented!()
121 }
122
123 /// Increment the number of requests that were rejected since the server was started (or restarted). The
124 /// requests include all Services defined in Part 4, also requests to create sessions. This
125 /// number includes the securityRejectedRequestsCount.
126 pub(crate) fn on_rejected_request(&mut self) {
127 self.server_diagnostics_summary.rejected_requests_count += 1;
128 unimplemented!()
129 }
130 */
131}