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