Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
[rrdtool.git] / src / rrd_tool.h
1 /*****************************************************************************
2  * RRDtool 1.0.33  Copyright Tobias Oetiker, 1997 - 2000
3  *****************************************************************************
4  * rrd_tool.h   Common Header File
5  *****************************************************************************
6  * $Id$
7  * $Log$
8  * Revision 1.2  2001/03/04 13:01:55  oetiker
9  * Aberrant Behavior Detection support. A brief overview added to rrdtool.pod.
10  * Major updates to rrd_update.c, rrd_create.c. Minor update to other core files.
11  * This is backwards compatible! But new files using the Aberrant stuff are not readable
12  * by old rrdtool versions. See http://cricket.sourceforge.net/aberrant/rrd_hw.htm
13  * -- Jake Brutlag <jakeb@corp.webtv.net>
14  *
15  * Revision 1.1.1.1  2001/02/25 22:25:06  oetiker
16  * checkin
17  *
18  *****************************************************************************/
19 #ifdef  __cplusplus
20 extern "C" {
21 #endif
22
23
24 #ifndef _RRD_TOOL_H
25 #define _RRD_TOOL_H
26
27 #ifdef WIN32
28 # include "ntconfig.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33 #endif
34
35 #ifdef MUST_DISABLE_SIGFPE
36 #include <signal.h>
37 #endif
38
39 #ifdef MUST_DISABLE_FPMASK
40 #include <floatingpoint.h>
41 #endif
42     
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <string.h>
47 #include <time.h>
48 #include <ctype.h>
49
50 #if HAVE_SYS_PARAM_H
51 #  include <sys/param.h>
52 #endif
53
54 #ifndef MAXPATH
55 #  define MAXPATH 1024
56 #endif
57
58 #if HAVE_MATH_H
59 # include <math.h>
60 #endif
61 #if HAVE_UNISTD_H
62 # include <unistd.h>
63 #endif
64 #if HAVE_SYS_TIME_H
65 # include <sys/time.h>
66 #endif
67 #if HAVE_SYS_TIMES_H
68 # include <sys/times.h>
69 #endif
70 #if HAVE_SYS_RESOURCE_H
71 # include <sys/resource.h>
72 #if (defined(__svr4__) && defined(__sun__))
73 /* Solaris headers (pre 2.6) don't have a getrusage prototype.
74    Use this instead. */
75 extern int getrusage(int, struct rusage *);
76 #endif /* __svr4__ && __sun__ */
77 #endif
78
79 #include "rrd.h"
80
81 #ifndef WIN32
82
83 /* unix-only includes */
84 #ifndef isnan
85 int isnan(double value);
86 #endif
87
88 #else
89
90 /* Win32 only includes */
91
92 #include <float.h>        /* for _isnan  */
93 #define isnan _isnan
94 #define finite _finite
95 #define isinf(a) (_fpclass(a) == _FPCLASS_NINF || _fpclass(a) == _FPCLASS_PINF)
96 #endif
97
98 /* local include files -- need to be after the system ones */
99 #include "getopt.h"
100 #include "rrd_format.h"
101
102 #ifndef max
103 #define max(a,b) ((a) > (b) ? (a) : (b))
104 #endif
105
106 #ifndef min
107 #define min(a,b) ((a) < (b) ? (a) : (b))
108 #endif                                                   
109
110 #define DIM(x) (sizeof(x)/sizeof(x[0]))
111
112 /* rrd info interface */
113 enum info_type   { RD_I_VAL=0,
114                RD_I_CNT,
115                RD_I_STR  };
116
117 typedef union infoval { 
118     unsigned long u_cnt; 
119     rrd_value_t   u_val;
120     char         *u_str;
121 } infoval;
122
123 typedef struct info_t {
124     char            *key;
125     enum info_type  type;
126     union infoval   value;
127     struct info_t   *next;
128 } info_t;
129
130
131 info_t *rrd_info(int, char **);
132
133 /* HELPER FUNCTIONS */
134 int GifSize(FILE *, long *, long *);
135 int PngSize(FILE *, long *, long *);
136 int PngSize(FILE *, long *, long *);
137
138 #include <gd.h>
139 void gdImagePng(gdImagePtr im, FILE *out);
140
141 int rrd_create_fn(char *file_name, rrd_t *rrd);
142 int rrd_fetch_fn(char *filename, enum cf_en cf_idx,
143                  time_t *start,time_t *end,
144                  unsigned long *step,
145                  unsigned long *ds_cnt,
146                  char        ***ds_namv,
147                  rrd_value_t **data);
148
149 void rrd_free(rrd_t *rrd);
150 void rrd_init(rrd_t *rrd);
151
152 int rrd_open(char *file_name, FILE **in_file, rrd_t *rrd, int rdwr);
153 int readfile(char *file, char **buffer, int skipfirst);
154
155 #define RRD_READONLY    0
156 #define RRD_READWRITE   1
157
158 enum cf_en cf_conv(char *string);
159 enum dst_en dst_conv(char *string);
160 long ds_match(rrd_t *rrd,char *ds_nam);
161 double rrd_diff(char *a, char *b);
162
163 /* functions added for aberrant behavior detection.
164  * implemented for the most part in rrd_hw.c */
165 int update_aberrant_CF(rrd_t *rrd, rrd_value_t pdp_val, enum cf_en current_cf,
166    unsigned long cdp_idx, unsigned long rra_idx, unsigned long ds_idx,
167    unsigned short CDP_scratch_idx, rrd_value_t *seasonal_coef);
168 int create_hw_contingent_rras(rrd_t *rrd, unsigned short period, 
169    unsigned long hashed_name);
170 int lookup_seasonal(rrd_t *rrd, unsigned long rra_idx, unsigned long rra_start,
171    FILE *rrd_file, unsigned long offset, rrd_value_t **seasonal_coef);
172 void erase_violations(rrd_t *rrd, unsigned long cdp_idx, unsigned long rra_idx);
173 int apply_smoother(rrd_t *rrd, unsigned long rra_idx, unsigned long rra_start,
174    FILE *rrd_file);
175
176 /* a standard fixed-capacity FIFO queue implementation */
177 typedef struct FIFOqueue {
178    rrd_value_t *queue;
179    int capacity, head, tail;
180 } FIFOqueue;
181
182 int queue_alloc(FIFOqueue **q,int capacity);
183 void queue_dealloc(FIFOqueue *q);
184 void queue_push(FIFOqueue *q, rrd_value_t value);
185 int queue_isempty(FIFOqueue *q);
186 rrd_value_t queue_pop(FIFOqueue *q);
187
188 #define BURNIN_CYCLES 3
189
190 #endif
191
192
193 #ifdef  __cplusplus
194 }
195 #endif