OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
agent_stats.cc
Go to the documentation of this file.
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>
13 
14 #include <cmn/agent_stats.h>
15 #include <cmn/stats_types.h>
16 #include <uve/agent_uve_base.h>
18 
20 
33  out_bytes_ = 0;
34 }
35 
36 void AgentStatsReq::HandleRequest() const {
37  Agent *agent = Agent::GetInstance();
38  AgentStats *stats = agent->stats();
39  IpcStatsResp *ipc = new IpcStatsResp();
40 
41  ipc->set_ipc_in_msgs(stats->ipc_in_msgs());
42  ipc->set_ipc_out_msgs(stats->ipc_out_msgs());
43  ipc->set_context(context());
44  ipc->set_more(true);
45  ipc->Response();
46 
47  /* If Pkt module is not set (for tor-agents for example), no need to send
48  * PktTrapStatsResp and FlowStatsResp */
49  if (agent->pkt()) {
50  PktTrapStatsResp *pkt = new PktTrapStatsResp();
51  pkt->set_exceptions(stats->pkt_exceptions());
52  pkt->set_invalid_agent_hdr(stats->pkt_invalid_agent_hdr());
53  pkt->set_invalid_interface(stats->pkt_invalid_interface());
54  pkt->set_no_handler(stats->pkt_no_handler());
55  pkt->set_pkt_dropped(stats->pkt_dropped());
56  pkt->set_pkt_fragments_dropped(stats->pkt_fragments_dropped());
57  pkt->set_pkt_invalid_mpls_hdr(stats->pkt_invalid_mpls_hdr());
58  pkt->set_pkt_invalid_ip_pkt(stats->pkt_invalid_ip_pkt());
59  pkt->set_pkt_drop_due_to_disable_tnl(stats->pkt_drop_due_to_disable_tnl());
60  pkt->set_pkt_invalid_frm_tor(stats->pkt_invalid_frm_tor());
61  pkt->set_pkt_drop_due_to_decode_error(stats->pkt_drop_due_to_decode_error());
62  pkt->set_pkt_drop_due_to_invalid_ethertype(stats->pkt_drop_due_to_invalid_ethertype());
63  pkt->set_pkt_drop_due_to_flow_trap(stats->pkt_drop_due_to_flow_trap());
64  pkt->set_context(context());
65  pkt->set_more(true);
66  pkt->Response();
67 
68  FlowStatsResp *flow = new FlowStatsResp();
69  flow->set_flow_active(stats->FlowCount());
70  flow->set_flow_created(stats->flow_created());
71  flow->set_flow_aged(stats->flow_aged());
72  flow->set_flow_drop_due_to_max_limit(
74  flow->set_flow_drop_due_to_linklocal_limit(
76  flow->set_flow_max_system_flows(agent->flow_table_size());
77  flow->set_flow_max_vm_flows(agent->max_vm_flows());
78  flow->set_context(context());
79  flow->set_more(true);
80  flow->Response();
81  }
82 
83  XmppStatsResp *xmpp_resp = new XmppStatsResp();
84  vector<XmppStatsInfo> list;
85  for (int count = 0; count < MAX_XMPP_SERVERS; count++) {
86  XmppStatsInfo peer;
87  if (!agent->controller_ifmap_xmpp_server(count).empty()) {
88  peer.set_ip(agent->controller_ifmap_xmpp_server(count));
89  AgentXmppChannel *ch = agent->controller_xmpp_channel(count);
90  if (ch == NULL) {
91  continue;
92  }
93  XmppChannel *xc = ch->GetXmppChannel();
94  if (xc == NULL) {
95  continue;
96  }
97  peer.set_reconnect(stats->xmpp_reconnects(count));
98  peer.set_in_msgs(stats->xmpp_in_msgs(count));
99  peer.set_out_msgs(stats->xmpp_out_msgs(count));
100  peer.set_config_in_msgs(stats->xmpp_config_in_msgs(count));
101  list.push_back(peer);
102  }
103  }
104  xmpp_resp->set_xmpp_list(list);
105  xmpp_resp->set_context(context());
106  xmpp_resp->set_more(true);
107  xmpp_resp->Response();
108 
109  SandeshStatsResp *sandesh = new SandeshStatsResp();
110  sandesh->set_sandesh_in_msgs(stats->sandesh_in_msgs());
111  sandesh->set_sandesh_out_msgs(stats->sandesh_out_msgs());
112  sandesh->set_sandesh_http_sessions(stats->sandesh_http_sessions());
113  sandesh->set_sandesh_reconnects(stats->sandesh_reconnects());
114  sandesh->set_context(context());
115  sandesh->set_more(true);
116  sandesh->Response();
117 
118  SessionEndpointExportStatsResp *srsp = new SessionEndpointExportStatsResp();
119  srsp->set_record_export_count(agent->flow_stats_manager()->
120  session_sample_exports());
121  srsp->set_msg_export_count(agent->flow_stats_manager()->
122  session_msg_exports());
123  srsp->set_session_export_disable_drops(agent->flow_stats_manager()->
124  session_export_disable_drops());
125  srsp->set_session_export_sampling_drops(agent->flow_stats_manager()->
126  session_export_sampling_drops());
127  srsp->set_session_exports(agent->flow_stats_manager()->session_exports());
128  srsp->set_session_export_drops(agent->flow_stats_manager()->
129  session_export_drops());
130  srsp->set_session_global_slo_logging_drops(agent->flow_stats_manager()->
131  session_global_slo_logging_drops());
132  srsp->set_session_slo_logging_drops(agent->flow_stats_manager()->
133  session_slo_logging_drops());
134  srsp->set_context(context());
135  srsp->set_more(false);
136  srsp->Response();
137 }
138 
139 void AgentStats::UpdateFlowMinMaxStats(uint64_t total_flows,
140  FlowCounters &stat) const {
141  uint64_t count = total_flows - stat.prev_flow_count;
142  if ((stat.max_flows_per_second == kInvalidFlowCount) ||
143  (count > stat.max_flows_per_second)) {
144  stat.max_flows_per_second = count;
145  }
146  if ((stat.min_flows_per_second == kInvalidFlowCount) ||
147  (count < stat.min_flows_per_second)) {
148  stat.min_flows_per_second = count;
149  }
150  stat.prev_flow_count = total_flows;
151 }
152 
156 }
157 
159  flow_count_fn_ = cb;
160 }
161 
162 uint32_t AgentStats::FlowCount() const {
163  if (flow_count_fn_.empty())
164  return 0;
165  return flow_count_fn_();
166 }
uint32_t FlowCount() const
Definition: agent_stats.cc:162
uint64_t pkt_drop_due_to_invalid_ethertype() const
Definition: agent_stats.h:159
uint64_t pkt_no_handler() const
Definition: agent_stats.h:138
XmppChannel * GetXmppChannel()
uint64_t pkt_invalid_frm_tor_
Definition: agent_stats.h:251
static Agent * GetInstance()
Definition: agent.h:436
FlowStatsManager * flow_stats_manager() const
Definition: agent.cc:925
uint64_t pkt_invalid_mpls_hdr() const
Definition: agent_stats.h:144
void Reset()
Definition: agent_stats.cc:21
uint64_t xmpp_out_msgs(uint8_t idx) const
Definition: agent_stats.h:67
uint64_t ipc_out_msgs_
Definition: agent_stats.h:270
static const uint32_t kInvalidFlowCount
Definition: agent_stats.h:16
uint64_t pkt_invalid_frm_tor() const
Definition: agent_stats.h:153
boost::function< uint32_t()> FlowCountFn
Definition: agent_stats.h:13
uint64_t in_bytes_
Definition: agent_stats.h:272
AgentStats * stats() const
Definition: agent.cc:881
uint64_t pkt_drop_due_to_disable_tnl() const
Definition: agent_stats.h:150
uint32_t nh_count_
Definition: agent_stats.h:239
uint64_t ipc_in_msgs() const
Definition: agent_stats.h:168
uint64_t flow_created() const
Definition: agent_stats.h:100
uint64_t flow_drop_due_to_linklocal_limit_
Definition: agent_stats.h:261
tbb::atomic< uint64_t > flow_created_
Definition: agent_stats.h:262
uint64_t pkt_fragments_dropped() const
Definition: agent_stats.h:141
uint32_t sandesh_http_sessions() const
Definition: agent_stats.h:84
uint64_t pkt_exceptions() const
Definition: agent_stats.h:129
uint32_t flow_table_size() const
Definition: agent.h:1199
uint32_t max_vm_flows() const
Definition: agent.h:1205
uint32_t xmpp_reconnects(uint8_t idx) const
Definition: agent_stats.h:59
uint64_t out_bytes_
Definition: agent_stats.h:274
uint64_t in_tpkts_
Definition: agent_stats.h:271
uint64_t pkt_invalid_agent_hdr_
Definition: agent_stats.h:243
AgentXmppChannel * controller_xmpp_channel(uint8_t idx) const
Definition: agent.h:809
uint64_t ipc_out_msgs() const
Definition: agent_stats.h:171
uint64_t pkt_drop_due_to_decode_error_
Definition: agent_stats.h:252
uint64_t pkt_drop_due_to_flow_trap_
Definition: agent_stats.h:254
uint64_t pkt_drop_due_to_flow_trap() const
Definition: agent_stats.h:162
uint64_t pkt_invalid_interface_
Definition: agent_stats.h:244
void ResetFlowMinMaxStats(FlowCounters &stat) const
Definition: agent_stats.cc:153
uint64_t flow_aged() const
Definition: agent_stats.h:107
uint64_t ipc_in_msgs_
Definition: agent_stats.h:269
uint64_t pkt_dropped() const
Definition: agent_stats.h:165
uint64_t pkt_no_handler_
Definition: agent_stats.h:245
uint64_t sandesh_in_msgs() const
Definition: agent_stats.h:78
uint64_t pkt_fragments_dropped_
Definition: agent_stats.h:246
Definition: agent.h:358
uint64_t sandesh_out_msgs_
Definition: agent_stats.h:235
void UpdateFlowMinMaxStats(uint64_t total_flows, FlowCounters &stat) const
Definition: agent_stats.cc:139
uint64_t sandesh_out_msgs() const
Definition: agent_stats.h:81
void RegisterFlowCountFn(FlowCountFn cb)
Definition: agent_stats.cc:158
static AgentStats * singleton_
Definition: agent_stats.h:276
uint64_t pkt_dropped_
Definition: agent_stats.h:247
uint64_t pkt_drop_due_to_invalid_ethertype_
Definition: agent_stats.h:253
const std::string & controller_ifmap_xmpp_server(uint8_t idx) const
Definition: agent.h:730
uint64_t flow_drop_due_to_max_limit() const
Definition: agent_stats.h:118
uint32_t sandesh_http_sessions_
Definition: agent_stats.h:236
#define MAX_XMPP_SERVERS
Definition: agent.h:291
uint64_t pkt_invalid_ip_pkt_
Definition: agent_stats.h:249
uint64_t pkt_invalid_interface() const
Definition: agent_stats.h:135
uint64_t pkt_invalid_ip_pkt() const
Definition: agent_stats.h:147
uint64_t xmpp_config_in_msgs(uint8_t idx) const
Definition: agent_stats.h:70
uint64_t pkt_invalid_mpls_hdr_
Definition: agent_stats.h:248
uint64_t xmpp_in_msgs(uint8_t idx) const
Definition: agent_stats.h:64
tbb::atomic< uint64_t > flow_aged_
Definition: agent_stats.h:263
FlowCountFn flow_count_fn_
Definition: agent_stats.h:227
uint64_t flow_drop_due_to_linklocal_limit() const
Definition: agent_stats.h:124
uint64_t session_exports() const
uint64_t pkt_drop_due_to_decode_error() const
Definition: agent_stats.h:156
uint64_t flow_drop_due_to_max_limit_
Definition: agent_stats.h:260
uint64_t pkt_exceptions_
Definition: agent_stats.h:242
uint64_t pkt_invalid_agent_hdr() const
Definition: agent_stats.h:132
uint32_t sandesh_reconnects_
Definition: agent_stats.h:233
tbb::atomic< uint32_t > hold_flow_count_
Definition: agent_stats.h:259
uint32_t sandesh_reconnects() const
Definition: agent_stats.h:75
PktModule * pkt() const
Definition: agent.cc:965
uint64_t out_tpkts_
Definition: agent_stats.h:273
uint64_t pkt_drop_due_to_disable_tnl_
Definition: agent_stats.h:250
uint64_t sandesh_in_msgs_
Definition: agent_stats.h:234