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