1
0

monitor.go 1.4 KB

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