vector/top/
mod.rs

1//! Top subcommand
2mod cmd;
3
4use clap::Parser;
5use glob::Pattern;
6
7pub use cmd::{cmd, top};
8use url::Url;
9
10use crate::config::api::default_graphql_url;
11
12/// Top options
13#[derive(Parser, Debug, Clone)]
14#[command(rename_all = "kebab-case")]
15pub struct Opts {
16    /// Interval to sample metrics at, in milliseconds
17    #[arg(default_value = "1000", short = 'i', long)]
18    interval: u32,
19
20    /// GraphQL API server endpoint
21    #[arg(short, long)]
22    url: Option<Url>,
23
24    /// Humanize metrics, using numeric suffixes - e.g. 1,100 = 1.10 k, 1,000,000 = 1.00 M
25    #[arg(short = 'H', long, default_value_t = true)]
26    human_metrics: bool,
27
28    /// Whether to reconnect if the underlying API connection drops.
29    ///
30    /// By default, top will attempt to reconnect if the connection drops.
31    #[arg(short, long)]
32    no_reconnect: bool,
33
34    /// Components IDs to observe (comma-separated; accepts glob patterns)
35    #[arg(default_value = "*", value_delimiter(','), short = 'c', long)]
36    components: Vec<Pattern>,
37}
38
39impl Opts {
40    /// Use the provided URL as the Vector GraphQL API server, or default to the local port
41    /// provided by the API config.
42    pub fn url(&self) -> Url {
43        self.url.clone().unwrap_or_else(default_graphql_url)
44    }
45
46    /// URL with scheme set to WebSockets
47    pub fn web_socket_url(&self) -> Url {
48        let mut url = self.url();
49        url.set_scheme(match url.scheme() {
50            "https" => "wss",
51            _ => "ws",
52        })
53        .expect("Couldn't build WebSocket URL. Please report.");
54
55        url
56    }
57}