com.alibaba.csp.sentinel.cluster.server.config.ClusterServerConfigManager Java Examples

The following examples show how to use com.alibaba.csp.sentinel.cluster.server.config.ClusterServerConfigManager. 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: ModifyServerNamespaceSetHandler.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    String data = request.getParam("data");
    if (StringUtil.isBlank(data)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("empty data"));
    }
    try {
        data = URLDecoder.decode(data, "utf-8");
        RecordLog.info("[ModifyServerNamespaceSetHandler] Receiving cluster server namespace set: " + data);
        Set<String> set = JSON.parseObject(data, new TypeReference<Set<String>>() {});
        ClusterServerConfigManager.loadServerNamespaceSet(set);
        return CommandResponse.ofSuccess("success");
    } catch (Exception e) {
        RecordLog.warn("[ModifyServerNamespaceSetHandler] Decode cluster server namespace set error", e);
        return CommandResponse.ofFailure(e, "decode client cluster config error");
    }
}
 
Example #2
Source File: ModifyClusterServerTransportConfigHandler.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    String portValue = request.getParam("port");
    if (StringUtil.isBlank(portValue)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid empty port"));
    }
    String idleSecondsValue = request.getParam("idleSeconds");
    if (StringUtil.isBlank(idleSecondsValue)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid empty idleSeconds"));
    }
    try {
        int port = Integer.valueOf(portValue);
        int idleSeconds = Integer.valueOf(idleSecondsValue);

        ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig()
            .setPort(port).setIdleSeconds(idleSeconds));
        return CommandResponse.ofSuccess("success");
    } catch (NumberFormatException e) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid parameter"));
    } catch (Exception ex) {
        return CommandResponse.ofFailure(new IllegalArgumentException("unexpected error"));
    }
}
 
Example #3
Source File: ScanIdleConnectionTask.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        int idleSeconds = ClusterServerConfigManager.getIdleSeconds();
        long idleTimeMillis = idleSeconds * 1000;
        if (idleTimeMillis < 0) {
            idleTimeMillis = ServerTransportConfig.DEFAULT_IDLE_SECONDS * 1000;
        }
        long now = System.currentTimeMillis();
        List<Connection> connections = connectionPool.listAllConnection();
        for (Connection conn : connections) {
            if ((now - conn.getLastReadTime()) > idleTimeMillis) {
                RecordLog.info(
                    String.format("[ScanIdleConnectionTask] The connection <%s:%d> has been idle for <%d>s. "
                        + "It will be closed now.", conn.getRemoteIP(), conn.getRemotePort(), idleSeconds)
                );
                conn.close();
            }
        }
    } catch (Throwable t) {
        RecordLog.warn("[ScanIdleConnectionTask] Failed to clean-up idle tasks", t);
    }
}
 
Example #4
Source File: ModifyServerNamespaceSetHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    String data = request.getParam("data");
    if (StringUtil.isBlank(data)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("empty data"));
    }
    try {
        data = URLDecoder.decode(data, "utf-8");
        RecordLog.info("[ModifyServerNamespaceSetHandler] Receiving cluster server namespace set: " + data);
        Set<String> set = JSON.parseObject(data, new TypeReference<Set<String>>() {});
        ClusterServerConfigManager.loadServerNamespaceSet(set);
        return CommandResponse.ofSuccess("success");
    } catch (Exception e) {
        RecordLog.warn("[ModifyServerNamespaceSetHandler] Decode cluster server namespace set error", e);
        return CommandResponse.ofFailure(e, "decode client cluster config error");
    }
}
 
Example #5
Source File: ScanIdleConnectionTask.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        int idleSeconds = ClusterServerConfigManager.getIdleSeconds();
        long idleTimeMillis = idleSeconds * 1000;
        if (idleTimeMillis < 0) {
            idleTimeMillis = ServerTransportConfig.DEFAULT_IDLE_SECONDS * 1000;
        }
        long now = System.currentTimeMillis();
        List<Connection> connections = connectionPool.listAllConnection();
        for (Connection conn : connections) {
            if ((now - conn.getLastReadTime()) > idleTimeMillis) {
                RecordLog.info(
                    String.format("[ScanIdleConnectionTask] The connection <%s:%d> has been idle for <%d>s. "
                        + "It will be closed now.", conn.getRemoteIP(), conn.getRemotePort(), idleSeconds)
                );
                conn.close();
            }
        }
    } catch (Throwable t) {
        RecordLog.warn("[ScanIdleConnectionTask] Failed to clean-up idle tasks", t);
    }
}
 
Example #6
Source File: ModifyClusterServerTransportConfigHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    String portValue = request.getParam("port");
    if (StringUtil.isBlank(portValue)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid empty port"));
    }
    String idleSecondsValue = request.getParam("idleSeconds");
    if (StringUtil.isBlank(idleSecondsValue)) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid empty idleSeconds"));
    }
    try {
        int port = Integer.valueOf(portValue);
        int idleSeconds = Integer.valueOf(idleSecondsValue);

        ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig()
            .setPort(port).setIdleSeconds(idleSeconds));
        return CommandResponse.ofSuccess("success");
    } catch (NumberFormatException e) {
        return CommandResponse.ofFailure(new IllegalArgumentException("invalid parameter"));
    } catch (Exception ex) {
        return CommandResponse.ofFailure(new IllegalArgumentException("unexpected error"));
    }
}
 
Example #7
Source File: DemoClusterInitFunc.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void initServerTransportConfigProperty() {
    ReadableDataSource<String, ServerTransportConfig> serverTransportDs = new NacosDataSource<>(remoteAddress, groupId,
        clusterMapDataId, source -> {
        List<ClusterGroupEntity> groupList = JSON.parseObject(source, new TypeReference<List<ClusterGroupEntity>>() {});
        return Optional.ofNullable(groupList)
            .flatMap(this::extractServerTransportConfig)
            .orElse(null);
    });
    ClusterServerConfigManager.registerServerTransportProperty(serverTransportDs.getProperty());
}
 
Example #8
Source File: ClusterServer.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 加载namespace的集合以及ServerTransportConfig
 * 最好还要再为他们每个都注册一个SentinelProperty,这样的话可以动态的修改这些配置项
 */
private void loadServerConfig(){
    // 加载namespace
    ClusterServerConfigManager.loadServerNamespaceSet(Collections.singleton(APP_NAME));
    // 加载ServerTransportConfig
    ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig()
            .setIdleSeconds(600)
            .setPort(CLUSTER_SERVER_PORT));
}
 
Example #9
Source File: ClusterServerDemo.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Not embedded mode by default (alone mode).
    ClusterTokenServer tokenServer = new SentinelDefaultTokenServer();

    // A sample for manually load config for cluster server.
    // It's recommended to use dynamic data source to cluster manage config and rules.
    // See the sample in DemoClusterServerInitFunc for detail.
    ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig()
        .setIdleSeconds(600)
        .setPort(11111));
    ClusterServerConfigManager.loadServerNamespaceSet(Collections.singleton(DemoConstants.APP_NAME));

    // Start the server.
    tokenServer.start();
}
 
Example #10
Source File: SimpleClusterFlowChecker.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static TokenResult acquireClusterToken(/*@Valid*/ FlowRule rule, int acquireCount) {
    Long id = rule.getClusterConfig().getFlowId();

    ClusterMetric metric = ClusterMetricStatistics.getMetric(id);
    if (metric == null) {
        return new TokenResult(TokenResultStatus.FAIL);
    }

    double latestQps = metric.getAvg(ClusterFlowEvent.PASS);
    double globalThreshold = rule.getCount() * ClusterServerConfigManager.getExceedCount();
    double nextRemaining = globalThreshold - latestQps - acquireCount;

    if (nextRemaining >= 0) {
        metric.add(ClusterFlowEvent.PASS, acquireCount);
        metric.add(ClusterFlowEvent.PASS_REQUEST, 1);

        ClusterServerStatLogUtil.log("flow|pass|" + id, acquireCount);
        ClusterServerStatLogUtil.log("flow|pass_request|" + id, 1);

        // Remaining count is cut down to a smaller integer.
        return new TokenResult(TokenResultStatus.OK)
            .setRemaining((int) nextRemaining)
            .setWaitInMs(0);
    } else {
        // Blocked.
        metric.add(ClusterFlowEvent.BLOCK, acquireCount);
        metric.add(ClusterFlowEvent.BLOCK_REQUEST, 1);
        ClusterServerStatLogUtil.log("flow|block|" + id, acquireCount);
        ClusterServerStatLogUtil.log("flow|block_request|" + id, 1);

        return blockedResult();
    }
}
 
Example #11
Source File: ClusterMetricStatistics.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static void resetFlowMetrics() {
    Set<Long> keySet = METRIC_MAP.keySet();
    for (Long id : keySet) {
        METRIC_MAP.put(id, new ClusterMetric(ClusterServerConfigManager.getSampleCount(),
            ClusterServerConfigManager.getIntervalMs()));
    }
}
 
Example #12
Source File: ClusterParamMetricStatistics.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static void resetFlowMetrics() {
    Set<Long> keySet = METRIC_MAP.keySet();
    for (Long id : keySet) {
        METRIC_MAP.put(id, new ClusterParamMetric(ClusterServerConfigManager.getSampleCount(),
            ClusterServerConfigManager.getIntervalMs()));
    }
}
 
Example #13
Source File: SentinelDefaultTokenServer.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public SentinelDefaultTokenServer(boolean embedded) {
    this.embedded = embedded;
    ClusterServerConfigManager.addTransportConfigChangeObserver(new ServerTransportConfigObserver() {
        @Override
        public void onTransportConfigChange(ServerTransportConfig config) {
            changeServerConfig(config);
        }
    });
    initNewServer();
}
 
Example #14
Source File: SentinelDefaultTokenServer.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void initNewServer() {
    if (server != null) {
        return;
    }
    int port = ClusterServerConfigManager.getPort();
    if (port > 0) {
        this.server = new NettyTransportServer(port);
        this.port = port;
    }
}
 
Example #15
Source File: SentinelDefaultTokenServer.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private void handleEmbeddedStart() {
    String namespace = ConfigSupplierRegistry.getNamespaceSupplier().get();
    if (StringUtil.isNotEmpty(namespace)) {
        // Mark server global mode as embedded.
        ClusterServerConfigManager.setEmbedded(true);
        if (!ClusterServerConfigManager.getNamespaceSet().contains(namespace)) {
            Set<String> namespaceSet = new HashSet<>(ClusterServerConfigManager.getNamespaceSet());
            namespaceSet.add(namespace);
            ClusterServerConfigManager.loadServerNamespaceSet(namespaceSet);
        }

        // Register self to connection group.
        ConnectionManager.addConnection(namespace, HostNameUtil.getIp());
    }
}
 
Example #16
Source File: FetchClusterServerConfigHandler.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private CommandResponse<String> namespaceConfigResult(/*@NonEmpty*/ String namespace) {
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount(namespace))
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio(namespace))
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs(namespace))
        .setSampleCount(ClusterServerConfigManager.getSampleCount(namespace));
    JSONObject config = new JSONObject()
        .fluentPut("flow", flowConfig);
    return CommandResponse.ofSuccess(config.toJSONString());
}
 
Example #17
Source File: FetchClusterServerConfigHandler.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
private CommandResponse<String> globalConfigResult() {
    ServerTransportConfig transportConfig = new ServerTransportConfig()
        .setPort(ClusterServerConfigManager.getPort())
        .setIdleSeconds(ClusterServerConfigManager.getIdleSeconds());
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount())
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio())
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs())
        .setSampleCount(ClusterServerConfigManager.getSampleCount());
    JSONObject config = new JSONObject()
        .fluentPut("transport", transportConfig)
        .fluentPut("flow", flowConfig)
        .fluentPut("namespaceSet", ClusterServerConfigManager.getNamespaceSet());
    return CommandResponse.ofSuccess(config.toJSONString());
}
 
Example #18
Source File: FetchClusterServerInfoCommandHandler.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    JSONObject info = new JSONObject();
    JSONArray connectionGroups = new JSONArray();
    Set<String> namespaceSet = ClusterServerConfigManager.getNamespaceSet();
    for (String namespace : namespaceSet) {
        ConnectionGroup group = ConnectionManager.getOrCreateConnectionGroup(namespace);
        if (group != null) {
            connectionGroups.add(group);
        }
    }

    ServerTransportConfig transportConfig = new ServerTransportConfig()
        .setPort(ClusterServerConfigManager.getPort())
        .setIdleSeconds(ClusterServerConfigManager.getIdleSeconds());
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount())
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio())
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs())
        .setSampleCount(ClusterServerConfigManager.getSampleCount())
        .setMaxAllowedQps(ClusterServerConfigManager.getMaxAllowedQps());

    JSONArray requestLimitData = buildRequestLimitData(namespaceSet);

    info.fluentPut("port", ClusterServerConfigManager.getPort())
        .fluentPut("connection", connectionGroups)
        .fluentPut("requestLimitData", requestLimitData)
        .fluentPut("transport", transportConfig)
        .fluentPut("flow", flowConfig)
        .fluentPut("namespaceSet", namespaceSet)
        .fluentPut("embedded", ClusterServerConfigManager.isEmbedded());

    // Since 1.5.0 the appName is carried so that the caller can identify the appName of the token server.
    info.put("appName", AppNameUtil.getAppName());

    return CommandResponse.ofSuccess(info.toJSONString());
}
 
Example #19
Source File: DemoClusterInitFunc.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private void initServerTransportConfigProperty() {
    ReadableDataSource<String, ServerTransportConfig> serverTransportDs = new NacosDataSource<>(remoteAddress, groupId,
        clusterMapDataId, source -> {
        List<ClusterGroupEntity> groupList = JSON.parseObject(source, new TypeReference<List<ClusterGroupEntity>>() {});
        return Optional.ofNullable(groupList)
            .flatMap(this::extractServerTransportConfig)
            .orElse(null);
    });
    ClusterServerConfigManager.registerServerTransportProperty(serverTransportDs.getProperty());
}
 
Example #20
Source File: ClusterServer.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 为ServerTransportConfig注册一个SentinelProperty
 * 这样的话可以动态的更改这些配置
 */
private void registerServerTransportProperty() {
    String serverTransportDataId = "cluster-server-transport-config";
    // 初始化一个配置服务端通道配置的 Nacos 数据源
    ReadableDataSource<String, ServerTransportConfig> transportConfigDs = new NacosDataSource<>(REMOTE_ADDRESS,
            GROUP_ID, serverTransportDataId,
            source -> JSON.parseObject(source, new TypeReference<ServerTransportConfig>() {}));
    ClusterServerConfigManager.registerServerTransportProperty(transportConfigDs.getProperty());
}
 
Example #21
Source File: ClusterServer.java    From sentinel-tutorial with Apache License 2.0 5 votes vote down vote up
/**
 * 为Namespace的集合注册一个SentinelProperty
 * 这样如果后期namespace集合发生变更的话,系统可以自动感知到
 */
private void registerNamespaceProperty() {
    String namespaceSetDataId = "cluster-server-namespace-set";
    // 初始化一个配置 namespace 的 Nacos 数据源
    ReadableDataSource<String, Set<String>> namespaceDs = new NacosDataSource<>(REMOTE_ADDRESS, GROUP_ID,
            namespaceSetDataId, source -> JSON.parseObject(source, new TypeReference<Set<String>>() {}));
    ClusterServerConfigManager.registerNamespaceSetProperty(namespaceDs.getProperty());
}
 
Example #22
Source File: FetchClusterServerInfoCommandHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Override
public CommandResponse<String> handle(CommandRequest request) {
    JSONObject info = new JSONObject();
    JSONArray connectionGroups = new JSONArray();
    Set<String> namespaceSet = ClusterServerConfigManager.getNamespaceSet();
    for (String namespace : namespaceSet) {
        ConnectionGroup group = ConnectionManager.getOrCreateConnectionGroup(namespace);
        if (group != null) {
            connectionGroups.add(group);
        }
    }

    ServerTransportConfig transportConfig = new ServerTransportConfig()
        .setPort(ClusterServerConfigManager.getPort())
        .setIdleSeconds(ClusterServerConfigManager.getIdleSeconds());
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount())
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio())
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs())
        .setSampleCount(ClusterServerConfigManager.getSampleCount())
        .setMaxAllowedQps(ClusterServerConfigManager.getMaxAllowedQps());

    JSONArray requestLimitData = buildRequestLimitData(namespaceSet);

    info.fluentPut("port", ClusterServerConfigManager.getPort())
        .fluentPut("connection", connectionGroups)
        .fluentPut("requestLimitData", requestLimitData)
        .fluentPut("transport", transportConfig)
        .fluentPut("flow", flowConfig)
        .fluentPut("namespaceSet", namespaceSet)
        .fluentPut("embedded", ClusterServerConfigManager.isEmbedded());

    // Since 1.5.0 the appName is carried so that the caller can identify the appName of the token server.
    info.put("appName", AppNameUtil.getAppName());

    return CommandResponse.ofSuccess(info.toJSONString());
}
 
Example #23
Source File: FetchClusterServerConfigHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private CommandResponse<String> globalConfigResult() {
    ServerTransportConfig transportConfig = new ServerTransportConfig()
        .setPort(ClusterServerConfigManager.getPort())
        .setIdleSeconds(ClusterServerConfigManager.getIdleSeconds());
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount())
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio())
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs())
        .setSampleCount(ClusterServerConfigManager.getSampleCount());
    JSONObject config = new JSONObject()
        .fluentPut("transport", transportConfig)
        .fluentPut("flow", flowConfig)
        .fluentPut("namespaceSet", ClusterServerConfigManager.getNamespaceSet());
    return CommandResponse.ofSuccess(config.toJSONString());
}
 
Example #24
Source File: FetchClusterServerConfigHandler.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private CommandResponse<String> namespaceConfigResult(/*@NonEmpty*/ String namespace) {
    ServerFlowConfig flowConfig = new ServerFlowConfig()
        .setExceedCount(ClusterServerConfigManager.getExceedCount(namespace))
        .setMaxOccupyRatio(ClusterServerConfigManager.getMaxOccupyRatio(namespace))
        .setIntervalMs(ClusterServerConfigManager.getIntervalMs(namespace))
        .setSampleCount(ClusterServerConfigManager.getSampleCount(namespace));
    JSONObject config = new JSONObject()
        .fluentPut("flow", flowConfig);
    return CommandResponse.ofSuccess(config.toJSONString());
}
 
Example #25
Source File: SentinelDefaultTokenServer.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private void handleEmbeddedStart() {
    String namespace = ConfigSupplierRegistry.getNamespaceSupplier().get();
    if (StringUtil.isNotEmpty(namespace)) {
        // Mark server global mode as embedded.
        ClusterServerConfigManager.setEmbedded(true);
        if (!ClusterServerConfigManager.getNamespaceSet().contains(namespace)) {
            Set<String> namespaceSet = new HashSet<>(ClusterServerConfigManager.getNamespaceSet());
            namespaceSet.add(namespace);
            ClusterServerConfigManager.loadServerNamespaceSet(namespaceSet);
        }

        // Register self to connection group.
        ConnectionManager.addConnection(namespace, HostNameUtil.getIp());
    }
}
 
Example #26
Source File: SentinelDefaultTokenServer.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
private void initNewServer() {
    if (server != null) {
        return;
    }
    int port = ClusterServerConfigManager.getPort();
    if (port > 0) {
        this.server = new NettyTransportServer(port);
        this.port = port;
    }
}
 
Example #27
Source File: SentinelDefaultTokenServer.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public SentinelDefaultTokenServer(boolean embedded) {
    this.embedded = embedded;
    ClusterServerConfigManager.addTransportConfigChangeObserver(new ServerTransportConfigObserver() {
        @Override
        public void onTransportConfigChange(ServerTransportConfig config) {
            changeServerConfig(config);
        }
    });
    initNewServer();
}
 
Example #28
Source File: ClusterParamMetricStatistics.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static void resetFlowMetrics() {
    Set<Long> keySet = METRIC_MAP.keySet();
    for (Long id : keySet) {
        METRIC_MAP.put(id, new ClusterParamMetric(ClusterServerConfigManager.getSampleCount(),
            ClusterServerConfigManager.getIntervalMs()));
    }
}
 
Example #29
Source File: ClusterMetricStatistics.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static void resetFlowMetrics() {
    Set<Long> keySet = METRIC_MAP.keySet();
    for (Long id : keySet) {
        METRIC_MAP.put(id, new ClusterMetric(ClusterServerConfigManager.getSampleCount(),
            ClusterServerConfigManager.getIntervalMs()));
    }
}
 
Example #30
Source File: ClusterServerDemo.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Not embedded mode by default (alone mode).
    ClusterTokenServer tokenServer = new SentinelDefaultTokenServer();

    // A sample for manually load config for cluster server.
    // It's recommended to use dynamic data source to cluster manage config and rules.
    // See the sample in DemoClusterServerInitFunc for detail.
    ClusterServerConfigManager.loadGlobalTransportConfig(new ServerTransportConfig()
        .setIdleSeconds(600)
        .setPort(11111));
    ClusterServerConfigManager.loadServerNamespaceSet(Collections.singleton(DemoConstants.APP_NAME));

    // Start the server.
    tokenServer.start();
}