vector/top/
mod.rs

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