类 MetricWriter

java.lang.Object
com.alibaba.csp.sentinel.node.metric.MetricWriter

public class MetricWriter extends Object
This class is responsible for writing MetricNode to disk:
  1. metric with the same second should write to the same file;
  2. single file size must be controlled;
  3. file name is like: ${appName}-metrics.log.pid${pid}.yyyy-MM-dd.[number]
  4. metric of different day should in different file;
  5. every metric file is accompanied with an index file, which file name is ${metricFileName}.idx
作者:
Carpenter Lee
  • 字段详细资料

    • METRIC_BASE_DIR

      public static final String METRIC_BASE_DIR
    • METRIC_FILE

      public static final String METRIC_FILE
      Note: MetricWriter.MetricFileNameComparator's implementation relies on the metric file name, so we should be careful when changing the metric file name.
      另请参阅:
    • METRIC_FILE_INDEX_SUFFIX

      public static final String METRIC_FILE_INDEX_SUFFIX
      另请参阅:
    • METRIC_FILE_NAME_CMP

      public static final Comparator<String> METRIC_FILE_NAME_CMP
  • 构造器详细资料

    • MetricWriter

      public MetricWriter(long singleFileSize)
    • MetricWriter

      public MetricWriter(long singleFileSize, int totalFileCount)
  • 方法详细资料

    • write

      public void write(long time, List<MetricNode> nodes) throws Exception
      如果传入了time,就认为nodes中所有的时间时间戳都是time.
      参数:
      time -
      nodes -
      抛出:
      Exception
    • close

      public void close() throws Exception
      抛出:
      Exception
    • fileNameMatches

      public static boolean fileNameMatches(String fileName, String baseFileName)
      Test whether fileName matches baseFileName. fileName matches baseFileName when
       fileName = baseFileName + ".yyyy-MM-dd.number"
       
      参数:
      fileName - file name
      baseFileName - base file name.
      返回:
      if fileName matches baseFileName return true, else return false.
    • formMetricFileName

      public static String formMetricFileName(String appName, int pid)
      Form metric file name use the specific appName and pid. Note that only form the file name, not include path. Note: MetricWriter.MetricFileNameComparator's implementation relays on the metric file name, we should be careful when changing the metric file name.
      参数:
      appName -
      pid -
      返回:
      metric file name.
    • formIndexFileName

      public static String formIndexFileName(String metricFileName)
      Form index file name of the metricFileName
      参数:
      metricFileName -
      返回:
      the index file name of the metricFileName