diff options
Diffstat (limited to 'common/src/tfe_fieldstat.cpp')
| -rw-r--r-- | common/src/tfe_fieldstat.cpp | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/common/src/tfe_fieldstat.cpp b/common/src/tfe_fieldstat.cpp index 2fc1e76..04523af 100644 --- a/common/src/tfe_fieldstat.cpp +++ b/common/src/tfe_fieldstat.cpp @@ -3,17 +3,45 @@ #include "tfe_stream.h" #include "tfe_resource.h" +#include "tfe_packet_io.h" -void tfe_set_intercept_metric(struct tfe_fieldstat_metric_t *fieldstat, struct tfe_cmsg *cmsg, int hit_count, int downstream_rx_pkts, int downstream_rx_bytes, int downstream_dir, int upstream_rx_pkts, int upstream_rx_bytes, int upstream_dir, int thread_id) +void tfe_set_intercept_metric(struct tfe_fieldstat_metric_t *fieldstat, struct session_ctx *s_ctx, int thread_id, int is_session_close) { int ret; uint16_t out_size; + struct tfe_cmsg *cmsg = s_ctx->cmsg; + struct timespec current_time; if (cmsg == NULL) { return; } + if (!is_session_close) + { + clock_gettime(CLOCK_MONOTONIC, ¤t_time); + if (current_time.tv_sec - s_ctx->metrics_last_time.tv_sec < 1) + { + return; + } + } + + s_ctx->metrics_last_time = current_time; + int downstream_dir = s_ctx->c2s_info.is_e2i_dir; + int downstream_rx_pkts = s_ctx->c2s_info.rx.n_pkts - s_ctx->c2s_info.rx_send_complete.n_pkts; + int downstream_rx_bytes = s_ctx->c2s_info.rx.n_bytes - s_ctx->c2s_info.rx_send_complete.n_bytes; + int upstream_dir = s_ctx->s2c_info.is_e2i_dir; + int upstream_rx_pkts = s_ctx->s2c_info.rx.n_pkts - s_ctx->s2c_info.rx_send_complete.n_pkts; + int upstream_rx_bytes = s_ctx->s2c_info.rx.n_bytes - s_ctx->s2c_info.rx_send_complete.n_bytes; + s_ctx->c2s_info.rx_send_complete = s_ctx->c2s_info.rx; + s_ctx->s2c_info.rx_send_complete = s_ctx->s2c_info.rx; + int hit_count = 0; + + if (s_ctx->metric_hit == 0) { + s_ctx->metric_hit = 1; + hit_count = 1; + } + int vsys_id = 0; ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_POLICY_VSYS_ID, (unsigned char *)&vsys_id, sizeof(vsys_id), &out_size); if (ret != 0) @@ -44,29 +72,29 @@ void tfe_set_intercept_metric(struct tfe_fieldstat_metric_t *fieldstat, struct t int out_bytes = 0; // incoming : E2I 的流量 - // outcoming : I2E 的流量 + // outgoing : I2E 的流量 // first_ctr_packet_dir <==> client hello packet dir // 1: E2I 0:I2E if (downstream_dir == 1) { - in_pkts = downstream_rx_pkts; - in_bytes = downstream_rx_bytes; + in_pkts += downstream_rx_pkts; + in_bytes += downstream_rx_bytes; } else { - out_pkts = downstream_rx_pkts; - out_bytes = downstream_rx_bytes; + out_pkts += downstream_rx_pkts; + out_bytes += downstream_rx_bytes; } if (upstream_dir == 1) { - in_pkts = upstream_rx_pkts; - in_bytes = upstream_rx_bytes; + in_pkts += upstream_rx_pkts; + in_bytes += upstream_rx_bytes; } else { - out_pkts = upstream_rx_pkts; - out_bytes = upstream_rx_bytes; + out_pkts += upstream_rx_pkts; + out_bytes += upstream_rx_bytes; } int nr_tags = 0; |
