File tree Expand file tree Collapse file tree 3 files changed +30
-28
lines changed Expand file tree Collapse file tree 3 files changed +30
-28
lines changed Original file line number Diff line number Diff line change 1
1
use byte_unit:: Byte ;
2
2
use serde:: Deserialize ;
3
3
use serde_with:: { serde_as, DurationSeconds } ;
4
- use std:: {
5
- fs,
6
- path:: { Path , PathBuf } ,
7
- time:: Duration ,
8
- } ;
4
+ use std:: { path:: PathBuf , time:: Duration } ;
9
5
use url:: Url ;
10
6
11
7
#[ serde_as]
@@ -21,29 +17,10 @@ pub(crate) struct Config {
21
17
22
18
impl Config {
23
19
pub ( crate ) fn get_disk_usage ( & self ) -> std:: io:: Result < Byte > {
24
- get_size ( & self . video_directory )
20
+ crate :: utils :: get_size ( & self . video_directory )
25
21
}
26
22
}
27
23
28
- pub ( crate ) fn get_size < P > ( path : P ) -> std:: io:: Result < Byte >
29
- where
30
- P : AsRef < Path > ,
31
- {
32
- let mut result: u128 = 0 ;
33
-
34
- for entry in fs:: read_dir ( & path) ? {
35
- let path = entry?. path ( ) ;
36
-
37
- if path. is_file ( ) {
38
- result += path. metadata ( ) ?. len ( ) as u128 ;
39
- } else {
40
- result += get_size ( path) ?. get_bytes ( ) ;
41
- }
42
- }
43
-
44
- Ok ( Byte :: from_bytes ( result) )
45
- }
46
-
47
24
#[ derive( Clone , Deserialize ) ]
48
25
pub ( crate ) struct StreamConfig {
49
26
pub ( crate ) url : Url ,
Original file line number Diff line number Diff line change 1
1
mod config;
2
2
mod ffmpeg;
3
3
mod server;
4
+ mod utils;
4
5
5
6
use clap:: Parser ;
6
7
use kagiyama:: prometheus:: { metrics:: gauge:: Gauge , registry:: Unit } ;
@@ -120,9 +121,10 @@ async fn main() {
120
121
#[ tracing:: instrument( skip_all) ]
121
122
fn update_segment_count_metric ( metric : & Gauge , config : & config:: Config ) {
122
123
debug ! ( "Updating segment count metric" ) ;
124
+
123
125
match std:: fs:: read_dir ( & config. video_directory ) {
124
- Ok ( doot ) => {
125
- let num = doot
126
+ Ok ( contents ) => {
127
+ let ts_file_count = contents
126
128
. filter_map ( |i| i. ok ( ) )
127
129
. map ( |i| i. path ( ) )
128
130
. filter ( |i| {
@@ -137,7 +139,8 @@ fn update_segment_count_metric(metric: &Gauge, config: &config::Config) {
137
139
}
138
140
} )
139
141
. count ( ) ;
140
- metric. set ( num as i64 ) ;
142
+
143
+ metric. set ( ts_file_count as i64 ) ;
141
144
}
142
145
Err ( e) => {
143
146
warn ! ( "Failed to read video directory, err={}" , e) ;
@@ -148,6 +151,7 @@ fn update_segment_count_metric(metric: &Gauge, config: &config::Config) {
148
151
#[ tracing:: instrument( skip_all) ]
149
152
fn update_disk_usage_metric ( metric : & Gauge , config : & config:: Config ) {
150
153
debug ! ( "Updating disk usage metric" ) ;
154
+
151
155
match config. get_disk_usage ( ) {
152
156
Ok ( disk_usage) => {
153
157
metric. set ( disk_usage. get_bytes ( ) as i64 ) ;
Original file line number Diff line number Diff line change
1
+ use byte_unit:: Byte ;
2
+ use std:: { fs, path:: Path } ;
3
+
4
+ pub ( crate ) fn get_size < P > ( path : P ) -> std:: io:: Result < Byte >
5
+ where
6
+ P : AsRef < Path > ,
7
+ {
8
+ let mut result: u128 = 0 ;
9
+
10
+ for entry in fs:: read_dir ( & path) ? {
11
+ let path = entry?. path ( ) ;
12
+
13
+ if path. is_file ( ) {
14
+ result += path. metadata ( ) ?. len ( ) as u128 ;
15
+ } else {
16
+ result += get_size ( path) ?. get_bytes ( ) ;
17
+ }
18
+ }
19
+
20
+ Ok ( Byte :: from_bytes ( result) )
21
+ }
You can’t perform that action at this time.
0 commit comments