1use metrics::{counter, gauge, histogram};
2
3pub const TASKS_SUBMITTED_TOTAL: &str = "core.tasks.submitted.total";
5pub const TASKS_PROCESSED_TOTAL: &str = "core.tasks.processed.total";
7pub const TASK_PROCESSING_DURATION_SECONDS: &str =
9 "core.task.processing.duration.seconds";
10pub const QUEUE_SIZE: &str = "core.queue.size";
12pub const PROCESSING_TASKS: &str = "core.processing.tasks";
14pub const TASKS_RETRIED_TOTAL: &str = "core.tasks.retried.total";
16
17pub const EDITOR_CREATION_DURATION_SECONDS: &str =
20 "core.editor.creation.duration.seconds";
21pub const COMMANDS_EXECUTED_TOTAL: &str = "core.commands.executed.total";
23pub const TRANSACTIONS_DISPATCHED_TOTAL: &str =
25 "core.transactions.dispatched.total";
26pub const MIDDLEWARE_EXECUTION_DURATION_SECONDS: &str =
28 "core.middleware.execution.duration.seconds";
29pub const HISTORY_OPERATIONS_TOTAL: &str = "core.history.operations.total";
31pub const EVENTS_EMITTED_TOTAL: &str = "core.events.emitted.total";
33
34pub const EXTENSION_MANAGER_CREATION_DURATION_SECONDS: &str =
37 "core.extension_manager.creation.duration.seconds";
38pub const EXTENSIONS_LOADED_TOTAL: &str = "core.extensions.loaded.total";
40pub const PLUGINS_LOADED_TOTAL: &str = "core.plugins.loaded.total";
42pub const XML_PARSING_DURATION_SECONDS: &str =
44 "core.xml.parsing.duration.seconds";
45
46pub fn register_metrics() {
47 }
49
50pub fn task_submitted() {
51 counter!(TASKS_SUBMITTED_TOTAL).increment(1);
52}
53
54pub fn task_processed(status: &str) {
55 counter!(TASKS_PROCESSED_TOTAL, "status" => status.to_string())
56 .increment(1);
57}
58
59pub fn task_processing_duration(duration: std::time::Duration) {
60 histogram!(TASK_PROCESSING_DURATION_SECONDS).record(duration.as_secs_f64());
61}
62
63pub fn set_queue_size(size: usize) {
64 gauge!(QUEUE_SIZE).set(size as f64);
65}
66
67pub fn increment_processing_tasks() {
68 gauge!(PROCESSING_TASKS).increment(1.0);
69}
70
71pub fn decrement_processing_tasks() {
72 gauge!(PROCESSING_TASKS).decrement(1.0);
73}
74
75pub fn task_retried() {
76 counter!(TASKS_RETRIED_TOTAL).increment(1);
77}
78
79pub fn editor_creation_duration(duration: std::time::Duration) {
80 histogram!(EDITOR_CREATION_DURATION_SECONDS).record(duration.as_secs_f64());
81}
82
83pub fn command_executed(name: &str) {
84 counter!(COMMANDS_EXECUTED_TOTAL, "command_name" => name.to_string())
85 .increment(1);
86}
87
88pub fn transaction_dispatched() {
89 counter!(TRANSACTIONS_DISPATCHED_TOTAL).increment(1);
90}
91
92pub fn middleware_execution_duration(
93 duration: std::time::Duration,
94 mw_type: &str,
95 mw_name: &str,
96) {
97 histogram!(
98 MIDDLEWARE_EXECUTION_DURATION_SECONDS,
99 "type" => mw_type.to_string(),
100 "middleware_name" => mw_name.to_string()
101 )
102 .record(duration.as_secs_f64());
103}
104
105pub fn history_operation(op: &str) {
106 counter!(HISTORY_OPERATIONS_TOTAL, "operation" => op.to_string())
107 .increment(1);
108}
109
110pub fn event_emitted(event_type: &str) {
111 counter!(EVENTS_EMITTED_TOTAL, "event_type" => event_type.to_string())
112 .increment(1);
113}
114
115pub fn extension_manager_creation_duration(duration: std::time::Duration) {
116 histogram!(EXTENSION_MANAGER_CREATION_DURATION_SECONDS)
117 .record(duration.as_secs_f64());
118}
119
120pub fn extensions_loaded(count: u64) {
121 counter!(EXTENSIONS_LOADED_TOTAL).increment(count);
122}
123
124pub fn plugins_loaded(count: u64) {
125 counter!(PLUGINS_LOADED_TOTAL).increment(count);
126}
127
128pub fn xml_parsing_duration(duration: std::time::Duration) {
129 histogram!(XML_PARSING_DURATION_SECONDS).record(duration.as_secs_f64());
130}