summaryrefslogtreecommitdiff
path: root/common/include/tfe_fieldstat.h
blob: bfa4b58c180a1a40a6c23f9cfaa48727fd9f016e (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
74
75
76
77
78
79
80
81
82
#ifndef _TFE_FIELDSTAT_METRIC_H
#define _TFE_FIELDSTAT_METRIC_H

#ifdef __cpluscplus
extern "C"
{
#endif

#include <tfe_utils.h>
#include "fieldstat/fieldstat_easy.h"

#define FIELDSTAT_TAG_INIT(ptr, index, _key, _type, _value) \
    do { ptr[index].key = _key; ptr[index].type = _type; ptr[index].value_longlong = _value; } while(0)
#define FIELDSTAT_TAG_STR(ptr, index, _key, _type, _value) \
    do { ptr[index].key = _key; ptr[index].type = _type; ptr[index].value_str = _value; } while(0)

enum metric_columns_index
{
	COLUMN_HIT_COUNT = 0,
	COLUMN_IN_BYTES,
	COLUMN_OUT_BYTES,
	COLUMN_IN_PKTS,
	COLUMN_OUT_PKTS,
	COLUMN_MAX
};

enum metric_tags_index
{
	TAG_VSYS_ID = 0,
	TAG_RULE_ID,
	TAG_ACTION,
    TAG_SUB_ACTION,
    TAG_PINNING_STATUS,
	TAG_MAX
};

struct fieldstat_easy_intercept
{
	int max_thread;
	int hit_count_idx;
    int in_bytes_idx;
    int out_bytes_idx;
    int in_pkts_idx;
    int out_pkts_idx;
	int output_fs_interval_ms;
	struct fieldstat_easy *fs;
};

struct filedstat_easy_manipulation
{
	int table_id;
    int max_thread;
    struct field **tags;
	int counter_array[COLUMN_MAX];
	struct fieldstat_easy *fs;
};

struct tfe_fieldstat_easy_t
{
	pthread_t tid;
	int thr_is_runing;
    int thr_need_exit;
    int output_kafka_interval_ms;
	struct fieldstat_easy_intercept *intercept;
	struct filedstat_easy_manipulation *manipulation;
};

int tfe_fieldstat_get_output_interval(struct fieldstat_easy_intercept *fieldstat);
int tfe_fieldstat_intercept_incrby(struct fieldstat_easy_intercept *fieldstat, void *val_data, int thread_index);
int tfe_fieldstat_manipulation_incrby(struct filedstat_easy_manipulation *fieldstat, unsigned int counter_id, long long value, const struct field tags[], int n_tags, int thread_id);

struct tfe_fieldstat_easy_t *tfe_fieldstat_easy_create(int output_kafka_interval_ms);
struct fieldstat_easy_intercept *tfe_fieldstat_easy_intercept_create(char *app_name, int max_thread, int output_fs_interval_ms, void *local_logger);
struct filedstat_easy_manipulation *tfe_fieldstat_easy_manipulation_create(char *app_name, char *outpath, int cycle, int max_thread, void *local_logger);
void tfe_fieldstat_easy_destroy(struct tfe_fieldstat_easy_t *fieldstat);

#ifdef __cpluscplus
}
#endif

#endif