Beispiel #1
0
 /**
  * 解析数据
  *
  * @param content
  * @return
  */
 public static MonitorRecord parseLineData(String content) {
   try {
     // 解析文件:# 时间 | handlername | hostname | totalNum | sucNum | failNum
     // | avgCost | maxCost | minCost
     if (StringUtils.isNotBlank(content) && content.indexOf("#") == -1) {
       String[] strArray = content.split("\\|");
       if (strArray.length == 9) {
         MonitorRecord item = new MonitorRecord();
         item.setMonitorTime(new Date(Long.valueOf(strArray[0].trim())));
         item.setHandlerName(strArray[1].trim());
         item.setHostName(strArray[2].trim());
         item.setTotalNum(Integer.valueOf(strArray[3].trim()));
         item.setSucNum(Integer.valueOf(strArray[4].trim()));
         item.setFailNum(Integer.valueOf(strArray[5].trim()));
         item.setAvgCost(Long.valueOf(strArray[6].trim()));
         item.setMaxCost(Long.valueOf(strArray[7].trim()));
         item.setMinCost(Long.valueOf(strArray[8].trim()));
         return item;
       }
     }
   } catch (Exception e) {
     logger.error("parseLineData exception,data:" + content, e);
   }
   return null;
 }
Beispiel #2
0
 /**
  * push data to origin dic :ORIGIN_DIR/DATA_DIR<br>
  * 注意001,此处DATA_DIR线上应该为ORIGIN_DIR,守护线程自动同步两个目录下文件<br>
  * 写监控数据需要同步,保证线程安全
  *
  * @param originData
  */
 public static synchronized void dealReceiveData(String originData) {
   MonitorRecord item = parseLineData(originData);
   if (item != null) {
     initZipThread();
     File dirA =
         new File(
             DATA_DIR,
             getDateFormat(FormatPath_yyyyMM).format(item.getMonitorTime())); // ../201509
     if (!dirA.exists()) {
       dirA.mkdirs();
       // 每个月启动zip压缩一次,异步实现
       zipTriggerQueue.offer(item.getMonitorTime());
     }
     File dirB = new File(dirA, FormatPath_dd.format(item.getMonitorTime())); // ../201509/01
     if (!dirB.exists()) {
       dirB.mkdirs();
     }
     String filePath = item.getHandlerName().concat("_").concat(item.getHostName()).concat(".txt");
     File file = new File(dirB, filePath); // ../201509/01/smsGeneralHandler_tkyuan.local.txt
     if (!file.exists()) {
       try {
         file.createNewFile();
       } catch (IOException e) {
         logger.error("create file exception,path=" + filePath, e);
       }
     }
     FileOutputStream fos = null;
     try {
       fos = new FileOutputStream(file, true);
       fos.write(("\r\n" + originData).getBytes("utf-8"));
       if (logger.isInfoEnabled()) {
         logger.info("deal receive data success:{}", originData);
       }
     } catch (FileNotFoundException e) {
       logger.error("deal receive data FileNotFoundException,originData=" + originData, e);
     } catch (IOException e) {
       logger.error("deal receive data IOException,originData=" + originData, e);
     } finally {
       if (fos != null) {
         try {
           fos.close();
         } catch (IOException e) {
         }
       }
     }
   }
 }