| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.swing.text.DateFormatter; |
| | | import java.io.IOException; |
| | | import java.net.InetAddress; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | |
| | | |
| | | private static final String DICT_TYPE = "platform_online"; |
| | | |
| | | private static final ExecutorService executorService = new ThreadPoolExecutor(8, |
| | | 24, |
| | | private static final ExecutorService executorService = new ThreadPoolExecutor(16, |
| | | 64, |
| | | 5000, |
| | | TimeUnit.SECONDS, |
| | | new ArrayBlockingQueue<>(10), |
| | | new ArrayBlockingQueue<>(1000), |
| | | new ThreadPoolExecutor.CallerRunsPolicy() |
| | | ); |
| | | |
| | |
| | | for (int tryTimes = 1; tryTimes < 3; tryTimes++) { |
| | | // 三秒未ping通重试一次,如果不行才扣分 |
| | | reachable = InetAddress.getByName(platform.getPlatformIP()).isReachable(3000); |
| | | if (! reachable && tryTimes == 0) { |
| | | continue; |
| | | } |
| | | if (! reachable) { |
| | | // 如果ping不通,离线时长加5秒 |
| | | redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + platform.getPlatformIP(), 5); |
| | | log.warn(platform.getPlatformName() + "平台未ping通"); |
| | | if (reachable) { |
| | | break; |
| | | } |
| | | } |
| | | if (!reachable) { |
| | | // 如果ping不通,离线时长加5秒 |
| | | LocalDateTime localDateTime = LocalDateTime.now(); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String todayTime = localDateTime.format(dateTimeFormatter); |
| | | //每次redis累增5s |
| | | redisTemplate.opsForValue().increment(REDIS_KEY_PREFIX + todayTime + platform.getPlatformIP(), 5); |
| | | log.warn(platform.getPlatformName() + "平台未ping通"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("检查平台连通性时发生错误", e); |
| | | log.error("检查平台连通性时发生d错误", e); |
| | | } |
| | | }); |
| | | executorService.shutdown(); |
| | | } |
| | | } |
| | | |
| | |
| | | .list(); |
| | | // 将java.util.Date转换为java.sql.Date |
| | | java.sql.Date sqlDate = new java.sql.Date(new Date().getTime()); |
| | | |
| | | LocalDateTime localDateTime = LocalDateTime.now(); |
| | | DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String todayTime = localDateTime.format(dateTimeFormatter); |
| | | for (Platform platform : platformList) { |
| | | Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + platform.getPlatformIP()); |
| | | Object outLineTime = redisTemplate.opsForValue().get(REDIS_KEY_PREFIX + todayTime + platform.getPlatformIP()); |
| | | Integer outlineTimeSed = Objects.isNull(outLineTime) ? 0 : (Integer) outLineTime; |
| | | PlatformOnline one = new LambdaQueryChainWrapper<>(platformOnlineService.getBaseMapper()) |
| | | .eq(PlatformOnline::getPlatformIp, platform.getPlatformIP()) |
| | | .eq(PlatformOnline::getPlatformId, platform.getId()) |
| | | .eq(PlatformOnline::getCreateDate, sqlDate) |
| | | .one(); |
| | | if (Objects.isNull(one)) { |
| | | one = new PlatformOnline(); |
| | | one.setPlatformIp(platform.getPlatformIP()); |
| | | one.setPlatformName(platform.getPlatformName()); |
| | | one.setPlatformId(platform.getId()); |
| | | one.setCreateDate(sqlDate); |
| | | one.setTodayOutlineSed(outlineTimeSed); |
| | | } else { |
| | | one.setTodayOutlineSed(one.getTodayOutlineSed() + outlineTimeSed); |
| | | } |
| | | one.setPlatformIp(platform.getPlatformIP()); |
| | | one.setPlatformName(platform.getPlatformName()); |
| | | one.setPlatformId(platform.getId()); |
| | | one.setCreateDate(sqlDate); |
| | | |
| | | platformOnlineService.saveOrUpdate(one); |