perf_metrics.go 832 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package controller
  2. import (
  3. "net/http"
  4. "strconv"
  5. perfmetrics "github.com/QuantumNous/new-api/pkg/perf_metrics"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func GetPerfMetrics(c *gin.Context) {
  9. modelName := c.Query("model")
  10. if modelName == "" {
  11. c.JSON(http.StatusBadRequest, gin.H{
  12. "success": false,
  13. "message": "model is required",
  14. })
  15. return
  16. }
  17. hours := 24
  18. if rawHours := c.Query("hours"); rawHours != "" {
  19. if parsed, err := strconv.Atoi(rawHours); err == nil {
  20. hours = parsed
  21. }
  22. }
  23. result, err := perfmetrics.Query(perfmetrics.QueryParams{
  24. Model: modelName,
  25. Group: c.Query("group"),
  26. Hours: hours,
  27. })
  28. if err != nil {
  29. c.JSON(http.StatusInternalServerError, gin.H{
  30. "success": false,
  31. "message": err.Error(),
  32. })
  33. return
  34. }
  35. c.JSON(http.StatusOK, gin.H{
  36. "success": true,
  37. "data": result,
  38. })
  39. }