moduforge_core/
metrics.rs1use metrics::{counter, gauge, histogram, Unit};
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 = "core.task.processing.duration.seconds";
9pub const QUEUE_SIZE: &str = "core.queue.size";
11pub const PROCESSING_TASKS: &str = "core.processing.tasks";
13pub const TASKS_RETRIED_TOTAL: &str = "core.tasks.retried.total";
15
16pub const EDITOR_CREATION_DURATION_SECONDS: &str = "core.editor.creation.duration.seconds";
19pub const COMMANDS_EXECUTED_TOTAL: &str = "core.commands.executed.total";
21pub const TRANSACTIONS_DISPATCHED_TOTAL: &str = "core.transactions.dispatched.total";
23pub const MIDDLEWARE_EXECUTION_DURATION_SECONDS: &str = "core.middleware.execution.duration.seconds";
25pub const HISTORY_OPERATIONS_TOTAL: &str = "core.history.operations.total";
27pub const EVENTS_EMITTED_TOTAL: &str = "core.events.emitted.total";
29
30pub const EXTENSION_MANAGER_CREATION_DURATION_SECONDS: &str = "core.extension_manager.creation.duration.seconds";
33pub const EXTENSIONS_LOADED_TOTAL: &str = "core.extensions.loaded.total";
35pub const PLUGINS_LOADED_TOTAL: &str = "core.plugins.loaded.total";
37
38pub fn register_metrics() {
39 }
41
42pub fn task_submitted() {
43 counter!(TASKS_SUBMITTED_TOTAL).increment(1);
44}
45
46pub fn task_processed(status: &str) {
47 counter!(TASKS_PROCESSED_TOTAL, "status" => status.to_string()).increment(1);
48}
49
50pub fn task_processing_duration(duration: std::time::Duration) {
51 histogram!(TASK_PROCESSING_DURATION_SECONDS).record(duration.as_secs_f64());
52}
53
54pub fn set_queue_size(size: usize) {
55 gauge!(QUEUE_SIZE).set(size as f64);
56}
57
58pub fn increment_processing_tasks() {
59 gauge!(PROCESSING_TASKS).increment(1.0);
60}
61
62pub fn decrement_processing_tasks() {
63 gauge!(PROCESSING_TASKS).decrement(1.0);
64}
65
66pub fn task_retried() {
67 counter!(TASKS_RETRIED_TOTAL).increment(1);
68}
69
70pub fn editor_creation_duration(duration: std::time::Duration) {
71 histogram!(EDITOR_CREATION_DURATION_SECONDS).record(duration.as_secs_f64());
72}
73
74pub fn command_executed(name: &str) {
75 counter!(COMMANDS_EXECUTED_TOTAL, "command_name" => name.to_string()).increment(1);
76}
77
78pub fn transaction_dispatched() {
79 counter!(TRANSACTIONS_DISPATCHED_TOTAL).increment(1);
80}
81
82pub fn middleware_execution_duration(duration: std::time::Duration, mw_type: &str, mw_name: &str) {
83 histogram!(
84 MIDDLEWARE_EXECUTION_DURATION_SECONDS,
85 "type" => mw_type.to_string(),
86 "middleware_name" => mw_name.to_string()
87 )
88 .record(duration.as_secs_f64());
89}
90
91pub fn history_operation(op: &str) {
92 counter!(HISTORY_OPERATIONS_TOTAL, "operation" => op.to_string()).increment(1);
93}
94
95pub fn event_emitted(event_type: &str) {
96 counter!(EVENTS_EMITTED_TOTAL, "event_type" => event_type.to_string()).increment(1);
97}
98
99pub fn extension_manager_creation_duration(duration: std::time::Duration) {
100 histogram!(EXTENSION_MANAGER_CREATION_DURATION_SECONDS).record(duration.as_secs_f64());
101}
102
103pub fn extensions_loaded(count: u64) {
104 counter!(EXTENSIONS_LOADED_TOTAL).increment(count);
105}
106
107pub fn plugins_loaded(count: u64) {
108 counter!(PLUGINS_LOADED_TOTAL).increment(count);
109}