summaryrefslogtreecommitdiff
path: root/src/MESA_field_stat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MESA_field_stat.cpp')
-rw-r--r--src/MESA_field_stat.cpp136
1 files changed, 16 insertions, 120 deletions
diff --git a/src/MESA_field_stat.cpp b/src/MESA_field_stat.cpp
index 1e1d3ea..0f562aa 100644
--- a/src/MESA_field_stat.cpp
+++ b/src/MESA_field_stat.cpp
@@ -1,4 +1,5 @@
#include "field_stat2.h"
+#include "field_stat_internal.h"
#include "hdr_histogram.h"
#include "cJSON.h"
@@ -20,48 +21,10 @@
#include <assert.h>
#include <sys/time.h>
-
-
-#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
-
double HISTOGRAM_DEFAULT_BINS[]={50.0, 80.0, 90.0, 95.0, 99.0};
-
int FIELD_STAT_VERSION_2_8_20200805_fix_outOfBound=0;
-#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
-
//Automatically generate the version number
#ifdef __cplusplus
extern "C"
@@ -88,7 +51,6 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
const char* draw_line="________________________________________________________________________________________________________________________________________________";
const char* draw_boundary="============================================================";
-
static char* __str_dup(const char* str)
{
char* dup=NULL;
@@ -136,41 +98,7 @@ error_out:
free(bins);
return -1;
}
-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 display_manifest_t* display_manifest_new(const char* name, enum field_dsp_style_t style,enum field_calc_algo calc_type)
{
struct display_manifest_t* p=(struct display_manifest_t*)calloc(sizeof(struct display_manifest_t),1);
@@ -189,51 +117,6 @@ void display_manifest_free(struct display_manifest_t* p)
return;
}
-
-struct FS_space_t
-{
- int stat_cycle;
- int screen_print_trigger;
- int print_mode; //1:Rewrite ,2: Append
- int create_thread;
- int running;
-
- 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;
-};
-
static int send_udp(int sd, unsigned int dest_ip, unsigned short dest_port, const char * data, int len)
{
int to_send_len=len;
@@ -574,6 +457,13 @@ int FS_set_para(screen_stat_handle_t handle, enum FS_option type,const void* va
}
_handle->metris_format=int_val;
break;
+ case OUTPUT_PROMETHEUS:
+ int_val = *(const int *)value;
+ if(size==sizeof(int))
+ {
+ _handle->output_prometheus=*(int *)value;
+ }
+ break;
default:
return -1;
}
@@ -647,6 +537,12 @@ void FS_start(screen_stat_handle_t handle)
{
pthread_create(&(_handle->cfg_mon_t), NULL, fs2_thread_screen_print, (void*)handle);
}
+
+ if(_handle->output_prometheus==1)
+ {
+ FS_library_promethues_register(handle);
+ }
+
return;
}
void FS_stop(screen_stat_handle_t* handle)
@@ -899,7 +795,7 @@ int FS_operate(screen_stat_handle_t handle,int id,int column_id,enum field_op op
}
return 0;
}
-static long long get_stat_unit_val(display_manifest_t* p, int column_seq,enum field_calc_algo calc_type,int is_refer)
+long long get_stat_unit_val(display_manifest_t* p, int column_seq,enum field_calc_algo calc_type,int is_refer)
{
stat_unit_t* target=NULL;
long long value=0;