summaryrefslogtreecommitdiff
path: root/shaping/include/shaper_stat.h
blob: 198b87d34f6a084d800c5821256048d043af0ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

#include <netinet/in.h>
#include <librdkafka/rdkafka.h>
#include <fieldstat/fieldstat_easy.h>
#include "uthash.h"

enum shaping_packet_dir {
    SHAPING_DIR_IN = 0,
    SHAPING_DIR_OUT,
    SHAPING_DIR_MAX
};

enum shaping_stat_tags_index {
    TAG_VSYS_ID_IDX = 0,
    TAG_RULE_ID_IDX,
    TAG_PROFILE_ID_IDX,
    TAG_PRIORITY_IDX,
    TAG_PROFILE_TYPE_IDX,
    TAG_IDX_MAX
};

enum shaping_stat_column_index {
    IN_QUEUE_LEN_IDX = 0,
    OUT_QUEUE_LEN_IDX,
    IN_PKTS_IDX,
    IN_BYTES_IDX,
    IN_DROP_PKTS_IDX,
    OUT_PKTS_IDX,
    OUT_BYTES_IDX,
    OUT_DROP_PKTS_IDX,
    STAT_COLUNM_IDX_MAX
};

struct shaping_stat_for_profile_dir {
    unsigned long long pkts;
    unsigned long long bytes;
    unsigned long long drop_pkts;
    unsigned long long max_latency;
    long long queue_len;
};
struct shaping_stat_for_profile {
    struct shaping_stat_for_profile_dir in;
    struct shaping_stat_for_profile_dir out;
    long long priority_queue_len[SHAPING_DIR_MAX];
};

struct shaping_stat {
    struct fieldstat_easy *counter_instance;
    struct fieldstat_easy *guage_instance;
    rd_kafka_t *kafka_handle; 
    rd_kafka_topic_t *topic_rkt;
    int output_interval_s;
    int latency_histogram_id;
    unsigned int column_ids[STAT_COLUNM_IDX_MAX];
};

void shaper_stat_destroy(struct shaping_stat *stat);
struct shaping_stat* shaper_stat_init(int thread_num);

void shaper_stat_queueing_pkt_inc(struct shaping_stat_for_profile *profile_stat, unsigned char direction, int thread_id);
void shaper_stat_queueing_pkt_dec(struct shaping_stat_for_profile *profile_stat, unsigned char direction, int thread_id);
void shaper_stat_queueing_pkt_inc_for_rule(struct shaping_rule_info *rule, unsigned char direction, int thread_id);
void shaper_stat_queueing_pkt_dec_for_rule(struct shaping_rule_info *rule, unsigned char direction, int thread_id);
void shaper_stat_forward_inc(struct shaping_stat_for_profile *profile_stat, unsigned char direction, int pkt_len, int thread_id);
void shaper_stat_forward_all_rule_inc(struct shaping_stat *stat, struct shaping_flow *sf, unsigned char direction, int pkt_len, int thread_id);
void shaper_stat_drop_inc(struct shaping_stat_for_profile *profile_stat, unsigned char direction, int thread_id);
void shaper_stat_max_latency_update(struct shaping_stat_for_profile *profile_stat, unsigned char direction, unsigned long long latency, int thread_id);

void shaper_stat_refresh(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, int force);
void shaper_stat_priority_queue_len_refresh_all(struct shaping_thread_ctx *ctx, struct shaping_profile_hash_node *profile_hash_node);

void shaper_stat_output(struct shaping_stat *stat);