summaryrefslogtreecommitdiff
path: root/src/field_stat_internal.h
blob: c477228b8aa4d17d36ef5fa0c618ff25a2d5c66c (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef	__FIELD_STAT2_INTERNAL_H__
#define	__FIELD_STAT2_INTERNAL_H__

#include <pthread.h>
#include "hdr_histogram.h"

#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 410)
#define atomic_inc(x) __sync_add_and_fetch((x),1)
#define atomic_dec(x) __sync_sub_and_fetch((x),1)
#define atomic_add(x,y) __sync_add_and_fetch((x),(y))
#define atomic_sub(x,y) __sync_sub_and_fetch((x),(y))
typedef long atomic_t;
#define ATOMIC_INIT(i)  { (i) }
#define atomic_read(x) __sync_add_and_fetch((x),0)
#define atomic_set(x,y) __sync_lock_test_and_set((x),y)
#else 
typedef long atomic_t;
#define atomic_inc(x)	((*(x))++)
#define atomic_dec(x)	((*(x))--)
#define atomic_add(x,y) ((*(x))+=(y))
#define atomic_sub(x,y) ((*(x))-=(y))
#define ATOMIC_INIT(i)  { (i) }
#define atomic_read(x) 	(*(x))
#define atomic_set(x,y)	((*(x))=(y))
#endif 

#define	INIT_STAT_FIELD_NUM		1024
#define	MAX_STAT_COLUMN_NUM		64
#define MAX_PATH_LEN			256
#define	UDP_PAYLOAD_SIZE		1460

#define	STATUS_PER_LINE				6
#define	FIELD_PER_LINE				8



#define	HISOTGRAM_EXTRA_INF			0
#define	HISTOGRAM_EXTRA_SUM			1
#define	HISTOGRAM_EXTRA_MAXVAL		2
#define	HISTOGRAM_EXTRA_SIZE		3


struct stat_unit_t
{
	long long changing;
	long long accumulated;	
	long long previous_changed;
};
struct histogram_t
{
	struct hdr_histogram* changing;
	struct hdr_histogram* accumulated;
	struct hdr_histogram* previous_changed;
	int64_t lowest_trackable_value;
	int64_t highest_trackable_value;
	int significant_figures;

};
struct display_manifest_t
{
	char* name;
	int is_invisible;
	int is_ratio;
	int not_send_to_server;
	int numerator_id;
	int denominator_id;
	int output_scaling;	//negative value: zoom in; positive value: zoom out;
	enum field_dsp_style_t style;
	enum field_calc_algo calc_type;
	union
	{
		struct stat_unit_t single;//for status and field
		struct stat_unit_t* line; //for line
		struct histogram_t histogram;
		int column_seq;	//for column
	};
};


struct FS_space_t
{
	int stat_cycle;
	int screen_print_trigger;
	int print_mode;	//1:Rewrite ,2: Append
	int create_thread;
	int running;
	int output_prometheus;
	
	int line_cnt;
	int display_cnt;
	int single_cnt;//including line_cnt;
	int metris_format;
	int column_cnt;
	int histogram_cnt;
	
	int histogram_bin_num;
	double* histogram_bins;

	int cloumn_id[MAX_STAT_COLUMN_NUM];
	int display_size;
	int current_date;
	int flush_by_date;
	char str_ip[32];
	char app_name[16];

	int statsd_switch;
	unsigned int server_ip;
	unsigned short server_port;
	int statsd_socket;

	size_t snd_buf_off;
	char send_buff[UDP_PAYLOAD_SIZE];
	
	pthread_mutex_t reg_lock;
	struct display_manifest_t **display;

	char appoint_output_file[MAX_PATH_LEN];
	char current_output_file[MAX_PATH_LEN];
	FILE* fp;
	pthread_t cfg_mon_t;
	struct timespec last_display_time;
	const char* write_mode;
};

int FS_library_promethues_register(screen_stat_handle_t handle);
long long get_stat_unit_val(display_manifest_t* p, int column_seq,enum field_calc_algo calc_type,int is_refer);
#endif