1 /*****************************************************************************
2 * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008
3 *****************************************************************************
4 * rrdlib.h Public header file for librrd
5 *****************************************************************************
6 * $Id$
7 * $Log$
8 * Revision 1.9 2005/02/13 16:13:33 oetiker
9 * let rrd_graph return the actual value range it picked ...
10 * -- Henrik Stoerner <henrik@hswn.dk>
11 *
12 * Revision 1.8 2004/05/26 22:11:12 oetiker
13 * reduce compiler warnings. Many small fixes. -- Mike Slifcak <slif@bellsouth.net>
14 *
15 * Revision 1.7 2003/11/12 22:14:26 oetiker
16 * allow to pass an open filehandle into rrd_graph as an extra argument
17 *
18 * Revision 1.6 2003/11/11 19:46:21 oetiker
19 * replaced time_value with rrd_time_value as MacOS X introduced a struct of that name in their standard headers
20 *
21 * Revision 1.5 2003/04/25 18:35:08 jake
22 * Alternate update interface, updatev. Returns info about CDPs written to disk as result of update. Output format is similar to rrd_info, a hash of key-values.
23 *
24 * Revision 1.4 2003/04/01 22:52:23 jake
25 * Fix Win32 build. VC++ 6.0 and 7.0 now use the thread-safe code.
26 *
27 * Revision 1.3 2003/02/13 07:05:27 oetiker
28 * Find attached the patch I promised to send to you. Please note that there
29 * are three new source files (src/rrd_is_thread_safe.h, src/rrd_thread_safe.c
30 * and src/rrd_not_thread_safe.c) and the introduction of librrd_th. This
31 * library is identical to librrd, but it contains support code for per-thread
32 * global variables currently used for error information only. This is similar
33 * to how errno per-thread variables are implemented. librrd_th must be linked
34 * alongside of libpthred
35 *
36 * There is also a new file "THREADS", holding some documentation.
37 *
38 * -- Peter Stamfest <peter@stamfest.at>
39 *
40 * Revision 1.2 2002/05/07 21:58:32 oetiker
41 * new command rrdtool xport integrated
42 * -- Wolfgang Schrimm <Wolfgang.Schrimm@urz.uni-heidelberg.de>
43 *
44 * Revision 1.1.1.1 2001/02/25 22:25:05 oetiker
45 * checkin
46 *
47 *****************************************************************************/
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
52 #ifndef _RRDLIB_H
53 #define _RRDLIB_H
55 #include <sys/types.h> /* for off_t */
57 #ifndef WIN32
58 #include <unistd.h> /* for off_t */
59 #else
60 typedef size_t ssize_t;
61 typedef long off_t;
62 #endif
64 #include <time.h>
65 #include <stdio.h> /* for FILE */
66 #include <string.h>
68 /* Formerly rrd_nan_inf.h */
69 #ifndef DNAN
70 # define DNAN rrd_set_to_DNAN()
71 #endif
73 #ifndef DINF
74 # define DINF rrd_set_to_DINF()
75 #endif
76 double rrd_set_to_DNAN(
77 void);
78 double rrd_set_to_DINF(
79 void);
80 /* end of rrd_nan_inf.h */
82 /* Transplanted from rrd_format.h */
83 typedef double rrd_value_t; /* the data storage type is
84 * double */
85 /* END rrd_format.h */
87 /* information about an rrd file */
88 typedef struct rrd_file_t {
89 size_t header_len; /* length of the header of this rrd file */
90 size_t file_len; /* total size of the rrd file */
91 size_t pos; /* current pos in file */
92 void *pvt;
93 } rrd_file_t;
95 /* information used for the conventional file access methods */
96 typedef struct rrd_simple_file_t {
97 int fd; /* file descriptor of this rrd file */
98 #ifdef HAVE_MMAP
99 char *file_start; /* start address of an open rrd file */
100 int mm_prot;
101 int mm_flags;
102 #endif
103 } rrd_simple_file_t;
105 /* rrd info interface */
106 typedef struct rrd_blob_t {
107 unsigned long size; /* size of the blob */
108 unsigned char *ptr; /* pointer */
109 } rrd_blob_t;
111 typedef enum rrd_info_type { RD_I_VAL = 0,
112 RD_I_CNT,
113 RD_I_STR,
114 RD_I_INT,
115 RD_I_BLO
116 } rrd_info_type_t;
118 typedef union rrd_infoval {
119 unsigned long u_cnt;
120 rrd_value_t u_val;
121 char *u_str;
122 int u_int;
123 rrd_blob_t u_blo;
124 } rrd_infoval_t;
126 typedef struct rrd_info_t {
127 char *key;
128 rrd_info_type_t type;
129 rrd_infoval_t value;
130 struct rrd_info_t *next;
131 } rrd_info_t;
134 /* main function blocks */
135 int rrd_create(
136 int,
137 char **);
138 rrd_info_t *rrd_info(
139 int,
140 char **);
141 rrd_info_t *rrd_info_push(
142 rrd_info_t *,
143 char *,
144 rrd_info_type_t,
145 rrd_infoval_t);
146 void rrd_info_print(
147 rrd_info_t * data);
148 void rrd_info_free(
149 rrd_info_t *);
150 int rrd_update(
151 int,
152 char **);
153 rrd_info_t *rrd_update_v(
154 int,
155 char **);
156 int rrd_graph(
157 int,
158 char **,
159 char ***,
160 int *,
161 int *,
162 FILE *,
163 double *,
164 double *);
165 rrd_info_t *rrd_graph_v(
166 int,
167 char **);
169 int rrd_fetch(
170 int,
171 char **,
172 time_t *,
173 time_t *,
174 unsigned long *,
175 unsigned long *,
176 char ***,
177 rrd_value_t **);
178 int rrd_restore(
179 int,
180 char **);
181 int rrd_dump(
182 int,
183 char **);
184 int rrd_tune(
185 int,
186 char **);
187 time_t rrd_last(
188 int,
189 char **);
190 int rrd_lastupdate(int argc, char **argv);
191 time_t rrd_first(
192 int,
193 char **);
194 int rrd_resize(
195 int,
196 char **);
197 char *rrd_strversion(
198 void);
199 double rrd_version(
200 void);
201 int rrd_xport(
202 int,
203 char **,
204 int *,
205 time_t *,
206 time_t *,
207 unsigned long *,
208 unsigned long *,
209 char ***,
210 rrd_value_t **);
211 int rrd_cmd_flush (int argc, char **argv);
213 void rrd_freemem(
214 void *mem);
216 /* thread-safe (hopefully) */
217 int rrd_create_r(
218 const char *filename,
219 unsigned long pdp_step,
220 time_t last_up,
221 int argc,
222 const char **argv);
223 rrd_info_t *rrd_info_r(
224 char *);
225 /* NOTE: rrd_update_r are only thread-safe if no at-style time
226 specifications get used!!! */
228 int rrd_update_r(
229 const char *filename,
230 const char *_template,
231 int argc,
232 const char **argv);
233 int rrd_fetch_r (
234 const char *filename,
235 const char *cf,
236 time_t *start,
237 time_t *end,
238 unsigned long *step,
239 unsigned long *ds_cnt,
240 char ***ds_namv,
241 rrd_value_t **data);
242 int rrd_dump_r(
243 const char *filename,
244 char *outname);
245 time_t rrd_last_r (const char *filename);
246 int rrd_lastupdate_r (const char *filename,
247 time_t *ret_last_update,
248 unsigned long *ret_ds_count,
249 char ***ret_ds_names,
250 char ***ret_last_ds);
251 time_t rrd_first_r(
252 const char *filename,
253 int rraindex);
255 /* Transplanted from rrd_parsetime.h */
256 typedef enum {
257 ABSOLUTE_TIME,
258 RELATIVE_TO_START_TIME,
259 RELATIVE_TO_END_TIME
260 } rrd_timetype_t;
262 #define TIME_OK NULL
264 typedef struct rrd_time_value {
265 rrd_timetype_t type;
266 long offset;
267 struct tm tm;
268 } rrd_time_value_t;
270 char *rrd_parsetime(
271 const char *spec,
272 rrd_time_value_t * ptv);
273 /* END rrd_parsetime.h */
275 typedef struct rrd_context {
276 char lib_errstr[256];
277 char rrd_error[4096];
278 } rrd_context_t;
280 /* returns the current per-thread rrd_context */
281 rrd_context_t *rrd_get_context(void);
283 #ifdef WIN32
284 /* this was added by the win32 porters Christof.Wegmann@exitgames.com */
285 rrd_context_t *rrd_force_new_context(void);
287 int rrd_proc_start_end(
288 rrd_time_value_t *,
289 rrd_time_value_t *,
290 time_t *,
291 time_t *);
292 #endif
294 /* HELPER FUNCTIONS */
295 void rrd_set_error(
296 char *,
297 ...);
298 void rrd_clear_error(
299 void);
300 int rrd_test_error(
301 void);
302 char *rrd_get_error(
303 void);
305 /* rrd_strerror is thread safe, but still it uses a global buffer
306 (but one per thread), thus subsequent calls within a single
307 thread overwrite the same buffer */
308 const char *rrd_strerror(
309 int err);
311 /** MULTITHREADED HELPER FUNCTIONS */
312 rrd_context_t *rrd_new_context(
313 void);
314 void rrd_free_context(
315 rrd_context_t * buf);
317 /* void rrd_set_error_r (rrd_context_t *, char *, ...); */
318 /* void rrd_clear_error_r(rrd_context_t *); */
319 /* int rrd_test_error_r (rrd_context_t *); */
320 /* char *rrd_get_error_r (rrd_context_t *); */
322 /*
323 * The following functions are _internal_ functions needed to read the raw RRD
324 * files. Since they are _internal_ they may change with the file format and
325 * will be replaced with a more general interface in RRDTool 1.4. Don't use
326 * these functions unless you have good reasons to do so. If you do use these
327 * functions you will have to adapt your code for RRDTool 1.4!
328 *
329 * To enable the deprecated functions define `RRD_EXPORT_DEPRECATED' before
330 * including <rrd_test.h>. You have been warned! If you come back to the
331 * RRDTool mailing list and whine about your broken application, you will get
332 * hit with something smelly!
333 */
334 #if defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED)
336 # if defined(_RRD_TOOL_H)
337 # include "rrd_format.h"
338 # else
339 # include <rrd_format.h>
340 # endif
342 #if defined(__GNUC__) && defined (RRD_EXPORT_DEPRECATED)
343 # define RRD_DEPRECATED __attribute__((deprecated))
344 #else
345 # define RRD_DEPRECATED /**/
346 #endif
347 void rrd_free(
348 rrd_t *rrd)
349 RRD_DEPRECATED;
350 void rrd_init(
351 rrd_t *rrd)
352 RRD_DEPRECATED;
354 rrd_file_t *rrd_open(
355 const char *const file_name,
356 rrd_t *rrd,
357 unsigned rdwr)
358 RRD_DEPRECATED;
360 void rrd_dontneed(
361 rrd_file_t *rrd_file,
362 rrd_t *rrd)
363 RRD_DEPRECATED;
364 int rrd_close(
365 rrd_file_t *rrd_file)
366 RRD_DEPRECATED;
367 ssize_t rrd_read(
368 rrd_file_t *rrd_file,
369 void *buf,
370 size_t count)
371 RRD_DEPRECATED;
372 ssize_t rrd_write(
373 rrd_file_t *rrd_file,
374 const void *buf,
375 size_t count)
376 RRD_DEPRECATED;
377 void rrd_flush(
378 rrd_file_t *rrd_file)
379 RRD_DEPRECATED;
380 off_t rrd_seek(
381 rrd_file_t *rrd_file,
382 off_t off,
383 int whence)
384 RRD_DEPRECATED;
385 off_t rrd_tell(
386 rrd_file_t *rrd_file)
387 RRD_DEPRECATED;
388 int rrd_lock(
389 rrd_file_t *file)
390 RRD_DEPRECATED;
391 void rrd_notify_row(
392 rrd_file_t *rrd_file,
393 int rra_idx,
394 unsigned long rra_row,
395 time_t rra_time)
396 RRD_DEPRECATED;
397 unsigned long rrd_select_initial_row(
398 rrd_file_t *rrd_file,
399 int rra_idx,
400 rra_def_t *rra
401 )
402 RRD_DEPRECATED;
403 #endif /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
405 #endif /* _RRDLIB_H */
407 #ifdef __cplusplus
408 }
409 #endif