Java Code Examples for com.alibaba.csp.sentinel.slots.system.SystemRuleManager#loadRules()

The following examples show how to use com.alibaba.csp.sentinel.slots.system.SystemRuleManager#loadRules() . 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: SystemGuardDemo.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 6 votes vote down vote up
private static void initSystemRule() {
    List<SystemRule> rules = new ArrayList<SystemRule>();
    SystemRule rule = new SystemRule();
    // max load is 3
    rule.setHighestSystemLoad(3.0);
    // max cpu usage is 60%
    rule.setHighestCpuUsage(0.6);
    // max avg rt of all request is 10 ms
    rule.setAvgRt(10);
    // max total qps is 20
    rule.setQps(20);
    // max parallel working thread is 10
    rule.setMaxThread(10);

    rules.add(rule);
    SystemRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example 2
Source File: SystemGuardDemo.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private static void initSystemRule() {
    List<SystemRule> rules = new ArrayList<SystemRule>();
    SystemRule rule = new SystemRule();
    // max load is 3
    rule.setHighestSystemLoad(3.0);
    // max cpu usage is 60%
    rule.setHighestCpuUsage(0.6);
    // max avg rt of all request is 10 ms
    rule.setAvgRt(10);
    // max total qps is 20
    rule.setQps(20);
    // max parallel working thread is 10
    rule.setMaxThread(10);

    rules.add(rule);
    SystemRuleManager.loadRules(Collections.singletonList(rule));
}
 
Example 3
Source File: SystemRuleTest.java    From Sentinel-Dashboard-Nacos with Apache License 2.0 5 votes vote down vote up
@Test
public void testSystemRule_load() {
    SystemRule systemRule = new SystemRule();

    systemRule.setAvgRt(4000L);

    SystemRuleManager.loadRules(Collections.singletonList(systemRule));
}
 
Example 4
Source File: AppLifecycleBean.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
void onStart(@Observes StartupEvent ev) {
    LOGGER.info("The application is starting...");
    FlowRule rule = new FlowRule()
            .setCount(1)
            .setGrade(RuleConstant.FLOW_GRADE_QPS)
            .setResource("GET:/hello/txt")
            .setLimitApp("default")
            .as(FlowRule.class);
    FlowRuleManager.loadRules(Arrays.asList(rule));

    SystemRule systemRule = new SystemRule();
    systemRule.setLimitApp("default");
    systemRule.setAvgRt(3000);
    SystemRuleManager.loadRules(Arrays.asList(systemRule));

    DegradeRule degradeRule1 = new DegradeRule("greeting1")
            .setCount(1)
            .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
            .setTimeWindow(10)
            .setMinRequestAmount(1);

    DegradeRule degradeRule2 = new DegradeRule("greeting2")
            .setCount(1)
            .setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT)
            .setTimeWindow(10)
            .setMinRequestAmount(1);
    DegradeRuleManager.loadRules(Arrays.asList(degradeRule1, degradeRule2));
}
 
Example 5
Source File: SystemRuleTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
@Test
public void testSystemRule_load() {
    SystemRule systemRule = new SystemRule();

    systemRule.setAvgRt(4000L);

    SystemRuleManager.loadRules(Collections.singletonList(systemRule));
}