ot_app_analyst.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package models
  2. const (
  3. //apdex:ms,rate:min
  4. APDEXANDREDSQL = `SELECT AppAlias as app_alias,
  5. countIf(Duration <= ? * 1000 *1000 ) AS satisfied,
  6. countIf(Duration > ? * 1000 * 1000 AND Duration <= ? * 1000 * 1000 ) AS tolerable,
  7. countIf(Duration > ? * 1000 * 1000 ) AS frustrated,
  8. (satisfied + tolerable / 2.0 ) / (satisfied + tolerable + frustrated) AS apdex,
  9. count(*) as totalRequests,
  10. (totalRequests / ?) as rate,
  11. countIf(SpanAttributes['http.status_code'] >= '400' or SpanAttributes['http.response.status_code'] >= '400') / totalRequests as errorRate,
  12. (sum(Duration) / totalRequests / (1000 * 1000)) as latency
  13. FROM otel.otel_traces
  14. WHERE Timestamp >= now() - INTERVAL ? MINUTE AND (ParentSpanId = '')
  15. AND AppAlias IN (?)
  16. GROUP BY AppAlias;
  17. `
  18. SERVICEAPDEXANDREDSQL = `SELECT AppAlias as app_alias,
  19. countIf(Duration <= %d * 1000 *1000 ) AS satisfied,
  20. countIf(Duration > %d * 1000 * 1000 AND Duration <= %d * 1000 * 1000 ) AS tolerable,
  21. countIf(Duration > %d * 1000 * 1000 ) AS frustrated,
  22. (satisfied + tolerable / 2.0 ) / (satisfied + tolerable + frustrated) AS apdex,
  23. count(*) as totalRequests,
  24. (totalRequests / %d) as rate,
  25. countIf(SpanAttributes['http.status_code'] >= '400' or SpanAttributes['http.response.status_code'] >= '400') / totalRequests as errorRate,
  26. (sum(Duration) / totalRequests / (1000 * 1000)) as latency
  27. FROM otel.otel_traces
  28. WHERE Timestamp >= ? AND Timestamp <= ? AND (ParentSpanId = '')
  29. AND AppAlias = ?
  30. AND ServiceName = ?
  31. GROUP BY AppAlias;
  32. `
  33. )
  34. //AND (SpanKind != 'SPAN_KIND_CLIENT')
  35. type ReqApp struct {
  36. AppId int `json:"app_id"`
  37. AppAlias string `uri:"app_alias" json:"app_alias"`
  38. AppName string `json:"app_name"`
  39. PolicyT map[string]interface{} `json:"policy_t"` //私有匹配策略,暂时不提供,后续开启业务个性化配置时开放,当前默认继承ScoreParams中的PolicyT
  40. }
  41. type ScoreParams struct {
  42. ReqAppList []ReqApp `json:"req_applist"`
  43. Interval int32 `json:"interval"` //最小分钟级 1min
  44. PolicyT map[string]interface{} `json:"policy_t"` //公共匹配策略 apdex_a: 1500(ms), apdex_b: 2500(ms) **duration单位为ns
  45. }
  46. type ServiceScoreParams struct {
  47. AppAlias string `uri:"app_alias" json:"app_alias"`
  48. SourceService string `json:"source_service" uri:"source_service" form:"source_service"`
  49. TargetService string `json:"target_service" uri:"target_service" form:"target_service"`
  50. TimeRange
  51. PolicyT map[string]interface{} `json:"policy_t"` //公共匹配策略 apdex_a: 1500(ms), apdex_b: 2500(ms) **duration单位为ns
  52. }
  53. type AppScore struct {
  54. // AppId int `json:"app_id"`
  55. // AppName string `json:"app_name"`
  56. AppAlias string `json:"app_alias" ch:"app_alias"`
  57. Satisfied uint64 `json:"satisfied" ch:"satisfied"` //满意请求
  58. Tolerable uint64 `json:"tolerable" ch:"tolerable"` //可接受请求
  59. Frustrated uint64 `json:"frustrated" ch:"frustrated"` //不满意请求
  60. TotalRequests uint64 `json:"totalRequests" ch:"totalRequests"`
  61. Apdex float64 `json:"apdex" ch:"apdex"`
  62. Rate float64 `json:"rate" ch:"rate"`
  63. ErrorRate float64 `json:"errorRate" ch:"errorRate"`
  64. Latency float64 `json:"latency" ch:"latency"`
  65. }
  66. type AppScoreList struct {
  67. Scores []AppScore `json:"scores"`
  68. }
  69. type AppInterval struct {
  70. AppAlias string `uri:"app_alias" json:"app_alias"`
  71. ServiceName string `uri:"service_name" form:"service_name" json:"service_name"`
  72. TimeRange
  73. AppPercentileRange
  74. }
  75. type AppServiceInterval struct {
  76. AppAlias string `uri:"app_alias" json:"app_alias"`
  77. SourceService string `uri:"source_service" json:"source_service" form:"source_service"`
  78. TargetService string `uri:"target_service" json:"target_service" form:"target_service"`
  79. TimeRange
  80. AppPercentileRange
  81. }
  82. // type TraceDuration struct {
  83. // Ts uint32 `json:"ts" ch:"ts"`
  84. // Duration int64 `json:"duration" ch:"Duration"`
  85. // HttpCode int32 `json:"http_code" ch:"HttpCode"`
  86. // // TraceId string `json:"traceId" ch:"TraceId"`
  87. // }
  88. type AppLatencyByInterval struct {
  89. Success []CoordinatePoint `json:"success"`
  90. Failed []CoordinatePoint `json:"failed"`
  91. }