Skip to content

Commit 6e9fc6b

Browse files
committed
add --output-metrics format using prometheus-client
(Prometheus/OpenMetrics)
1 parent 93fe658 commit 6e9fc6b

12 files changed

Lines changed: 198 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ serde_json = "1.0"
4242
sysinfo = "0.37"
4343
ctrlc = "3"
4444
chrono = "0.4"
45+
prometheus-client = "0.24.1"
4546

4647
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
4748
portable-atomic = "1.4"

completions/_dust

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ m\:"last modified time"))' \
107107
'(-D --only-dir)--only-file[Only files will be displayed. (Finds your largest files)]' \
108108
'-j[Output the directory tree as json to the current directory]' \
109109
'--output-json[Output the directory tree as json to the current directory]' \
110+
'--output-metrics[Output the directory tree as OpenMetrics / prometheus metrics]' \
110111
'-h[Print help (see more with '\''--help'\'')]' \
111112
'--help[Print help (see more with '\''--help'\'')]' \
112113
'-V[Print version]' \

completions/_dust.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Register-ArgumentCompleter -Native -CommandName 'dust' -ScriptBlock {
9191
[CompletionResult]::new('--only-file', '--only-file', [CompletionResultType]::ParameterName, 'Only files will be displayed. (Finds your largest files)')
9292
[CompletionResult]::new('-j', '-j', [CompletionResultType]::ParameterName, 'Output the directory tree as json to the current directory')
9393
[CompletionResult]::new('--output-json', '--output-json', [CompletionResultType]::ParameterName, 'Output the directory tree as json to the current directory')
94+
[CompletionResult]::new('--output-metrics', '--output-metrics', [CompletionResultType]::ParameterName, 'Output the directory tree as OpenMetrics / prometheus metrics')
9495
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
9596
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
9697
[CompletionResult]::new('-V', '-V ', [CompletionResultType]::ParameterName, 'Print version')

completions/dust.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _dust() {
2323

2424
case "${cmd}" in
2525
dust)
26-
opts="-d -T -n -p -X -I -L -x -s -r -c -C -b -B -z -R -f -i -v -e -t -w -P -D -F -o -S -j -M -A -y -m -h -V --depth --threads --config --number-of-lines --full-paths --ignore-directory --ignore-all-in-file --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --force-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore-hidden --invert-filter --filter --file-types --terminal-width --no-progress --print-errors --only-dir --only-file --output-format --stack-size --output-json --mtime --atime --ctime --files0-from --files-from --collapse --filetime --help --version [PATH]..."
26+
opts="-d -T -n -p -X -I -L -x -s -r -c -C -b -B -z -R -f -i -v -e -t -w -P -D -F -o -S -j -M -A -y -m -h -V --depth --threads --config --number-of-lines --full-paths --ignore-directory --ignore-all-in-file --dereference-links --limit-filesystem --apparent-size --reverse --no-colors --force-colors --no-percent-bars --bars-on-right --min-size --screen-reader --skip-total --filecount --ignore-hidden --invert-filter --filter --file-types --terminal-width --no-progress --print-errors --only-dir --only-file --output-format --stack-size --output-json --output-metrics --mtime --atime --ctime --files0-from --files-from --collapse --filetime --help --version [PATH]..."
2727
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
2828
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
2929
return 0

completions/dust.elv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ set edit:completion:arg-completer[dust] = {|@words|
8888
cand --only-file 'Only files will be displayed. (Finds your largest files)'
8989
cand -j 'Output the directory tree as json to the current directory'
9090
cand --output-json 'Output the directory tree as json to the current directory'
91+
cand --output-metrics 'Output the directory tree as OpenMetrics / prometheus metrics'
9192
cand -h 'Print help (see more with ''--help'')'
9293
cand --help 'Print help (see more with ''--help'')'
9394
cand -V 'Print version'

completions/dust.fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ complete -c dust -l print-errors -d 'Print path with errors'
4747
complete -c dust -s D -l only-dir -d 'Only directories will be displayed'
4848
complete -c dust -s F -l only-file -d 'Only files will be displayed. (Finds your largest files)'
4949
complete -c dust -s j -l output-json -d 'Output the directory tree as json to the current directory'
50+
complete -c dust -l output-metrics -d 'Output the directory tree as OpenMetrics / prometheus metrics'
5051
complete -c dust -s h -l help -d 'Print help (see more with \'--help\')'
5152
complete -c dust -s V -l version -d 'Print version'

man-page/dust.1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.SH NAME
55
Dust \- Like du but more intuitive
66
.SH SYNOPSIS
7-
\fBdust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-T\fR|\fB\-\-threads\fR] [\fB\-\-config\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-I\fR|\fB\-\-ignore\-all\-in\-file\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-C\fR|\fB\-\-force\-colors\fR] [\fB\-b\fR|\fB\-\-no\-percent\-bars\fR] [\fB\-B\fR|\fB\-\-bars\-on\-right\fR] [\fB\-z\fR|\fB\-\-min\-size\fR] [\fB\-R\fR|\fB\-\-screen\-reader\fR] [\fB\-\-skip\-total\fR] [\fB\-f\fR|\fB\-\-filecount\fR] [\fB\-i\fR|\fB\-\-ignore\-hidden\fR] [\fB\-v\fR|\fB\-\-invert\-filter\fR] [\fB\-e\fR|\fB\-\-filter\fR] [\fB\-t\fR|\fB\-\-file\-types\fR] [\fB\-w\fR|\fB\-\-terminal\-width\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-\-print\-errors\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fB\-o\fR|\fB\-\-output\-format\fR] [\fB\-S\fR|\fB\-\-stack\-size\fR] [\fB\-j\fR|\fB\-\-output\-json\fR] [\fB\-M\fR|\fB\-\-mtime\fR] [\fB\-A\fR|\fB\-\-atime\fR] [\fB\-y\fR|\fB\-\-ctime\fR] [\fB\-\-files0\-from\fR] [\fB\-\-files\-from\fR] [\fB\-\-collapse\fR] [\fB\-m\fR|\fB\-\-filetime\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIPATH\fR]
7+
\fBdust\fR [\fB\-d\fR|\fB\-\-depth\fR] [\fB\-T\fR|\fB\-\-threads\fR] [\fB\-\-config\fR] [\fB\-n\fR|\fB\-\-number\-of\-lines\fR] [\fB\-p\fR|\fB\-\-full\-paths\fR] [\fB\-X\fR|\fB\-\-ignore\-directory\fR] [\fB\-I\fR|\fB\-\-ignore\-all\-in\-file\fR] [\fB\-L\fR|\fB\-\-dereference\-links\fR] [\fB\-x\fR|\fB\-\-limit\-filesystem\fR] [\fB\-s\fR|\fB\-\-apparent\-size\fR] [\fB\-r\fR|\fB\-\-reverse\fR] [\fB\-c\fR|\fB\-\-no\-colors\fR] [\fB\-C\fR|\fB\-\-force\-colors\fR] [\fB\-b\fR|\fB\-\-no\-percent\-bars\fR] [\fB\-B\fR|\fB\-\-bars\-on\-right\fR] [\fB\-z\fR|\fB\-\-min\-size\fR] [\fB\-R\fR|\fB\-\-screen\-reader\fR] [\fB\-\-skip\-total\fR] [\fB\-f\fR|\fB\-\-filecount\fR] [\fB\-i\fR|\fB\-\-ignore\-hidden\fR] [\fB\-v\fR|\fB\-\-invert\-filter\fR] [\fB\-e\fR|\fB\-\-filter\fR] [\fB\-t\fR|\fB\-\-file\-types\fR] [\fB\-w\fR|\fB\-\-terminal\-width\fR] [\fB\-P\fR|\fB\-\-no\-progress\fR] [\fB\-\-print\-errors\fR] [\fB\-D\fR|\fB\-\-only\-dir\fR] [\fB\-F\fR|\fB\-\-only\-file\fR] [\fB\-o\fR|\fB\-\-output\-format\fR] [\fB\-S\fR|\fB\-\-stack\-size\fR] [\fB\-j\fR|\fB\-\-output\-json\fR] [\fB\-\-output\-metrics\fR] [\fB\-M\fR|\fB\-\-mtime\fR] [\fB\-A\fR|\fB\-\-atime\fR] [\fB\-y\fR|\fB\-\-ctime\fR] [\fB\-\-files0\-from\fR] [\fB\-\-files\-from\fR] [\fB\-\-collapse\fR] [\fB\-m\fR|\fB\-\-filetime\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fIPATH\fR]
88
.SH DESCRIPTION
99
Like du but more intuitive
1010
.SH OPTIONS
@@ -128,6 +128,9 @@ Specify memory to use as stack size \- use if you see: \*(Aqfatal runtime error:
128128
\fB\-j\fR, \fB\-\-output\-json\fR
129129
Output the directory tree as json to the current directory
130130
.TP
131+
\fB\-\-output\-metrics\fR
132+
Output the directory tree as OpenMetrics / prometheus metrics
133+
.TP
131134
\fB\-M\fR, \fB\-\-mtime\fR \fI<MTIME>\fR
132135
+/\-n matches files modified more/less than n days ago , and n matches files modified exactly n days ago, days are rounded down.That is +n => (−∞, curr−(n+1)), n => [curr−(n+1), curr−n), and \-n => (𝑐𝑢𝑟𝑟−𝑛, +∞)
133136
.TP

src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ pub struct Cli {
158158
#[arg(short('j'), long)]
159159
pub output_json: bool,
160160

161+
/// Output the directory tree as OpenMetrics / prometheus metrics
162+
#[arg(long)]
163+
pub output_metrics: bool,
164+
161165
/// +/-n matches files modified more/less than n days ago , and n matches
162166
/// files modified exactly n days ago, days are rounded down.That is +n =>
163167
/// (−∞, curr−(n+1)), n => [curr−(n+1), curr−n), and -n => (𝑐𝑢𝑟𝑟−𝑛, +∞)

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub struct Config {
3434
pub stack_size: Option<usize>,
3535
pub threads: Option<usize>,
3636
pub output_json: Option<bool>,
37+
pub output_metrics: Option<bool>,
3738
pub print_errors: Option<bool>,
3839
pub files0_from: Option<String>,
3940
pub number_of_lines: Option<usize>,
@@ -157,6 +158,9 @@ impl Config {
157158
pub fn get_output_json(&self, options: &Cli) -> bool {
158159
Some(true) == self.output_json || options.output_json
159160
}
161+
pub fn get_output_metrics(&self, options: &Cli) -> bool {
162+
Some(true) == self.output_metrics || options.output_metrics
163+
}
160164

161165
pub fn get_number_of_lines(&self, options: &Cli) -> Option<usize> {
162166
let from_cmd_line = options.number_of_lines;

0 commit comments

Comments
 (0)