bsc/
stats.rs

1use std::time::Duration;
2
3use serde::{Deserialize, Serialize};
4
5use crate::Id;
6
7#[derive(Debug, Serialize, Deserialize)]
8pub struct StatsJob {
9    /// "id" is the job id
10    pub id: Id,
11    /// "tube" is the name of the tube that contains this job
12    pub tube: String,
13    /// "state" is "ready" or "delayed" or "reserved" or "buried"
14    pub state: State,
15    /// "pri" is the priority value set by the put, release, or bury commands.
16    pub pri: u32,
17    /// "age" is the time in seconds since the put command that created this job.
18    #[serde(deserialize_with = "from_seconds")]
19    pub age: Duration,
20    /// "delay" is the integer number of seconds to wait before putting this job in
21    ///   the ready queue.
22    #[serde(deserialize_with = "from_seconds")]
23    pub delay: Duration,
24    /// "ttr" -- time to run -- is the integer number of seconds a worker is
25    ///   allowed to run this job.
26    pub ttr: u32,
27    /// "time-left" is the number of seconds left until the server puts this job
28    ///   into the ready queue. This number is only meaningful if the job is
29    ///   reserved or delayed. If the job is reserved and this amount of time
30    ///   elapses before its state changes, it is considered to have timed out.
31    #[serde(rename = "time-left", deserialize_with = "from_seconds")]
32    pub time_left: Duration,
33    /// "file" is the number of the earliest binlog file containing this job.
34    ///   If -b wasn't used, this will be 0.
35    pub file: u32,
36    /// "reserves" is the number of times this job has been reserved.
37    pub reserves: u32,
38    /// "timeouts" is the number of times this job has timed out during a
39    ///   reservation.
40    pub timeouts: u32,
41    /// "releases" is the number of times a client has released this job from a
42    ///   reservation.
43    pub releases: u32,
44    /// "buries" is the number of times this job has been buried.
45    pub buries: u32,
46    /// "kicks" is the number of times this job has been kicked.
47    pub kicks: u32,
48}
49
50#[derive(Debug, Serialize, Deserialize)]
51#[serde(rename_all = "lowercase")]
52pub enum State {
53    Ready,
54    Delayed,
55    Reserved,
56    Buried,
57}
58
59#[derive(Debug, Serialize, Deserialize)]
60pub struct StatsTube {
61    /// "name" is the tube's name.
62    pub name: String,
63    /// "current-jobs-urgent" is the number of ready jobs with priority < 1024 in
64    /// this tube.
65    #[serde(rename = "current-jobs-urgent")]
66    pub current_jobs_urgent: u32,
67    /// "current-jobs-ready" is the number of jobs in the ready queue in this tube.
68    #[serde(rename = "current-jobs-ready")]
69    pub current_jobs_ready: u32,
70    /// "current-jobs-reserved" is the number of jobs reserved by all clients in
71    /// this tube.
72    #[serde(rename = "current-jobs-reserved")]
73    pub current_jobs_reserved: u32,
74    /// "current-jobs-delayed" is the number of delayed jobs in this tube.
75    #[serde(rename = "current-jobs-delayed")]
76    pub current_jobs_delayed: u32,
77    /// "current-jobs-buried" is the number of buried jobs in this tube.
78    #[serde(rename = "current-jobs-buried")]
79    pub current_jobs_buried: u32,
80    /// "total-jobs" is the cumulative count of jobs created in this tube in
81    ///  the current beanstalkd process.
82    #[serde(rename = "total-jobs")]
83    pub total_jobs: u32,
84    /// "current-using" is the number of open connections that are currently
85    ///  using this tube.
86    #[serde(rename = "current-using")]
87    pub current_using: u32,
88    /// "current-waiting" is the number of open connections that have issued a
89    ///  reserve command while watching this tube but not yet received a response.
90    #[serde(rename = "current-waiting")]
91    pub current_waiting: u32,
92    /// "current-watching" is the number of open connections that are currently
93    ///  watching this tube.
94    #[serde(rename = "current-watching")]
95    pub current_watching: u32,
96    /// "pause" is the number of seconds the tube has been paused for.
97    pub pause: u32,
98    /// "cmd-delete" is the cumulative number of delete commands for this tube
99    #[serde(rename = "cmd-delete")]
100    pub cmd_delete: u32,
101    /// "cmd-pause-tube" is the cumulative number of pause-tube commands for this tube.
102    #[serde(rename = "cmd-pause-tube")]
103    pub cmd_pause_tube: u32,
104    /// "pause-time-left" is the number of seconds until the tube is un-paused.
105    #[serde(
106        rename = "pause-time-left",
107        serialize_with = "as_seconds",
108        deserialize_with = "from_seconds"
109    )]
110    pub pause_time_left: Duration,
111}
112
113#[derive(Debug, Serialize, Deserialize)]
114pub struct Stats {
115    /// "current-jobs-urgent" is the number of ready jobs with priority < 1024.
116    #[serde(rename = "current-jobs-urgent")]
117    pub current_jobs_urgent: u32,
118    /// "current-jobs-ready" is the number of jobs in the ready queue.
119    #[serde(rename = "current-jobs-ready")]
120    pub current_jobs_ready: u32,
121    /// "current-jobs-reserved" is the number of jobs reserved by all clients.
122    #[serde(rename = "current-jobs-reserved")]
123    pub current_jobs_reserved: u32,
124    /// "current-jobs-delayed" is the number of delayed jobs.
125    #[serde(rename = "current-jobs-delayed")]
126    pub current_jobs_delayed: u32,
127    /// "current-jobs-buried" is the number of buried jobs.
128    #[serde(rename = "current-jobs-buried")]
129    pub current_jobs_buried: u32,
130    /// "cmd-put" is the cumulative number of put commands.
131    #[serde(rename = "cmd-put")]
132    pub cmd_put: u32,
133    /// "cmd-peek" is the cumulative number of peek commands.
134    #[serde(rename = "cmd-peek")]
135    pub cmd_peek: u32,
136    /// "cmd-peek-ready" is the cumulative number of peek-ready commands.
137    #[serde(rename = "cmd-peek-ready")]
138    pub cmd_peek_ready: u32,
139    /// "cmd-peek-delayed" is the cumulative number of peek-delayed commands.
140    #[serde(rename = "cmd-peek-delayed")]
141    pub cmd_peek_delayed: u32,
142    /// "cmd-peek-buried" is the cumulative number of peek-buried commands.
143    #[serde(rename = "cmd-peek-buried")]
144    pub cmd_peek_buried: u32,
145    /// "cmd-reserve" is the cumulative number of reserve commands.
146    #[serde(rename = "cmd-reserve")]
147    pub cmd_reserve: u32,
148    /// "cmd-use" is the cumulative number of use commands.
149    #[serde(rename = "cmd-use")]
150    pub cmd_use: u32,
151    /// "cmd-watch" is the cumulative number of watch commands.
152    #[serde(rename = "cmd-watch")]
153    pub cmd_watch: u32,
154    /// "cmd-ignore" is the cumulative number of ignore commands.
155    #[serde(rename = "cmd-ignore")]
156    pub cmd_ignore: u32,
157    /// "cmd-delete" is the cumulative number of delete commands.
158    #[serde(rename = "cmd-delete")]
159    pub cmd_delete: u32,
160    /// "cmd-release" is the cumulative number of release commands.
161    #[serde(rename = "cmd-release")]
162    pub cmd_release: u32,
163    /// "cmd-bury" is the cumulative number of bury commands.
164    #[serde(rename = "cmd-bury")]
165    pub cmd_bury: u32,
166    /// "cmd-kick" is the cumulative number of kick commands.
167    #[serde(rename = "cmd-kick")]
168    pub cmd_kick: u32,
169    /// "cmd-stats" is the cumulative number of stats commands.
170    #[serde(rename = "cmd-stats")]
171    pub cmd_stats: u32,
172    /// "cmd-stats-job" is the cumulative number of stats-job commands.
173    #[serde(rename = "cmd-stats-job")]
174    pub cmd_stats_job: u32,
175    /// "cmd-stats-tube" is the cumulative number of stats-tube commands.
176    #[serde(rename = "cmd-stats-tube")]
177    pub cmd_stats_tube: u32,
178    /// "cmd-list-tubes" is the cumulative number of list-tubes commands.
179    #[serde(rename = "cmd-list-tubes")]
180    pub cmd_list_tubes: u32,
181    /// "cmd-list-tube-used" is the cumulative number of list-tube-used commands.
182    #[serde(rename = "cmd-list-tube-used")]
183    pub cmd_list_tube_used: u32,
184    /// "cmd-list-tubes-watched" is the cumulative number of list-tubes-watched commands.
185    #[serde(rename = "cmd-list-tubes-watched")]
186    pub cmd_list_tubes_watched: u32,
187    /// "cmd-pause-tube" is the cumulative number of pause-tube commands.
188    #[serde(rename = "cmd-pause-tube")]
189    pub cmd_pause_tube: u32,
190    /// "job-timeouts" is the cumulative count of times a job has timed out.
191    #[serde(rename = "job-timeouts")]
192    pub job_timeouts: u32,
193    /// "total-jobs" is the cumulative count of jobs created.
194    #[serde(rename = "total-jobs")]
195    pub total_jobs: u32,
196    /// "max-job-size" is the maximum number of bytes in a job.
197    #[serde(rename = "max-job-size")]
198    pub max_job_size: u32,
199    /// "current-tubes" is the number of currently-existing tubes.
200    #[serde(rename = "current-tubes")]
201    pub current_tubes: u32,
202    /// "current-connections" is the number of currently open connections.
203    #[serde(rename = "current-connections")]
204    pub current_connections: u32,
205    /// "current-producers" is the number of open connections that have each issued at least one put command.
206    #[serde(rename = "current-producers")]
207    pub current_producers: u32,
208    /// "current-workers" is the number of open connections that have each issued at least one reserve command.
209    #[serde(rename = "current-workers")]
210    pub current_workers: u32,
211    /// "current-waiting" is the number of open connections that have issued a reserve command but not yet received a response.
212    #[serde(rename = "current-waiting")]
213    pub current_waiting: u32,
214    /// "total-connections" is the cumulative count of connections.
215    #[serde(rename = "total-connections")]
216    pub total_connections: u32,
217    /// "pid" is the process id of the server.
218    #[serde(rename = "pid")]
219    pub pid: u32,
220    /// "version" is the version string of the server.
221    #[serde(rename = "version")]
222    pub version: String,
223    /// "rusage-utime" is the cumulative user CPU time of this process in seconds and microseconds.
224    #[serde(rename = "rusage-utime")]
225    pub rusage_utime: f32,
226    /// "rusage-stime" is the cumulative system CPU time of this process in seconds and microseconds.
227    #[serde(rename = "rusage-stime")]
228    pub rusage_stime: f32,
229    /// "uptime" is the number of seconds since this server process started running.
230    #[serde(
231        rename = "uptime",
232        serialize_with = "as_seconds",
233        deserialize_with = "from_seconds"
234    )]
235    pub uptime: Duration,
236    /// "binlog-oldest-index" is the index of the oldest binlog file needed to store the current jobs.
237    #[serde(rename = "binlog-oldest-index")]
238    pub binlog_oldest_index: usize,
239    /// "binlog-current-index" is the index of the current binlog file being written to. If binlog is not active this value will be 0.
240    #[serde(rename = "binlog-current-index")]
241    pub binlog_current_index: usize,
242    /// "binlog-max-size" is the maximum size in bytes a binlog file is allowed to get before a new binlog file is opened.
243    #[serde(rename = "binlog-max-size")]
244    pub binlog_max_size: usize,
245    /// "binlog-records-written" is the cumulative number of records written to the binlog.
246    #[serde(rename = "binlog-records-written")]
247    pub binlog_records_written: u32,
248    /// "binlog-records-migrated" is the cumulative number of records written as part of compaction.
249    #[serde(rename = "binlog-records-migrated")]
250    pub binlog_records_migrated: u32,
251    /// "draining" is set to "true" if the server is in drain mode, "false" otherwise.
252    #[serde(default)]
253    pub draining: bool,
254    /// "id" is a random id string for this server process, generated every time beanstalkd process starts.
255    pub id: String,
256    /// "hostname" is the hostname of the machine as determined by uname.
257    pub hostname: String,
258    /// "os" is the OS version as determined by uname
259    pub os: Option<String>,
260    /// "platform" is the machine architecture as determined by uname
261    pub platform: Option<String>,
262}
263
264pub fn as_seconds<S>(value: &Duration, serializer: S) -> Result<S::Ok, S::Error>
265where
266    S: serde::Serializer,
267{
268    value.serialize(serializer)
269}
270
271pub fn from_seconds<'de, D>(deserializer: D) -> Result<Duration, D::Error>
272where
273    D: serde::Deserializer<'de>,
274{
275    u64::deserialize(deserializer).map(Duration::from_secs)
276}