Line data Source code
1 : /* 2 : * Copyright (c) 2015 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : #ifndef SRC_VNSW_AGENT_OPER_PROFILE_H_ 5 : #define SRC_VNSW_AGENT_OPER_PROFILE_H_ 6 : #include "db/db.h" 7 : class Agent; 8 : class Timer; 9 : 10 : class ProfileData { 11 : public: 12 : ProfileData(); 13 393 : ~ProfileData(){} 14 : struct WorkQueueStats { 15 : std::string name_; 16 : uint64_t queue_count_; 17 : uint64_t enqueue_count_; 18 : uint64_t dequeue_count_; 19 : uint64_t max_queue_count_; 20 : uint64_t start_count_; 21 : uint64_t busy_time_; 22 : void Reset(); 23 : void Get(); 24 : }; 25 : 26 : struct FlowTokenStats { 27 : uint32_t add_tokens_; 28 : uint64_t add_failures_; 29 : uint64_t add_restarts_; 30 : uint32_t ksync_tokens_; 31 : uint64_t ksync_failures_; 32 : uint64_t ksync_restarts_; 33 : uint32_t update_tokens_; 34 : uint64_t update_failures_; 35 : uint64_t update_restarts_; 36 : uint32_t del_tokens_; 37 : uint64_t del_failures_; 38 : uint64_t del_restarts_; 39 : void Reset(); 40 : }; 41 : 42 : struct DBTableStats { 43 : uint64_t db_entry_count_; 44 : uint64_t walker_count_; 45 : uint64_t enqueue_count_; 46 : uint64_t input_count_; 47 : uint64_t notify_count_; 48 : void Get(const DBTable *table); 49 : void Accumulate(const DBTableBase *table); 50 : void Reset(); 51 : }; 52 : 53 : struct FlowStats { 54 : uint64_t flow_count_; 55 : uint64_t add_count_; 56 : uint64_t del_count_; 57 : uint64_t audit_count_; 58 : uint64_t reval_count_; 59 : uint64_t recompute_count_; 60 : uint64_t vrouter_responses_; 61 : uint64_t vrouter_error_; 62 : uint64_t evict_count_; 63 : FlowTokenStats token_stats_; 64 : WorkQueueStats pkt_handler_queue_; 65 : WorkQueueStats flow_mgmt_queue_; 66 : WorkQueueStats flow_update_queue_; 67 : std::vector<WorkQueueStats> flow_event_queue_; 68 : std::vector<WorkQueueStats> flow_tokenless_queue_; 69 : std::vector<WorkQueueStats> flow_delete_queue_; 70 : std::vector<WorkQueueStats> flow_ksync_queue_; 71 : std::vector<WorkQueueStats> flow_stats_queue_; 72 : void Get(); 73 : void Reset(); 74 : }; 75 : 76 : struct PktStats { 77 : uint64_t arp_count_; 78 : uint64_t dhcp_count_; 79 : uint64_t dns_count_; 80 : uint64_t icmp_count_; 81 : void Get(); 82 : void Reset(); 83 : }; 84 : 85 : struct XmppStats { 86 : uint64_t inet4_add_count_; 87 : uint64_t inet4_del_count_; 88 : uint64_t inet6_add_count_; 89 : uint64_t inet6_del_count_; 90 : uint64_t mcast_add_count_; 91 : uint64_t mcast_del_count_; 92 : uint64_t bridge_add_count_; 93 : uint64_t bridge_del_count_; 94 : void Get(); 95 : void Reset(); 96 : }; 97 : 98 : struct NovaIpcStats { 99 : uint64_t add_count_; 100 : uint64_t del_count_; 101 : void Get(); 102 : }; 103 : 104 : void Get(Agent *agent); 105 : public: 106 : std::string time_; 107 : FlowStats flow_; 108 : PktStats pkt_; 109 : DBTableStats inet4_routes_; 110 : DBTableStats inet6_routes_; 111 : DBTableStats bridge_routes_; 112 : DBTableStats multicast_routes_; 113 : DBTableStats evpn_routes_; 114 : XmppStats rx_stats_; 115 : XmppStats tx_stats_; 116 : WorkQueueStats ksync_tx_queue_count_; 117 : WorkQueueStats ksync_rx_queue_count_; 118 : TaskStats task_stats_[24]; 119 : std::map<std::string, DBTableStats > profile_stats_table_; 120 : }; 121 : 122 : class AgentProfile { 123 : public: 124 : static const uint32_t kProfileTimeout = 1000; 125 : static const uint16_t kSecondsHistoryCount = 300; 126 : static const uint16_t kMinutesHistoryCount = 60; 127 : static const uint16_t kHoursHistoryCount = 24; 128 : typedef boost::function<void(ProfileData *data)> PktFlowStatsCb; 129 : typedef boost::function<void(ProfileData *data)> KSyncStatsCb; 130 : typedef boost::function<void(ProfileData *data)> ProfileCb; 131 : 132 : AgentProfile(Agent *agent, bool enable); 133 : ~AgentProfile(); 134 : bool Init(); 135 : void Shutdown(); 136 : void InitDone(); 137 : 138 : bool TimerRun(); 139 : void Log(); 140 : 141 1 : void RegisterPktFlowStatsCb(ProfileCb cb) { pkt_flow_stats_cb_ = cb; } 142 1 : void RegisterKSyncStatsCb(ProfileCb cb) { ksync_stats_cb_ = cb; } 143 0 : void RegisterFlowStatsCb(ProfileCb cb) { flow_stats_cb_ = cb; } 144 : void AddProfileData(ProfileData *data); 145 : ProfileData *GetProfileData(uint16_t index); 146 0 : uint16_t seconds_history_index() const { return seconds_history_index_; } 147 : private: 148 : ProfileData *GetLastProfileData(); 149 : 150 : Agent *agent_; 151 : Timer *timer_; 152 : time_t start_time_; 153 : bool enable_; 154 : 155 : ProfileData one_min_data_; 156 : ProfileData five_min_data_; 157 : ProfileData fifteen_min_data_; 158 : ProfileData thirty_min_data_; 159 : ProfileData one_hr_data_; 160 : ProfileData four_hr_data_; 161 : ProfileData eight_hr_data_; 162 : ProfileData sixteen_hr_data_; 163 : ProfileData twentyfour_hr_data_; 164 : 165 : uint16_t seconds_history_index_; 166 : ProfileData seconds_history_data_[kSecondsHistoryCount]; 167 : uint16_t minutes_history_index_; 168 : ProfileData minutes_history_data_[kMinutesHistoryCount]; 169 : uint16_t hours_history_index_; 170 : ProfileData hours_history_data_[kHoursHistoryCount]; 171 : 172 : ProfileCb pkt_flow_stats_cb_; 173 : ProfileCb ksync_stats_cb_; 174 : ProfileCb flow_stats_cb_; 175 : DISALLOW_COPY_AND_ASSIGN(AgentProfile); 176 : }; 177 : 178 : #endif // SRC_VNSW_AGENT_OPER_PROFILE_H_