org.apache.servicecomb.foundation.common.net.NetUtils Java Examples

The following examples show how to use org.apache.servicecomb.foundation.common.net.NetUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VertxRestTransport.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canInit() {
  setListenAddressWithoutSchema(TransportConfig.getAddress());

  URIEndpointObject ep = (URIEndpointObject) getEndpoint().getAddress();
  if (ep == null) {
    return true;
  }

  if (!NetUtils.canTcpListen(ep.getSocketAddress().getAddress(), ep.getPort())) {
    LOGGER.warn(
        "Can not start VertxRestTransport, the port:{} may have been occupied. You can ignore this message if you are using a web container like tomcat.",
        ep.getPort());
    return false;
  }

  return true;
}
 
Example #2
Source File: CloudEyeFilePublisher.java    From servicecomb-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void init(GlobalRegistry globalRegistry, EventBus eventBus, MetricsBootstrapConfig config) {
  eventBus.register(this);

  Microservice microservice = RegistryUtils.getMicroservice();
  filePrefix = microservice.getAppId() + "." + microservice.getServiceName();

  hostName = NetUtils.getHostName();
  if (StringUtils.isEmpty(hostName)) {
    hostName = NetUtils.getHostAddress();
  }

  System.setProperty("cloudEye.logDir",
      DynamicPropertyFactory
          .getInstance()
          .getStringProperty("cloudEye.logDir", "logs")
          .get());
}
 
Example #3
Source File: ServletUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static boolean canPublishEndpoint(String listenAddress) {
  if (StringUtils.isEmpty(listenAddress)) {
    LOGGER.info("listenAddress is null, can not publish.");
    return false;
  }

  IpPort ipPort = NetUtils.parseIpPortFromURI("http://" + listenAddress);
  if (ipPort == null) {
    LOGGER.info("invalid listenAddress {}, can not publish, format should be ip:port.", listenAddress);
    return false;
  }

  if (NetUtils.canTcpListen(ipPort.getSocketAddress().getAddress(), ipPort.getPort())) {
    LOGGER.info("{} is not listened, can not publish.", ipPort.getSocketAddress());
    return false;
  }

  return true;
}
 
Example #4
Source File: TestRegistry.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegistryUtilGetHostName(@Mocked InetAddress ethAddress) {
  new Expectations(NetUtils.class) {
    {
      NetUtils.getHostName();
      result = "testHostName";
    }
  };
  String host = RegistrationManager.getPublishHostName();
  Assert.assertEquals("testHostName", host);

  inMemoryConfig.addProperty(RegistrationManager.PUBLISH_ADDRESS, "127.0.0.1");
  Assert.assertEquals("127.0.0.1", RegistrationManager.getPublishHostName());

  new Expectations(DynamicPropertyFactory.getInstance()) {
    {
      ethAddress.getHostName();
      result = "testHostName";
      NetUtils.ensureGetInterfaceAddress("eth100");
      result = ethAddress;
    }
  };
  inMemoryConfig.addProperty(RegistrationManager.PUBLISH_ADDRESS, "{eth100}");
  Assert.assertEquals("testHostName", RegistrationManager.getPublishHostName());
}
 
Example #5
Source File: ServiceRegistryConfigBuilder.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public ArrayList<IpPort> getIpPort() {
  List<String> uriList = Objects
      .requireNonNull(Deployment.getSystemBootStrapInfo(DeploymentProvider.SYSTEM_KEY_SERVICE_CENTER),
          "no sc address found!")
      .getAccessURL();
  ArrayList<IpPort> ipPortList = new ArrayList<>();
  uriList.forEach(anUriList -> {
    try {
      URI uri = new URI(anUriList.trim());
      this.ssl = "https".equals(uri.getScheme());
      ipPortList.add(NetUtils.parseIpPort(uri));
    } catch (Exception e) {
      LOGGER.error("servicecomb.service.registry.address invalid : {}", anUriList, e);
    }
  });
  return ipPortList;
}
 
Example #6
Source File: ServiceRegistryConfigCustomizer.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public ServiceRegistryConfigCustomizer addressListFromConfiguration(String configuration) {
  String address = DynamicPropertyFactory.getInstance()
      .getStringProperty(configuration, null)
      .get();
  if (address == null) {
    throw new IllegalStateException("service center address is required.");
  }
  String[] urls = address.split(",");
  List<String> uriList = Arrays.asList(urls);
  ArrayList<IpPort> ipPortList = new ArrayList<>();
  uriList.forEach(anUriList -> {
    try {
      URI uri = new URI(anUriList.trim());
      if ("https".equals(uri.getScheme())) {
        this.original.setSsl(true);
      }
      ipPortList.add(NetUtils.parseIpPort(uri));
    } catch (Exception e) {
      throw new IllegalStateException("service center address is required.", e);
    }
  });
  this.original.setIpPort(ipPortList);

  return this;
}
 
Example #7
Source File: RegistrationManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * In the case that listening address configured as 0.0.0.0, the publish address will be determined
 * by the query result for the net interfaces.
 *
 * @return the publish address, or {@code null} if the param {@code address} is null.
 */
public static String getPublishAddress(String schema, String address) {
  if (address == null) {
    return address;
  }

  try {
    URI originalURI = new URI(schema + "://" + address);
    IpPort ipPort = NetUtils.parseIpPort(originalURI);
    if (ipPort == null) {
      LOGGER.warn("address {} not valid.", address);
      return null;
    }

    IpPort publishIpPort = genPublishIpPort(schema, ipPort);
    URIBuilder builder = new URIBuilder(originalURI);
    return builder.setHost(publishIpPort.getHostOrIp()).setPort(publishIpPort.getPort()).build().toString();
  } catch (URISyntaxException e) {
    LOGGER.warn("address {} not valid.", address);
    return null;
  }
}
 
Example #8
Source File: RegistrationManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static String getPublishHostName() {
  String publicAddressSetting =
      DynamicPropertyFactory.getInstance().getStringProperty(PUBLISH_ADDRESS, "").get();
  publicAddressSetting = publicAddressSetting.trim();
  if (publicAddressSetting.isEmpty()) {
    return NetUtils.getHostName();
  }

  if (publicAddressSetting.startsWith("{") && publicAddressSetting.endsWith("}")) {
    return NetUtils
        .ensureGetInterfaceAddress(publicAddressSetting.substring(1, publicAddressSetting.length() - 1))
        .getHostName();
  }

  return publicAddressSetting;
}
 
Example #9
Source File: RegistrationManager.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
public static String getPublishAddress() {
  String publicAddressSetting =
      DynamicPropertyFactory.getInstance().getStringProperty(PUBLISH_ADDRESS, "").get();
  publicAddressSetting = publicAddressSetting.trim();
  if (publicAddressSetting.isEmpty()) {
    return NetUtils.getHostAddress();
  }

  // placeholder is network interface name
  if (publicAddressSetting.startsWith("{") && publicAddressSetting.endsWith("}")) {
    return NetUtils
        .ensureGetInterfaceAddress(publicAddressSetting.substring(1, publicAddressSetting.length() - 1))
        .getHostAddress();
  }

  return publicAddressSetting;
}
 
Example #10
Source File: AbstractTransport.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
protected void setListenAddressWithoutSchema(String addressWithoutSchema,
    Map<String, String> pairs) {
  addressWithoutSchema = genAddressWithoutSchema(addressWithoutSchema, pairs);

  this.endpoint = new Endpoint(this, NetUtils.getRealListenAddress(getName(), addressWithoutSchema));
  if (this.endpoint.getEndpoint() != null) {
    this.publishEndpoint = new Endpoint(this, RegistrationManager.getPublishAddress(getName(),
        addressWithoutSchema));
  } else {
    this.publishEndpoint = null;
  }
}
 
Example #11
Source File: RegistrationManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private static IpPort genPublishIpPort(String schema, IpPort ipPort) {
  String publicAddressSetting = DynamicPropertyFactory.getInstance()
      .getStringProperty(PUBLISH_ADDRESS, "")
      .get();
  publicAddressSetting = publicAddressSetting.trim();

  if (publicAddressSetting.isEmpty()) {
    InetSocketAddress socketAddress = ipPort.getSocketAddress();
    if (socketAddress.getAddress().isAnyLocalAddress()) {
      String host = NetUtils.getHostAddress();
      LOGGER.warn("address {}, auto select a host address to publish {}:{}, maybe not the correct one",
          socketAddress,
          host,
          socketAddress.getPort());
      return new IpPort(host, ipPort.getPort());
    }

    return ipPort;
  }

  if (publicAddressSetting.startsWith("{") && publicAddressSetting.endsWith("}")) {
    publicAddressSetting = NetUtils
        .ensureGetInterfaceAddress(
            publicAddressSetting.substring(1, publicAddressSetting.length() - 1))
        .getHostAddress();
  }

  String publishPortKey = PUBLISH_PORT.replace("{transport_name}", schema);
  int publishPortSetting = DynamicPropertyFactory.getInstance()
      .getIntProperty(publishPortKey, 0)
      .get();
  int publishPort = publishPortSetting == 0 ? ipPort.getPort() : publishPortSetting;
  return new IpPort(publicAddressSetting, publishPort);
}
 
Example #12
Source File: SimpleMicroserviceInstancePing.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean ping(MicroserviceInstance instance) {
  if (instance.getEndpoints() != null && instance.getEndpoints().size() > 0) {
    IpPort ipPort = NetUtils.parseIpPortFromURI(instance.getEndpoints().get(0));
    try (Socket s = new Socket()) {
      s.connect(new InetSocketAddress(ipPort.getHostOrIp(), ipPort.getPort()), 3000);
      return true;
    } catch (IOException e) {
      // ignore this error
    }
  }
  return false;
}
 
Example #13
Source File: ConfigCenterClient.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void refreshMembers(MemberDiscovery memberDiscovery) {
  if (CONFIG_CENTER_CONFIG.getAutoDiscoveryEnabled()) {
    String configCenter = memberDiscovery.getConfigServer();
    IpPort ipPort = NetUtils.parseIpPortFromURI(configCenter);
    HttpClients.getClient(ConfigCenterHttpClientOptionsSPI.CLIENT_NAME).runOnContext(client -> {
      @SuppressWarnings("deprecation")
      HttpClientRequest request =
          client.get(ipPort.getPort(), ipPort.getHostOrIp(), uriConst.MEMBERS, rsp -> {
            if (rsp.statusCode() == HttpResponseStatus.OK.code()) {
              rsp.bodyHandler(buf -> {
                memberDiscovery.refreshMembers(buf.toJsonObject());
              });
            }
          });
      SignRequest signReq = createSignRequest(request.method().toString(),
          configCenter + uriConst.MEMBERS,
          new HashMap<>(),
          null);
      if (ConfigCenterConfig.INSTANCE.getToken() != null) {
        request.headers().add("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
      }
      authHeaderProviders.forEach(provider -> request.headers()
          .addAll(provider.getSignAuthHeaders(signReq)));
      request.exceptionHandler(e -> {
        LOGGER.error("Fetch member from {} failed. Error message is [{}].", configCenter, e.getMessage());
        logIfDnsFailed(e);
      });
      request.end();
    });
  }
}
 
Example #14
Source File: DefaultLogPublisher.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void printNetLog(StringBuilder sb, MeasurementNode osNode) {
  MeasurementNode netNode = osNode.findChild(OsMeter.OS_TYPE_NET);
  if (netNode == null || netNode.getMeasurements().isEmpty()) {
    return;
  }

  appendLine(sb, "  net:");
  appendLine(sb, "    send(Bps)    recv(Bps)    send(pps)    recv(pps)    interface");

  StringBuilder tmpSb = new StringBuilder();
  for (MeasurementNode interfaceNode : netNode.getChildren().values()) {
    double sendRate = interfaceNode.findChild(NetMeter.TAG_SEND.value()).summary();
    double sendPacketsRate = interfaceNode.findChild(NetMeter.TAG_PACKETS_SEND.value()).summary();
    double receiveRate = interfaceNode.findChild(NetMeter.TAG_RECEIVE.value()).summary();
    double receivePacketsRate = interfaceNode.findChild(NetMeter.TAG_PACKETS_RECEIVE.value()).summary();
    if (sendRate == 0 && receiveRate == 0 && receivePacketsRate == 0 && sendPacketsRate == 0) {
      continue;
    }
    appendLine(tmpSb, "    %-12s %-12s %-12s %-12s %s",
        NetUtils.humanReadableBytes((long) sendRate),
        NetUtils.humanReadableBytes((long) receiveRate),
        NetUtils.humanReadableBytes((long) sendPacketsRate),
        NetUtils.humanReadableBytes((long) receivePacketsRate),
        interfaceNode.getName());
  }
  if (tmpSb.length() != 0) {
    sb.append(tmpSb.toString());
  }
}
 
Example #15
Source File: RegistryHandler.java    From spring-cloud-huawei with Apache License 2.0 5 votes vote down vote up
private static MicroserviceInstance buildInstance(String serviceID,
    ServiceCombDiscoveryProperties serviceCombDiscoveryProperties,
    TagsProperties tagsProperties) {
  MicroserviceInstance microserviceInstance = new MicroserviceInstance();
  microserviceInstance.setServiceId(serviceID);
  microserviceInstance.setHostName(NetUtil.getLocalHost());
  if (null != serviceCombDiscoveryProperties.getDatacenter()) {
    microserviceInstance.setDataCenterInfo(serviceCombDiscoveryProperties.getDatacenter());
  }
  List<String> endPoints = new ArrayList<>();
  String address = NetUtils.getHostAddress();
  endPoints.add("rest://" + address + ":" + serviceCombDiscoveryProperties.getPort());
  microserviceInstance.setEndpoints(endPoints);
  HealthCheck healthCheck = new HealthCheck();
  healthCheck.setMode(HealthCheckMode.PLATFORM);
  healthCheck.setInterval(serviceCombDiscoveryProperties.getHealthCheckInterval());
  healthCheck.setTimes(3);
  microserviceInstance.setHealthCheck(healthCheck);
  String currTime = String.valueOf(System.currentTimeMillis());
  microserviceInstance.setTimestamp(currTime);
  microserviceInstance.setModTimestamp(currTime);
  microserviceInstance.setVersion(serviceCombDiscoveryProperties.getVersion());
  Map<String, String> properties = new HashMap<>();
  if (tagsProperties.getTag() != null) {
    properties.putAll(tagsProperties.getTag());
  }
  properties.putAll(genCasProperties());
  microserviceInstance.setProperties(properties);
  return microserviceInstance;
}
 
Example #16
Source File: KieClient.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
void refreshConfig(CountDownLatch latch) {
  String path = "/v1/"
      + KieConfig.INSTANCE.getDomainName()
      + "/kie/kv?label=app:"
      + KieConfig.INSTANCE.getAppName()
      + "&revision=" + revision;
  long timeout;
  if (enableLongPolling && !IS_FIRST_PULL.get()) {
    path += "&wait=" + LONG_POLLING_WAIT_TIME_IN_SECONDS + "s";
    timeout = LONG_POLLING_REQUEST_TIME_OUT_IN_MILLIS;
  } else {
    IS_FIRST_PULL.compareAndSet(true, false);
    timeout = PULL_REQUEST_TIME_OUT_IN_MILLIS;
  }
  String finalPath = path;
  HttpClients.getClient(ConfigKieHttpClientOptionsSPI.CLIENT_NAME).runOnContext(client -> {
    IpPort ipPort = NetUtils.parseIpPortFromURI(serviceUri);
    HttpClientRequest request = client
        .get(ipPort.getPort(), ipPort.getHostOrIp(), finalPath, rsp -> {
          if (rsp.statusCode() == HttpStatus.SC_OK) {
            revision = rsp.getHeader("X-Kie-Revision");
            rsp.bodyHandler(buf -> {
              try {
                Map<String, Object> resMap = KieUtil.getConfigByLabel(JsonUtils.OBJ_MAPPER
                    .readValue(buf.toString(), KVResponse.class));
                KieWatcher.INSTANCE.refreshConfigItems(resMap);
                EventManager.post(new ConnSuccEvent());
              } catch (IOException e) {
                EventManager.post(new ConnFailEvent(
                    "config update result parse fail " + e.getMessage()));
                LOGGER.error("Config update from {} failed. Error message is [{}].",
                    serviceUri,
                    e.getMessage());
              }
              latch.countDown();
            });
          } else if (rsp.statusCode() == HttpStatus.SC_NOT_MODIFIED) {
            EventManager.post(new ConnSuccEvent());
            latch.countDown();
          } else {
            EventManager.post(new ConnFailEvent("fetch config fail"));
            LOGGER.error("Config update from {} failed. Error code is {}, error message is [{}].",
                serviceUri,
                rsp.statusCode(),
                rsp.statusMessage());
            latch.countDown();
          }
        }).setTimeout(timeout);

    request.exceptionHandler(e -> {
      EventManager.post(new ConnFailEvent("fetch config fail"));
      LOGGER.error("Config update from {} failed. Error message is [{}].",
          serviceUri,
          e.getMessage());
      latch.countDown();
    });
    request.end();
  });
}
 
Example #17
Source File: ConfigCenterClient.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
public void doWatch(String configCenter)
    throws UnsupportedEncodingException, InterruptedException {
  CountDownLatch waiter = new CountDownLatch(1);
  IpPort ipPort = NetUtils.parseIpPortFromURI(configCenter);
  String url = uriConst.REFRESH_ITEMS + "?dimensionsInfo="
      + StringUtils.deleteWhitespace(URLEncoder.encode(serviceName, "UTF-8"));
  Map<String, String> headers = new HashMap<>();
  headers.put("x-domain-name", tenantName);
  if (ConfigCenterConfig.INSTANCE.getToken() != null) {
    headers.put("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
  }
  headers.put("x-environment", environment);

  HttpClientWithContext vertxHttpClient = HttpClients.getClient(ConfigCenterHttpClientOptionsSPI.CLIENT_NAME);

  vertxHttpClient.runOnContext(client -> {
    Map<String, String> authHeaders = new HashMap<>();
    authHeaderProviders.forEach(provider -> authHeaders.putAll(provider.getSignAuthHeaders(
        createSignRequest(null, configCenter + url, headers, null))));
    WebSocketConnectOptions options = new WebSocketConnectOptions();
    options.setHost(ipPort.getHostOrIp()).setPort(refreshPort).setURI(url)
        .setHeaders(new CaseInsensitiveHeaders().addAll(headers)
            .addAll(authHeaders));
    client.webSocket(options, asyncResult -> {
      if (asyncResult.failed()) {
        LOGGER.error(
            "watcher connect to config center {} refresh port {} failed. Error message is [{}]",
            configCenter,
            refreshPort,
            asyncResult.cause().getMessage());
        waiter.countDown();
      } else {
        {
          asyncResult.result().exceptionHandler(e -> {
            LOGGER.error("watch config read fail", e);
            stopHeartBeatThread();
            isWatching = false;
          });
          asyncResult.result().closeHandler(v -> {
            LOGGER.warn("watching config connection is closed accidentally");
            stopHeartBeatThread();
            isWatching = false;
          });

          asyncResult.result().pongHandler(pong -> {
            // ignore, just prevent NPE.
          });
          asyncResult.result().frameHandler(frame -> {
            Buffer action = frame.binaryData();
            LOGGER.info("watching config recieved {}", action);
            Map<String, Object> mAction = action.toJsonObject().getMap();
            if ("CREATE".equals(mAction.get("action"))) {
              //event loop can not be blocked,we just keep nothing changed in push mode
              refreshConfig(configCenter, false);
            } else if ("MEMBER_CHANGE".equals(mAction.get("action"))) {
              refreshMembers(memberdis);
            } else {
              parseConfigUtils.refreshConfigItemsIncremental(mAction);
            }
          });
          startHeartBeatThread(asyncResult.result());
          isWatching = true;
          waiter.countDown();
        }
      }
    });
  });
  waiter.await();
}
 
Example #18
Source File: ServerEndpointsLogPublisher.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public void print(boolean printDetail) {
  appendLine(sb, "    server.endpoints:");
  appendLine(sb,
      "      connectCount disconnectCount rejectByLimit connections send(Bps) receive(Bps) listen");

  double connect = 0;
  double disconnect = 0;
  double reject = 0;
  double connections = 0;
  double readSize = 0;
  double writeSize = 0;
  for (MeasurementNode address : measurementNode.getChildren().values()) {
    connect += address.findChild(EndpointMeter.CONNECT_COUNT).summary();
    disconnect += address.findChild(EndpointMeter.DISCONNECT_COUNT).summary();
    reject += address.findChild(ServerEndpointMeter.REJECT_BY_CONNECTION_LIMIT).summary();
    connections += address.findChild(EndpointMeter.CONNECTIONS).summary();
    readSize += address.findChild(EndpointMeter.BYTES_READ).summary();
    writeSize += address.findChild(EndpointMeter.BYTES_WRITTEN).summary();

    if (printDetail) {
      appendLine(sb, "      %-12.0f %-15.0f %-13.0f %-11.0f %-9s %-12s %s",
          address.findChild(EndpointMeter.CONNECT_COUNT).summary(),
          address.findChild(EndpointMeter.DISCONNECT_COUNT).summary(),
          address.findChild(ServerEndpointMeter.REJECT_BY_CONNECTION_LIMIT).summary(),
          address.findChild(EndpointMeter.CONNECTIONS).summary(),
          NetUtils.humanReadableBytes((long) address.findChild(EndpointMeter.BYTES_WRITTEN).summary()),
          NetUtils.humanReadableBytes((long) address.findChild(EndpointMeter.BYTES_READ).summary()),
          address.getName()
      );
    }
  }

  appendLine(sb, "      %-12.0f %-15.0f %-13.0f %-11.0f %-9s %-12s %s",
      connect,
      disconnect,
      reject,
      connections,
      NetUtils.humanReadableBytes((long) writeSize),
      NetUtils.humanReadableBytes((long) readSize),
      "(summary)"
  );
}
 
Example #19
Source File: ClientEndpointsLogPublisher.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public void print(boolean printDetail) {
  appendLine(sb, "    client.endpoints:");
  appendLine(sb, "      connectCount disconnectCount queue         connections send(Bps) receive(Bps) remote");

  double connect = 0;
  double disconnect = 0;
  double queue = 0;
  double connections = 0;
  double readSize = 0;
  double writeSize = 0;
  for (MeasurementNode address : measurementNode.getChildren().values()) {
    connect += address.findChild(EndpointMeter.CONNECT_COUNT).summary();
    disconnect += address.findChild(EndpointMeter.DISCONNECT_COUNT).summary();
    queue += address.findChild(HttpClientEndpointMeter.QUEUE_COUNT).summary();
    connections += address.findChild(EndpointMeter.CONNECTIONS).summary();
    readSize += address.findChild(EndpointMeter.BYTES_READ).summary();
    writeSize += address.findChild(EndpointMeter.BYTES_WRITTEN).summary();

    if (printDetail) {
      appendLine(sb, "      %-12.0f %-15.0f %-13.0f %-11.0f %-9s %-12s %s",
          address.findChild(EndpointMeter.CONNECT_COUNT).summary(),
          address.findChild(EndpointMeter.DISCONNECT_COUNT).summary(),
          address.findChild(HttpClientEndpointMeter.QUEUE_COUNT).summary(),
          address.findChild(EndpointMeter.CONNECTIONS).summary(),
          NetUtils.humanReadableBytes((long) address.findChild(EndpointMeter.BYTES_WRITTEN).summary()),
          NetUtils.humanReadableBytes((long) address.findChild(EndpointMeter.BYTES_READ).summary()),
          address.getName()
      );
    }
  }

  appendLine(sb, "      %-12.0f %-15.0f %-13.0f %-11.0f %-9s %-12s %s",
      connect,
      disconnect,
      queue,
      connections,
      NetUtils.humanReadableBytes((long) writeSize),
      NetUtils.humanReadableBytes((long) readSize),
      "(summary)"
  );
}
 
Example #20
Source File: NetUtil.java    From spring-cloud-huawei with Apache License 2.0 2 votes vote down vote up
/**
 * getLocalHost
 * @return
 */
public static String getLocalHost() {
  return NetUtils.getHostName();
}