org.zodiac.actuate.sentinel.SentinelMonitorEndpoint Maven / Gradle / Ivy
The newest version!
package org.zodiac.actuate.sentinel;
import java.util.Collections;
import java.util.Map;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.LogBase;
import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.zodiac.sdk.toolkit.util.collection.CollUtil;
import org.zodiac.sentinel.base.config.SentinelConfigInfo;
import org.zodiac.sentinel.base.constants.SentinelBaseConstants;
@Endpoint(id = SentinelMonitorEndpoint.ID)
public class SentinelMonitorEndpoint {
public static final String ID = "sentinel-monitor";
private final SentinelConfigInfo sentinelConfigInfo;
public SentinelMonitorEndpoint(SentinelConfigInfo sentinelConfigInfo) {
this.sentinelConfigInfo = sentinelConfigInfo;
}
@ReadOperation
public Map invoke() {
final Map result = CollUtil.map();
if (sentinelConfigInfo.isEnabled()) {
result.put("appName", AppNameUtil.getAppName());
result.put("logDir", LogBase.getLogBaseDir());
result.put("logUsePid", LogBase.isLogNameUsePid());
result.put("blockPage", SentinelConfig.getConfig(SentinelBaseConstants.BLOCK_PAGE_URL_CONF_KEY));
result.put("metricsFileSize", SentinelConfig.singleMetricFileSize());
result.put("metricsFileCharset", SentinelConfig.charset());
result.put("totalMetricsFileCount", SentinelConfig.totalMetricFileCount());
result.put("consoleServer", TransportConfig.getConsoleServerList());
result.put("clientIp", TransportConfig.getHeartbeatClientIp());
result.put("heartbeatIntervalMs", TransportConfig.getHeartbeatIntervalMs());
result.put("clientPort", TransportConfig.getPort());
result.put("coldFactor", sentinelConfigInfo.getFlow().getColdFactor());
result.put("filter", sentinelConfigInfo.getHttp().getFilter());
result.put("datasource", sentinelConfigInfo.getDatasource());
final Map rules = CollUtil.map();
rules.put("flowRules", FlowRuleManager.getRules());
rules.put("degradeRules", DegradeRuleManager.getRules());
rules.put("systemRules", SystemRuleManager.getRules());
rules.put("authorityRule", AuthorityRuleManager.getRules());
rules.put("paramFlowRule", ParamFlowRuleManager.getRules());
result.put("rules", rules);
}
return Collections.unmodifiableMap(result);
}
}