flags.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ExternalNetworksWhitelist = kingpin.
  14. 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)").
  15. Envar("TRACK_PUBLIC_NETWORK").
  16. Default("0.0.0.0/0").
  17. Strings()
  18. 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()
  19. Provider = kingpin.Flag("provider", "`provider` label for `node_cloud_info` metric").Envar("PROVIDER").String()
  20. Region = kingpin.Flag("region", "`region` label for `node_cloud_info` metric").Envar("REGION").String()
  21. AvailabilityZone = kingpin.Flag("availability-zone", "`availability_zone` label for `node_cloud_info` metric").Envar("AVAILABILITY_ZONE").String()
  22. InstanceType = kingpin.Flag("instance-type", "`instance_type` label for `node_cloud_info` metric").Envar("INSTANCE_TYPE").String()
  23. InstanceLifeCycle = kingpin.Flag("instance-life-cycle", "`instance_life_cycle` label for `node_cloud_info` metric").Envar("INSTANCE_LIFE_CYCLE").String()
  24. LogPerSecond = kingpin.Flag("log-per-second", "The number of logs per second").Default("10.0").Envar("LOG_PER_SECOND").Float64()
  25. 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()
  26. CollectorEndpoint = kingpin.Flag("collector-endpoint", "A base endpoint URL for metrics, traces, logs, and profiles").Envar("COLLECTOR_ENDPOINT").URL()
  27. ApiKey = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String()
  28. MetricsEndpoint = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL()
  29. TracesEndpoint = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL()
  30. LogsEndpoint = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL()
  31. ProfilesEndpoint = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL()
  32. InsecureSkipVerify = kingpin.Flag("insecure-skip-verify", "whether to skip verifying the certificate or not").Envar("INSECURE_SKIP_VERIFY").Default("false").Bool()
  33. ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
  34. 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()
  35. )
  36. func GetString(fl *string) string {
  37. if fl == nil {
  38. return ""
  39. }
  40. return *fl
  41. }
  42. func init() {
  43. if strings.HasSuffix(os.Args[0], ".test") {
  44. return
  45. }
  46. kingpin.HelpFlag.Short('h').Hidden()
  47. kingpin.Parse()
  48. if *CollectorEndpoint != nil {
  49. u := *CollectorEndpoint
  50. if *MetricsEndpoint == nil {
  51. *MetricsEndpoint = u.JoinPath("/v1/metrics")
  52. }
  53. if *TracesEndpoint == nil {
  54. *TracesEndpoint = u.JoinPath("/v1/traces")
  55. }
  56. if *LogsEndpoint == nil {
  57. *LogsEndpoint = u.JoinPath("/v1/logs")
  58. }
  59. if *ProfilesEndpoint == nil {
  60. *ProfilesEndpoint = u.JoinPath("/v1/profiles")
  61. }
  62. }
  63. if *MetricsEndpoint != nil {
  64. *ListenAddress = "127.0.0.1:10300"
  65. }
  66. }