flags.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package flags
  2. import (
  3. "os"
  4. "strings"
  5. "gopkg.in/alecthomas/kingpin.v2"
  6. )
  7. var (
  8. ListenAddress = kingpin.Flag("listen", "Listen address - ip:port or :port").Default("0.0.0.0:80").Envar("LISTEN").String()
  9. CgroupRoot = kingpin.Flag("cgroupfs-root", "The mount point of the host cgroupfs root").Default("/sys/fs/cgroup").Envar("CGROUPFS_ROOT").String()
  10. DisableLogParsing = kingpin.Flag("disable-log-parsing", "Disable container log parsing").Default("false").Envar("DISABLE_LOG_PARSING").Bool()
  11. DisablePinger = kingpin.Flag("disable-pinger", "Don't ping upstreams").Default("false").Envar("DISABLE_PINGER").Bool()
  12. DisableL7Tracing = kingpin.Flag("disable-l7-tracing", "Disable L7 tracing").Default("false").Envar("DISABLE_L7_TRACING").Bool()
  13. DisableStackTracing = kingpin.Flag("disable-stack-tracing", "Disable stack tracing").Default("false").Envar("DISABLE_STACK_TRACING").Bool()
  14. DisableE2ETracing = kingpin.Flag("disable-e2e-tracing", "Disable e2e tracing").Default("false").Envar("DISABLE_E2E_TRACING").Bool()
  15. ExternalNetworksWhitelist = kingpin.Flag("track-public-network", "Allow track connections to the specified IP networks, all private networks are allowed by default (e.g., Y.Y.Y.Y/mask)").Envar("TRACK_PUBLIC_NETWORK").Strings()
  16. EphemeralPortRange = kingpin.Flag("ephemeral-port-range", "Destination and Listen TCP ports from this range will be skipped").Default("32768-60999").Envar("EPHEMERAL_PORT_RANGE").String()
  17. Provider = kingpin.Flag("provider", "`provider` label for `node_cloud_info` metric").Envar("PROVIDER").String()
  18. Region = kingpin.Flag("region", "`region` label for `node_cloud_info` metric").Envar("REGION").String()
  19. AvailabilityZone = kingpin.Flag("availability-zone", "`availability_zone` label for `node_cloud_info` metric").Envar("AVAILABILITY_ZONE").String()
  20. InstanceType = kingpin.Flag("instance-type", "`instance_type` label for `node_cloud_info` metric").Envar("INSTANCE_TYPE").String()
  21. InstanceLifeCycle = kingpin.Flag("instance-life-cycle", "`instance_life_cycle` label for `node_cloud_info` metric").Envar("INSTANCE_LIFE_CYCLE").String()
  22. LogPerSecond = kingpin.Flag("log-per-second", "The number of logs per second").Default("10.0").Envar("LOG_PER_SECOND").Float64()
  23. LogBurst = kingpin.Flag("log-burst", "The maximum number of tokens that can be consumed in a single call to allow").Default("100").Envar("LOG_BURST").Int()
  24. CollectorEndpoint = kingpin.Flag("collector-endpoint", "A base endpoint URL for metrics, traces, logs, and profiles").Envar("COLLECTOR_ENDPOINT").URL()
  25. ApiKey = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String()
  26. MetricsEndpoint = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL()
  27. TracesEndpoint = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL()
  28. LogsEndpoint = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL()
  29. ProfilesEndpoint = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL()
  30. ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
  31. WalDir = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String()
  32. )
  33. func GetString(fl *string) string {
  34. if fl == nil {
  35. return ""
  36. }
  37. return *fl
  38. }
  39. func init() {
  40. if strings.HasSuffix(os.Args[0], ".test") {
  41. return
  42. }
  43. kingpin.HelpFlag.Short('h').Hidden()
  44. kingpin.Parse()
  45. if *CollectorEndpoint != nil {
  46. u := *CollectorEndpoint
  47. if *MetricsEndpoint == nil {
  48. *MetricsEndpoint = u.JoinPath("/v1/metrics")
  49. }
  50. if *TracesEndpoint == nil {
  51. *TracesEndpoint = u.JoinPath("/v1/traces")
  52. }
  53. if *LogsEndpoint == nil {
  54. *LogsEndpoint = u.JoinPath("/v1/logs")
  55. }
  56. if *ProfilesEndpoint == nil {
  57. *ProfilesEndpoint = u.JoinPath("/v1/profiles")
  58. }
  59. }
  60. if *MetricsEndpoint != nil {
  61. *ListenAddress = "127.0.0.1:10300"
  62. }
  63. }