Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

多维度bvar支持http内置服务查看吗? #2062

Closed
17336 opened this issue Dec 26, 2022 · 2 comments
Closed

多维度bvar支持http内置服务查看吗? #2062

17336 opened this issue Dec 26, 2022 · 2 comments
Labels
discussion open problems and feature requests module/bvar usage user need to change the way using brpc to solve the problem

Comments

@17336
Copy link

17336 commented Dec 26, 2022

github里多维度bvar文档里说支持
image
我在example中的echo示例中用了多维度bvar,但是在/brpc_metrics中并没有看到request_countabcd的统计数据。
我又在https://brpc.apache.org/zh/docs/bvar/mbvar-c++/
里看到说多维度bvar目前不支持http内置服务查询,所以到底支持还是不支持?还是只能在代码里通过describe等函数查到?
image

namespace metric {
    bvar::MultiDimension<bvar::Adder<int>> g_request_count("request_countabcd", {"idc", "method", "status"});
    int process_request(const std::list<std::string>& request_label) {
        // 获取request_label对应的单维度bvar指针,比如:request_label = {"tc", "get", "200"}
        bvar::Adder<int>* adder = g_request_count.get_stats(request_label);
        // 判断指针非空
        if (!adder) {
            LOG(ERROR) << "request no bvar"; // adder add up to 6
            return -1;
        }
        // adder只能在g_request_count的生命周期内访问,否则行为未定义,可能会出core
        // 给adder输入一些值
        *adder << 1 << 2 <<3;
        LOG(INFO) << "request adder=" << *adder; // adder add up to 6
        return 0;
    }
} // metric
namespace example {
class EchoServiceImpl : public EchoService {
public:
    EchoServiceImpl() {}
    virtual ~EchoServiceImpl() {}
    virtual void Echo(google::protobuf::RpcController* cntl_base,
                      const EchoRequest* request,
                      EchoResponse* response,
                      google::protobuf::Closure* done) {
        // This object helps you to call done->Run() in RAII style. If you need
        // to process the request asynchronously, pass done_guard.release().
        brpc::ClosureGuard done_guard(done);

        brpc::Controller* cntl =
            static_cast<brpc::Controller*>(cntl_base);

        // The purpose of following logs is to help you to understand
        // how clients interact with servers more intuitively. You should 
        // remove these logs in performance-sensitive servers.
        LOG(INFO) << "Received request[log_id=" << cntl->log_id() 
                  << "] from " << cntl->remote_side() 
                  << " to " << cntl->local_side()
                  << ": " << request->message()
                  << " (attached=" << cntl->request_attachment() << ")";

        // Fill response.
        response->set_message(request->message());

        metric::process_request({"lf","echo","success"});
        // You can compress the response by setting Controller, but be aware
        // that compression may be costly, evaluate before turning on.
        // cntl->set_response_compress_type(brpc::COMPRESS_TYPE_GZIP);

        if (FLAGS_echo_attachment) {
            // Set attachment which is wired to network directly instead of
            // being serialized into protobuf messages.
            cntl->response_attachment().append(cntl->request_attachment());
        }
    }
};
}  // namespace example
@cdjingit
Copy link
Contributor

bvar_max_dump_multi_dimension_metric_number 这个控制可以通过/brpc_metrics dump出来的multi bvar的数量,默认是0

@17336
Copy link
Author

17336 commented Dec 26, 2022

通过/brpc_metrics dump出来的multi bvar的数量,默认是0

好的,十分感谢

@serverglen serverglen added discussion open problems and feature requests usage user need to change the way using brpc to solve the problem module/bvar labels Jan 5, 2023
@wwbmmm wwbmmm closed this as completed Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion open problems and feature requests module/bvar usage user need to change the way using brpc to solve the problem
Projects
None yet
Development

No branches or pull requests

4 participants