17336 opened a new issue, #2062:
URL: https://github.com/apache/incubator-brpc/issues/2062

   github里多维度bvar文档里说支持
   
![image](https://user-images.githubusercontent.com/74393844/209496436-1e391a38-712b-409d-aece-52f3f105a2c4.png)
   我在example中的echo示例中用了多维度bvar,但是在/brpc_metrics中并没有看到request_countabcd的统计数据。
   
我又在https://brpc.apache.org/zh/docs/bvar/mbvar-c++/里看到说多维度bvar目前不支持http内置服务查询,所以到底支持还是不支持?还是只能在代码里通过describe等函数查到?
   
![image](https://user-images.githubusercontent.com/74393844/209496564-f402950c-2086-438e-b23e-b8c83ab0ba10.png)
   
   ```
   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::qps << 1;
           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
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to