Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #include <string> 6 : #include <vector> 7 : #include <base/logging.h> 8 : 9 : #include <vnc_cfg_types.h> 10 : #include <cmn/agent_cmn.h> 11 : #include <xmpp/xmpp_channel.h> 12 : #include <controller/controller_peer.h> 13 : 14 : #include <cmn/agent_stats.h> 15 : #include <cmn/stats_types.h> 16 : #include <uve/agent_uve_base.h> 17 : #include <vrouter/flow_stats/flow_stats_collector.h> 18 : 19 : AgentStats *AgentStats::singleton_; 20 : 21 0 : void AgentStats::Reset() { 22 0 : sandesh_reconnects_ = sandesh_in_msgs_ = sandesh_out_msgs_ = 0; 23 0 : sandesh_http_sessions_ = nh_count_ = pkt_exceptions_ = 0; 24 0 : pkt_invalid_agent_hdr_ = pkt_invalid_interface_ = 0; 25 0 : pkt_no_handler_ = pkt_dropped_ = 0; 26 0 : pkt_invalid_mpls_hdr_ = pkt_invalid_ip_pkt_ = pkt_drop_due_to_disable_tnl_ = 0; 27 0 : pkt_invalid_frm_tor_ = pkt_drop_due_to_decode_error_ = pkt_drop_due_to_invalid_ethertype_ = 0; 28 0 : pkt_drop_due_to_flow_trap_ = 0; 29 0 : flow_created_ = pkt_fragments_dropped_ = hold_flow_count_ = 0; 30 0 : flow_aged_ = flow_drop_due_to_max_limit_ = 0; 31 0 : flow_drop_due_to_linklocal_limit_ = ipc_in_msgs_ = 0; 32 0 : ipc_out_msgs_ = in_tpkts_ = in_bytes_ = out_tpkts_ = 0; 33 0 : out_bytes_ = 0; 34 0 : } 35 : 36 0 : void AgentStatsReq::HandleRequest() const { 37 0 : Agent *agent = Agent::GetInstance(); 38 0 : AgentStats *stats = agent->stats(); 39 0 : IpcStatsResp *ipc = new IpcStatsResp(); 40 : 41 0 : ipc->set_ipc_in_msgs(stats->ipc_in_msgs()); 42 0 : ipc->set_ipc_out_msgs(stats->ipc_out_msgs()); 43 0 : ipc->set_context(context()); 44 0 : ipc->set_more(true); 45 0 : ipc->Response(); 46 : 47 : /* If Pkt module is not set (for tor-agents for example), no need to send 48 : * PktTrapStatsResp and FlowStatsResp */ 49 0 : if (agent->pkt()) { 50 0 : PktTrapStatsResp *pkt = new PktTrapStatsResp(); 51 0 : pkt->set_exceptions(stats->pkt_exceptions()); 52 0 : pkt->set_invalid_agent_hdr(stats->pkt_invalid_agent_hdr()); 53 0 : pkt->set_invalid_interface(stats->pkt_invalid_interface()); 54 0 : pkt->set_no_handler(stats->pkt_no_handler()); 55 0 : pkt->set_pkt_dropped(stats->pkt_dropped()); 56 0 : pkt->set_pkt_fragments_dropped(stats->pkt_fragments_dropped()); 57 0 : pkt->set_pkt_invalid_mpls_hdr(stats->pkt_invalid_mpls_hdr()); 58 0 : pkt->set_pkt_invalid_ip_pkt(stats->pkt_invalid_ip_pkt()); 59 0 : pkt->set_pkt_drop_due_to_disable_tnl(stats->pkt_drop_due_to_disable_tnl()); 60 0 : pkt->set_pkt_invalid_frm_tor(stats->pkt_invalid_frm_tor()); 61 0 : pkt->set_pkt_drop_due_to_decode_error(stats->pkt_drop_due_to_decode_error()); 62 0 : pkt->set_pkt_drop_due_to_invalid_ethertype(stats->pkt_drop_due_to_invalid_ethertype()); 63 0 : pkt->set_pkt_drop_due_to_flow_trap(stats->pkt_drop_due_to_flow_trap()); 64 0 : pkt->set_context(context()); 65 0 : pkt->set_more(true); 66 0 : pkt->Response(); 67 : 68 0 : FlowStatsResp *flow = new FlowStatsResp(); 69 0 : flow->set_flow_active(stats->FlowCount()); 70 0 : flow->set_flow_created(stats->flow_created()); 71 0 : flow->set_flow_aged(stats->flow_aged()); 72 0 : flow->set_flow_drop_due_to_max_limit( 73 : stats->flow_drop_due_to_max_limit()); 74 0 : flow->set_flow_drop_due_to_linklocal_limit( 75 : stats->flow_drop_due_to_linklocal_limit()); 76 0 : flow->set_flow_max_system_flows(agent->flow_table_size()); 77 0 : flow->set_flow_max_vm_flows(agent->max_vm_flows()); 78 0 : flow->set_context(context()); 79 0 : flow->set_more(true); 80 0 : flow->Response(); 81 : } 82 : 83 0 : XmppStatsResp *xmpp_resp = new XmppStatsResp(); 84 0 : vector<XmppStatsInfo> list; 85 0 : for (int count = 0; count < MAX_XMPP_SERVERS; count++) { 86 0 : XmppStatsInfo peer; 87 0 : if (!agent->controller_ifmap_xmpp_server(count).empty()) { 88 0 : peer.set_ip(agent->controller_ifmap_xmpp_server(count)); 89 0 : AgentXmppChannel *ch = agent->controller_xmpp_channel(count); 90 0 : if (ch == NULL) { 91 0 : continue; 92 : } 93 0 : XmppChannel *xc = ch->GetXmppChannel(); 94 0 : if (xc == NULL) { 95 0 : continue; 96 : } 97 0 : peer.set_reconnect(stats->xmpp_reconnects(count)); 98 0 : peer.set_in_msgs(stats->xmpp_in_msgs(count)); 99 0 : peer.set_out_msgs(stats->xmpp_out_msgs(count)); 100 0 : peer.set_config_in_msgs(stats->xmpp_config_in_msgs(count)); 101 0 : list.push_back(peer); 102 : } 103 0 : } 104 0 : xmpp_resp->set_xmpp_list(list); 105 0 : xmpp_resp->set_context(context()); 106 0 : xmpp_resp->set_more(true); 107 0 : xmpp_resp->Response(); 108 : 109 0 : SandeshStatsResp *sandesh = new SandeshStatsResp(); 110 0 : sandesh->set_sandesh_in_msgs(stats->sandesh_in_msgs()); 111 0 : sandesh->set_sandesh_out_msgs(stats->sandesh_out_msgs()); 112 0 : sandesh->set_sandesh_http_sessions(stats->sandesh_http_sessions()); 113 0 : sandesh->set_sandesh_reconnects(stats->sandesh_reconnects()); 114 0 : sandesh->set_context(context()); 115 0 : sandesh->set_more(true); 116 0 : sandesh->Response(); 117 : 118 0 : SessionEndpointExportStatsResp *srsp = new SessionEndpointExportStatsResp(); 119 0 : srsp->set_record_export_count(agent->flow_stats_manager()-> 120 : session_sample_exports()); 121 0 : srsp->set_msg_export_count(agent->flow_stats_manager()-> 122 : session_msg_exports()); 123 0 : srsp->set_session_export_disable_drops(agent->flow_stats_manager()-> 124 : session_export_disable_drops()); 125 0 : srsp->set_session_export_sampling_drops(agent->flow_stats_manager()-> 126 0 : session_export_sampling_drops()); 127 0 : srsp->set_session_exports(agent->flow_stats_manager()->session_exports()); 128 0 : srsp->set_session_export_drops(agent->flow_stats_manager()-> 129 0 : session_export_drops()); 130 0 : srsp->set_session_global_slo_logging_drops(agent->flow_stats_manager()-> 131 : session_global_slo_logging_drops()); 132 0 : srsp->set_session_slo_logging_drops(agent->flow_stats_manager()-> 133 : session_slo_logging_drops()); 134 0 : srsp->set_context(context()); 135 0 : srsp->set_more(false); 136 0 : srsp->Response(); 137 0 : } 138 : 139 0 : void AgentStats::UpdateFlowMinMaxStats(uint64_t total_flows, 140 : FlowCounters &stat) const { 141 0 : uint64_t count = total_flows - stat.prev_flow_count; 142 0 : if ((stat.max_flows_per_second == kInvalidFlowCount) || 143 0 : (count > stat.max_flows_per_second)) { 144 0 : stat.max_flows_per_second = count; 145 : } 146 0 : if ((stat.min_flows_per_second == kInvalidFlowCount) || 147 0 : (count < stat.min_flows_per_second)) { 148 0 : stat.min_flows_per_second = count; 149 : } 150 0 : stat.prev_flow_count = total_flows; 151 0 : } 152 : 153 0 : void AgentStats::ResetFlowMinMaxStats(FlowCounters &stat) const { 154 0 : stat.max_flows_per_second = kInvalidFlowCount; 155 0 : stat.min_flows_per_second = kInvalidFlowCount; 156 0 : } 157 : 158 2 : void AgentStats::RegisterFlowCountFn(FlowCountFn cb) { 159 2 : flow_count_fn_ = cb; 160 2 : } 161 : 162 0 : uint32_t AgentStats::FlowCount() const { 163 0 : if (flow_count_fn_.empty()) 164 0 : return 0; 165 0 : return flow_count_fn_(); 166 : }