24
#include <sys/types.h>
27
#if TIME_WITH_SYS_TIME
28
# include <sys/time.h>
32
# include <sys/time.h>
39
# include <sys/socket.h>
43
# include <netinet/in.h>
47
# include <arpa/inet.h>
56
# include "pcre_cpp_wrapper.h"
61
#include <readline/readline.h>
62
#include <readline/history.h>
64
/* Use kqueue in preference to anything else.
65
* If we don't have that, try FAM
66
* If we don't have FAM, fall back to stat()
68
#define USING_KQUEUE 1
72
# include <sys/event.h>
73
# define POLLING_METHOD USING_KQUEUE
76
# define POLLING_METHOD USING_FAM
80
#ifndef POLLING_METHOD
81
# define POLLING_METHOD USING_STAT
89
#define getMIN(a,b) (a < b ? a : b)
90
#define getMAX(a,b) (a > b ? a : b)
93
# define MAXPATHLEN 128
96
/* upon startup, each input file is put into an element of this array,
97
* starting at 0. The struct under this maps the current fd into this array
98
* so we can find it without iterating.
104
short type; /* types defined in log.h */
107
/* if open == false, then ApacheTop will periodically try to re-open
108
* this input file. */
109
bool open; /* is the file open or not? */
111
#if (POLLING_METHOD == USING_FAM)
119
#define SORT_REQCOUNT 1
120
#define SORT_REQPERSEC 2
121
#define SORT_BYTECOUNT 3
122
#define SORT_BYTESPERSEC 4
123
#define SORT_2XX 12 /* see display.cc around line 911 (shellsort) */
124
#define SORT_3XX 13 /* for the consequences of changing these. */
125
#define SORT_4XX 14 /* Logic there relies on them being */
126
#define SORT_5XX 15 /* (retcode/100)+SORTTYPE_OFFSET_HACK */
127
#define SORTTYPE_OFFSET_HACK 10
128
short sort, retcodes_sort;
133
short selected_item_screen; /* screen position our marker is at */
134
unsigned int selected_item_pos; /* which url/ip/refpos it relates to */
135
short selected_item_mode; /* is it url/ip/ref pos? */
136
unsigned int selected_item_hash;
138
short current_display_size; /* how many lines we're displaying */
142
#define TIMED_CIRCLE 'T'
143
#define HITS_CIRCLE 'H'
147
/* these defines are used in cf.filter too */
148
#define DISPLAY_URLS 1
149
#define DISPLAY_HOSTS 2
150
#define DISPLAY_REFS 3
151
#define DISPLAY_FILES 4
152
#define DISPLAY_DETAIL 9
155
#define NUMBERS_HITS_BYTES 1
156
#define NUMBERS_RETCODES 2
159
/* when in DISPLAY_DETAIL mode, display_mode is copied in here */
160
short display_mode_detail;
161
/* what would we like to display in DISPLAY_DETAIL modes? */
162
bool detail_display_hosts, detail_display_refs, detail_display_urls;
165
bool do_immed_display; /* signals a screen update is req'd */
168
Filter *urlfilter, *hostfilter, *reffilter;
171
bool keep_querystring;
173
unsigned short keep_segments;
174
bool preserve_ref_protocol;
178
bool exit; /* true when we want to finish */
180
/* keypress submenu */
181
#define SUBMENU_NONE 0
183
#define SUBMENU_SORT_HB 1
184
#define SUBMENU_SORT_RC 2
186
#define SUBMENU_DISP 4
188
#define SUBMENU_FILT 5
189
#define SUBMENU_FILT_ADD 6
190
#define SUBMENU_FILT_SHOW 7
192
#define SUBMENU_HELP 9
193
unsigned short in_submenu;
194
bool in_submenu_stay; /* stay in submenu till keypress? */
195
time_t in_submenu_time;
204
/* for stats worked out in display.cc */
209
time_t start; /* when did we start */
211
/* space for 1xx-5xx return codes */
212
struct hitinfo r_codes[6];
214
/* space for counting global hits and bytes per sec */
215
struct hitinfo alltime;
222
# include "resolver.h"
227
#include "hits_circle.h"
228
#include "timed_circle.h"
247
#define DEBUG_OUTPUT "/tmp/atop.debug"
249
/* this can be overridden from config.h via ./configure --with-logfile .. */
250
#ifndef DEFAULT_LOGFILE
251
# define DEFAULT_LOGFILE "/var/httpd/apache_log"
253
#define DEFAULT_CIRCLE_SIZE 30
254
#define DEFAULT_CIRCLE_MODE TIMED_CIRCLE
255
#define DEFAULT_SORT SORT_REQCOUNT
256
#define DEFAULT_RETCODES_SORT SORT_2XX
257
#define DEFAULT_REFRESH_DELAY 5
258
#define DEFAULT_DISPLAY_MODE DISPLAY_URLS
259
#define DEFAULT_NUMBERS_MODE NUMBERS_HITS_BYTES
261
/* if the layout of the display changes, these need updating */
262
#define COLS_RESERVED 25
263
#define LINES_RESERVED 7
265
#define MAX_INPUT_FILES 50
267
int recordstats(struct logbits l);
269
int read_key(int ch);
271
#define SEEK_TO_END true
272
#define NO_SEEK_TO_END false
273
int new_file(char *filename, bool do_seek_to_end);
276
int dprintf(const char *fmt, ...);
278
static void catchsig(int s);
279
static void catchwinch(int s);