/**************************************************************************** Program: $Id: rtgplot.h,v 1.23 2004/05/01 19:32:53 rbeverly Exp $ Author: $Author: rbeverly $ Date: $Date: 2004/05/01 19:32:53 $ Orig Date: January 15, 2002 Description: RTG traffic grapher headers ****************************************************************************/ #ifndef _RTGPLOT_H_ #define _RTGPLOT_H_ 1 #include #include #include /* XXX - REB - add to configure? */ #include #include /* XXX - REB - add to configure? */ #define XPLOT_AREA 500 #define YPLOT_AREA 150 #define BORDER_T 20 #define BORDER_B 70 #define BORDER_L 50 #define BORDER_R 20 #define XIMG_AREA (unsigned int)(XPLOT_AREA + BORDER_L + BORDER_R) #define YIMG_AREA (unsigned int)(YPLOT_AREA + BORDER_T + BORDER_B) /* size in pixels of the colors boxes in the legend */ #define LEGENDBOX_SIZE 7 /* number of pixels between the color legend boxes and their associated text */ #define LEGENDBOX_PAD 3 #define LEGENDBOX_AREA (unsigned int)(LEGENDBOX_PAD + LEGENDBOX_SIZE) /* number of pixels between bottom of X axis of graph and the start of */ /* legend data */ #define XLEGEND_OFFSET 30 #define XTICKS 10 #define YTICKS 5 #define MINUTE 60 #define HOUR (unsigned int)(MINUTE * 60) #define DAY (unsigned int)(HOUR * 24) #define WEEK (unsigned int)(DAY * 7) #define MONTH (unsigned int)(WEEK * 4) #define DEFAULT_UNITS "bps" #define MAXLINES 10 #define MAXTABLES 4 #define MAXIIDS 5 #define COPYRIGHT "RTG" #define DEBUGLOG "/tmp/rtgplot.log" /* Populate a data_t per item to plot */ typedef struct data_struct { long long counter; // interval sample value unsigned long timestamp; // UNIX timestamp float rate; // floating point rate int x; // X plot coordinate int y; // Y plot coordinate struct data_struct *next; // next sample } data_t; /* If calculating rate, a rate_t stores total, max, avg, cur rates */ typedef struct rate_struct { unsigned long long total; float max; float avg; float cur; } rate_t; /* we store legend info so we can create the legend in one */ /* fowl swoop */ typedef struct legend_struct { rate_t rate; // rate value int color; // color of the legend box int iid; // iid of interface char *table; // table name struct legend_struct *next; // next iid } legend_t; /* Each graph uses a range_t to keep track of data ranges */ typedef struct range_struct { unsigned long begin; // UNIX begin time unsigned long end; // UNIX end time unsigned long dataBegin; // Actual first datapoint in database long long counter_max; // Largest counter in range int scalex; // Scale X values to match actual datapoints long datapoints; // Number of datapoints in range } range_t; /* XXX - REB - new structs */ typedef struct count_struct { unsigned int POs; unsigned int DOs; unsigned int LOs; } count_t; typedef struct data_obj { unsigned short index; char *table; unsigned short id; data_t *data; // ptr to head of data linked list -- needs to be populated() rate_t *rate; // ptr to head of rate linked list -- needs to be calculated() } data_obj_t; /* We may wish to construct arbitrary groupings of data objects (DO). This is one particular wrapper: a linked-list of DOs */ typedef struct data_obj_list { data_obj_t *DO; struct data_obj_list *next; } data_obj_list_t; typedef struct plot_obj { char *title; unsigned short xsize; unsigned short ysize; unsigned short scalex; unsigned short scaley; } plot_obj_t; /* index:data:modifiers:appearance:label */ typedef struct line_obj { unsigned short index; data_obj_list_t *DO_list; unsigned short aggr; unsigned short percentile; unsigned short filled; unsigned short factor; char *label; } line_obj_t; /* XXX - REB - new structs */ /* Each graph has a image_t struct to keep borders and area variables */ typedef struct image_struct { unsigned int xplot_area; // X pixels of the plot unsigned int yplot_area; // Y pixels of the plot unsigned int border_b; // Pixels of border from plot to image bottom unsigned int ximg_area; // X pixels of the entire image unsigned int yimg_area; // Y pixels of the entire image } image_t; /* Each graph uses a graph_t struct to keep graph properties */ typedef struct graph_struct { int xmax; float ymax; unsigned long xoffset; int xunits; long long yunits; char *units; int impulses; int gauge; int scaley; range_t range; image_t image; } graph_t; /* A linked list of colors that we iterate through each line */ typedef struct color_struct { int shade; int rgb[3]; struct color_struct *next; } color_t; typedef struct arguments_struct { char *table[MAXTABLES]; int iid[MAXIIDS]; int tables_to_plot; int iids_to_plot; int factor; unsigned int aggregate; unsigned int percentile; unsigned int filled; char *conf_file; char *output_file; } arguments_t; /* Globals */ enum major_colors {white, black, light}; int std_colors[3]; /* Precasts: rtgplot.c */ void dump_data(data_t *); int populate(char *, void *, data_t **, graph_t *); void normalize(data_t *, graph_t *); void usage(char *); void dump_rate_stats(rate_t *); void plot_line(data_t *, gdImagePtr *, graph_t *, int, int); void plot_Nth(gdImagePtr *, graph_t *, data_t *); void create_graph(gdImagePtr *, graph_t *); void draw_grid(gdImagePtr *, graph_t *); void draw_border(gdImagePtr *, graph_t *); void draw_arrow(gdImagePtr *, graph_t *); void write_graph(gdImagePtr *, char *); void plot_scale(gdImagePtr *, graph_t *); void plot_labels(gdImagePtr *, graph_t *); /* void plot_legend(gdImagePtr *, rate_t, graph_t *, int, char *, int); */ void plot_legend(gdImagePtr *, graph_t *, legend_t *, int); void init_colors(gdImagePtr *, color_t **); void calculate_rate(data_t **, rate_t *, int); void calculate_total(data_t **, rate_t *, int); #ifdef HAVE_STRTOLL long long intSpeed(void *, int); #else long intSpeed(void *, int); #endif void sizeDefaults(graph_t *); int sizeImage(graph_t *); float cmp(data_t *, data_t *); data_t *sort_data(data_t *data, int is_circular, int is_double ); unsigned int count_data(data_t *); data_t *return_Nth(data_t *, int, int); void parseCmdLine(int, char **, arguments_t *, graph_t *); void parseWeb(arguments_t *, graph_t *); void dataAggr(data_t *, data_t *, rate_t *, rate_t *, graph_t *); char *file_timestamp(); /* REB - XXX NEW */ /* Precasts: rtgparse.c */ char *getField(char *c, char sep, char **result); void parse(char *string); data_obj_t *parseDO(char *string); void parseLOmod(char *string, line_obj_t **LOptr); void parseLODO(char *string, line_obj_t **LOptr); line_obj_t *parseLO(char *string); plot_obj_t *parsePO(char *string); void cgi_header(); void plotbail(char *s); void checkCount(count_t *c); void addDO(int pos, void *insert); void addLO(int pos, void *insert); void printPOs(); void printDOs(); void printLOs(); /* REB - XXX NEW */ #endif /* not _RTGPLOT_H_ */