rocketmq_common/common/running/
running_stats.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/// Stats tracking various runtime metrics of RocketMQ
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub enum RunningStats {
21    /// Maximum offset in the commit log
22    CommitLogMaxOffset,
23
24    /// Minimum offset in the commit log
25    CommitLogMinOffset,
26
27    /// Disk usage ratio for commit log
28    CommitLogDiskRatio,
29
30    /// Disk usage ratio for consume queue
31    ConsumeQueueDiskRatio,
32
33    /// Offset for scheduled messages
34    ScheduleMessageOffset,
35}
36
37impl RunningStats {
38    /// Get the string representation of the enum value
39    pub fn as_str(&self) -> &'static str {
40        match self {
41            RunningStats::CommitLogMaxOffset => "commitLogMaxOffset",
42            RunningStats::CommitLogMinOffset => "commitLogMinOffset",
43            RunningStats::CommitLogDiskRatio => "commitLogDiskRatio",
44            RunningStats::ConsumeQueueDiskRatio => "consumeQueueDiskRatio",
45            RunningStats::ScheduleMessageOffset => "scheduleMessageOffset",
46        }
47    }
48}
49
50impl std::fmt::Display for RunningStats {
51    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52        write!(f, "{}", self.as_str())
53    }
54}
55
56impl std::str::FromStr for RunningStats {
57    type Err = String;
58
59    fn from_str(s: &str) -> Result<Self, Self::Err> {
60        match s {
61            "commitLogMaxOffset" => Ok(RunningStats::CommitLogMaxOffset),
62            "commitLogMinOffset" => Ok(RunningStats::CommitLogMinOffset),
63            "commitLogDiskRatio" => Ok(RunningStats::CommitLogDiskRatio),
64            "consumeQueueDiskRatio" => Ok(RunningStats::ConsumeQueueDiskRatio),
65            "scheduleMessageOffset" => Ok(RunningStats::ScheduleMessageOffset),
66            _ => Err(format!("Unknown RunningStats value: {s}")),
67        }
68    }
69}