类 MetricsUtils

java.lang.Object
io.github.chatpass.dify.util.MetricsUtils

public final class MetricsUtils extends Object
性能监控工具类
作者:
chat-pass
  • 方法详细资料

    • incrementRequestCount

      public static void incrementRequestCount(String apiName)
      增加请求计数
      参数:
      apiName - API名称
    • incrementErrorCount

      public static void incrementErrorCount(String apiName)
      增加错误计数
      参数:
      apiName - API名称
    • recordResponseTime

      public static void recordResponseTime(String apiName, long responseTimeMs)
      记录响应时间
      参数:
      apiName - API名称
      responseTimeMs - 响应时间(毫秒)
    • getRequestCount

      public static long getRequestCount(String apiName)
      获取请求计数
      参数:
      apiName - API名称
      返回:
      请求计数
    • getErrorCount

      public static long getErrorCount(String apiName)
      获取错误计数
      参数:
      apiName - API名称
      返回:
      错误计数
    • getAverageResponseTime

      public static double getAverageResponseTime(String apiName)
      获取平均响应时间
      参数:
      apiName - API名称
      返回:
      平均响应时间(毫秒)
    • getMaxResponseTime

      public static long getMaxResponseTime(String apiName)
      获取最大响应时间
      参数:
      apiName - API名称
      返回:
      最大响应时间(毫秒)
    • getErrorRate

      public static double getErrorRate(String apiName)
      获取错误率
      参数:
      apiName - API名称
      返回:
      错误率(0-1之间)
    • printMetrics

      public static void printMetrics()
      打印所有API的性能统计
    • clearMetrics

      public static void clearMetrics()
      清空所有统计数据