monitor.go 1.3 KB

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