flags.go 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
  33. 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()
  34. )
  35. func GetString(fl *string) string {
  36. if fl == nil {
  37. return ""
  38. }
  39. return *fl
  40. }
  41. func init() {
  42. if strings.HasSuffix(os.Args[0], ".test") {
  43. return
  44. }
  45. kingpin.HelpFlag.Short('h').Hidden()
  46. kingpin.Parse()
  47. if *CollectorEndpoint != nil {
  48. u := *CollectorEndpoint
  49. if *MetricsEndpoint == nil {
  50. *MetricsEndpoint = u.JoinPath("/v1/metrics")
  51. }
  52. if *TracesEndpoint == nil {
  53. *TracesEndpoint = u.JoinPath("/v1/traces")
  54. }
  55. if *LogsEndpoint == nil {
  56. *LogsEndpoint = u.JoinPath("/v1/logs")
  57. }
  58. if *ProfilesEndpoint == nil {
  59. *ProfilesEndpoint = u.JoinPath("/v1/profiles")
  60. }
  61. }
  62. if *MetricsEndpoint != nil {
  63. *ListenAddress = "127.0.0.1:10300"
  64. }
  65. }