monitor.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package features
  2. import (
  3. "fmt"
  4. "strings"
  5. "time"
  6. "github.com/fatedier/frp/pkg/util/log"
  7. "github.com/fatedier/frp/test/e2e/framework"
  8. "github.com/fatedier/frp/test/e2e/framework/consts"
  9. "github.com/fatedier/frp/test/e2e/pkg/request"
  10. . "github.com/onsi/ginkgo"
  11. )
  12. var _ = Describe("[Feature: Monitor]", func() {
  13. f := framework.NewDefaultFramework()
  14. It("Prometheus metrics", func() {
  15. dashboardPort := f.AllocPort()
  16. serverConf := consts.DefaultServerConfig + fmt.Sprintf(`
  17. enable_prometheus = true
  18. dashboard_addr = 0.0.0.0
  19. dashboard_port = %d
  20. `, dashboardPort)
  21. clientConf := consts.DefaultClientConfig
  22. remotePort := f.AllocPort()
  23. clientConf += fmt.Sprintf(`
  24. [tcp]
  25. type = tcp
  26. local_port = {{ .%s }}
  27. remote_port = %d
  28. `, framework.TCPEchoServerPort, remotePort)
  29. f.RunProcesses([]string{serverConf}, []string{clientConf})
  30. framework.NewRequestExpect(f).Port(remotePort).Ensure()
  31. time.Sleep(500 * time.Millisecond)
  32. framework.NewRequestExpect(f).RequestModify(func(r *request.Request) {
  33. r.HTTP().Port(dashboardPort).HTTPPath("/metrics")
  34. }).Ensure(func(resp *request.Response) bool {
  35. log.Trace("prometheus metrics response: \n%s", resp.Content)
  36. if resp.Code != 200 {
  37. return false
  38. }
  39. if !strings.Contains(string(resp.Content), "traffic_in") {
  40. return false
  41. }
  42. return true
  43. })
  44. })
  45. })