Loading...
Searching...
No Matches
stats.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <chrono>
23#include <future>
24
26
27namespace resdb {
28
29class Stats {
30 public:
31 static Stats* GetGlobalStats(int sleep_seconds = 5);
32
33 void Stop();
34
35 void AddLatency(uint64_t run_time);
36
37 void Monitor();
38 void MonitorGlobal();
39
41
42 void IncClientCall();
43
44 void IncClientRequest();
45 void IncPropose();
46 void IncPrepare();
47 void IncCommit();
48 void IncPendingExecute();
49 void IncExecute();
50 void IncExecuteDone();
51
52 void BroadCastMsg();
53 void SendBroadCastMsg(uint32_t num);
55 void SeqFail();
56 void IncTotalRequest(uint32_t num);
57 void IncTotalGeoRequest(uint32_t num);
58 void IncGeoRequest();
59
60 void SeqGap(uint64_t seq_gap);
61 // Network in->worker
62 void ServerCall();
63 void ServerProcess();
64 void SetPrometheus(const std::string& prometheus_address);
65
66 protected:
67 Stats(int sleep_time = 5);
68 ~Stats();
69
70 private:
71 std::string monitor_port_ = "default";
72 std::string name_;
73 std::atomic<int> num_call_, run_call_;
74 std::atomic<uint64_t> last_time_, run_time_, run_call_time_;
75 std::thread thread_;
76 std::atomic<bool> begin_;
77 std::atomic<bool> stop_;
78 std::condition_variable cv_;
79 std::mutex mutex_;
80
81 std::thread global_thread_;
82 std::atomic<uint64_t> num_client_req_, num_propose_, num_prepare_,
83 num_commit_, pending_execute_, execute_, execute_done_;
84 std::atomic<uint64_t> client_call_, socket_recv_;
85 std::atomic<uint64_t> broad_cast_msg_, send_broad_cast_msg_,
86 send_broad_cast_msg_per_rep_;
87 std::atomic<uint64_t> seq_fail_;
88 std::atomic<uint64_t> server_call_, server_process_;
89 std::atomic<uint64_t> run_req_num_;
90 std::atomic<uint64_t> run_req_run_time_;
91 std::atomic<uint64_t> seq_gap_;
92 std::atomic<uint64_t> total_request_, total_geo_request_, geo_request_;
93 int monitor_sleep_time_ = 5; // default 5s.
94
95 std::unique_ptr<PrometheusHandler> prometheus_;
96};
97
98} // namespace resdb
void IncExecuteDone()
Definition stats.cpp:254
void BroadCastMsg()
Definition stats.cpp:261
void SeqFail()
Definition stats.cpp:272
void IncTotalGeoRequest(uint32_t num)
Definition stats.cpp:281
static Stats * GetGlobalStats(int sleep_seconds=5)
Definition stats.cpp:29
void IncClientRequest()
Definition stats.cpp:222
void MonitorGlobal()
Definition stats.cpp:76
void ServerProcess()
Definition stats.cpp:292
void Stop()
Definition stats.cpp:67
void IncSocketRecv()
void IncTotalRequest(uint32_t num)
Definition stats.cpp:274
void SendBroadCastMsg(uint32_t num)
Definition stats.cpp:268
void IncPrepare()
Definition stats.cpp:236
void IncExecute()
Definition stats.cpp:252
void IncPendingExecute()
Definition stats.cpp:250
void IncCommit()
Definition stats.cpp:243
void SendBroadCastMsgPerRep()
Definition stats.cpp:270
void Monitor()
void AddLatency(uint64_t run_time)
Definition stats.cpp:301
void IncPropose()
Definition stats.cpp:229
void IncGeoRequest()
Definition stats.cpp:283
void SeqGap(uint64_t seq_gap)
Definition stats.cpp:299
void SetPrometheus(const std::string &prometheus_address)
Definition stats.cpp:306
void IncClientCall()
Definition stats.cpp:215
void ServerCall()
Definition stats.cpp:285