-
Notifications
You must be signed in to change notification settings - Fork 33
How To Use
Eric Zhao edited this page Jul 2, 2019
·
2 revisions
void InitSentinel() {
// The Logger should be initialized at first.
Sentinel::Log::Logger::InitDefaultLogger();
// Initialize the HTTP command server.
Sentinel::Transport::HttpCommandCenterInitTarget command_center_init;
command_center_init.Initialize();
// Initialize the metric log task.
Sentinel::Log::MetricLogTask metric_log_task;
metric_log_task.Initialize();
}
#include "sentinel-core/public/sph_u.h"
void SentinelEntry() {
auto r = Sentinel::SphU::Entry(resource_name);
// ------ response time begin ------
// Your logic here (should avoid exception!)
service->DoSomething();
if (!r->IsBlocked()) {
// ------ response time end ------
r.Exit();
} else {
// indicates that the request was blocked here
}
}
#include "sentinel-core/flow/flow_rule_manager.h"
void LoadRules() {
Sentinel::Flow::FlowRule rule1{"my_open_api_abc"};
rule1.set_count(8);
rule1.set_metric_type(Sentinel::Flow::FlowMetricType::kThreadCount);
Sentinel::Flow::FlowRule rule2{"my_another_service:foo()"};
rule2.set_count(20);
Sentinel::Flow::FlowRuleManager::GetInstance().LoadRules({rule1, rule2});
}
SomeDataSource<std::vector<Sentinel::Flow::FlowRule>> ds(args...);
ds.Init();
Sentinel::Flow::FlowRuleManager::GetInstance().RegisterToProperty(ds.GetProperty());