pprof.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/http"
  6. "net/url"
  7. "go-common/app/admin/main/apm/model/pprof"
  8. "go-common/library/conf/env"
  9. "go-common/library/log"
  10. )
  11. // Instances get instances
  12. func (d *Dao) Instances(c context.Context, appName string) (ins *pprof.Ins, err error) {
  13. var (
  14. req *http.Request
  15. uri = d.c.Host.SVENCo + "/x/admin/apm/noauth/discovery/fetch"
  16. ret = &pprof.Response{}
  17. params = url.Values{}
  18. )
  19. params.Add("zone", env.Zone)
  20. params.Add("env", env.DeployEnv)
  21. params.Add("region", env.Region)
  22. params.Add("appid", appName)
  23. params.Add("status", "3")
  24. if req, err = d.client.NewRequest(http.MethodGet, uri, "", params); err != nil {
  25. log.Error("d.Instances http.NewRequest error(%v)", err)
  26. return
  27. }
  28. if err = d.client.Do(c, req, ret); err != nil {
  29. log.Error("d.Instances client Do error(%v)", err)
  30. return
  31. }
  32. if ret.Code != 0 {
  33. err = fmt.Errorf("%s params(%s) response return_code(%d)", uri, params.Encode(), ret.Code)
  34. log.Error("d.Instance error(%v)", err)
  35. return
  36. }
  37. ins = ret.Data
  38. return
  39. }