1 /*****************************************************************************
2 * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010
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 #ifdef _MSC_VER
61 typedef int mode_t;
62 #define strtoll _strtoi64
63 #endif
64 typedef size_t ssize_t;
65 typedef long off_t;
66 #endif
68 #include <time.h>
69 #include <stdio.h> /* for FILE */
70 #include <string.h>
72 /* Formerly rrd_nan_inf.h */
73 #ifndef DNAN
74 # define DNAN rrd_set_to_DNAN()
75 #endif
77 #ifndef DINF
78 # define DINF rrd_set_to_DINF()
79 #endif
80 double rrd_set_to_DNAN(
81 void);
82 double rrd_set_to_DINF(
83 void);
84 /* end of rrd_nan_inf.h */
86 /* Transplanted from rrd_format.h */
87 typedef double rrd_value_t; /* the data storage type is
88 * double */
89 /* END rrd_format.h */
91 /* information about an rrd file */
92 typedef struct rrd_file_t {
93 size_t header_len; /* length of the header of this rrd file */
94 size_t file_len; /* total size of the rrd file */
95 size_t pos; /* current pos in file */
96 void *pvt;
97 } rrd_file_t;
99 /* information used for the conventional file access methods */
100 typedef struct rrd_simple_file_t {
101 int fd; /* file descriptor of this rrd file */
102 #ifdef HAVE_MMAP
103 char *file_start; /* start address of an open rrd file */
104 int mm_prot;
105 int mm_flags;
106 #endif
107 } rrd_simple_file_t;
109 /* rrd info interface */
110 typedef struct rrd_blob_t {
111 unsigned long size; /* size of the blob */
112 unsigned char *ptr; /* pointer */
113 } rrd_blob_t;
115 typedef enum rrd_info_type { RD_I_VAL = 0,
116 RD_I_CNT,
117 RD_I_STR,
118 RD_I_INT,
119 RD_I_BLO
120 } rrd_info_type_t;
122 typedef union rrd_infoval {
123 unsigned long u_cnt;
124 rrd_value_t u_val;
125 char *u_str;
126 int u_int;
127 rrd_blob_t u_blo;
128 } rrd_infoval_t;
130 typedef struct rrd_info_t {
131 char *key;
132 rrd_info_type_t type;
133 rrd_infoval_t value;
134 struct rrd_info_t *next;
135 } rrd_info_t;
137 typedef size_t (* rrd_output_callback_t)(
138 const void *,
139 size_t,
140 void *);
142 /* main function blocks */
143 int rrd_create(
144 int,
145 char **);
146 rrd_info_t *rrd_info(
147 int,
148 char **);
149 rrd_info_t *rrd_info_push(
150 rrd_info_t *,
151 char *,
152 rrd_info_type_t,
153 rrd_infoval_t);
154 void rrd_info_print(
155 rrd_info_t * data);
156 void rrd_info_free(
157 rrd_info_t *);
158 int rrd_update(
159 int,
160 char **);
161 rrd_info_t *rrd_update_v(
162 int,
163 char **);
164 int rrd_graph(
165 int,
166 char **,
167 char ***,
168 int *,
169 int *,
170 FILE *,
171 double *,
172 double *);
173 rrd_info_t *rrd_graph_v(
174 int,
175 char **);
177 int rrd_fetch(
178 int,
179 char **,
180 time_t *,
181 time_t *,
182 unsigned long *,
183 unsigned long *,
184 char ***,
185 rrd_value_t **);
186 int rrd_restore(
187 int,
188 char **);
189 int rrd_dump(
190 int,
191 char **);
192 int rrd_tune(
193 int,
194 char **);
195 time_t rrd_last(
196 int,
197 char **);
198 int rrd_lastupdate(int argc, char **argv);
199 time_t rrd_first(
200 int,
201 char **);
202 int rrd_resize(
203 int,
204 char **);
205 char *rrd_strversion(
206 void);
207 double rrd_version(
208 void);
209 int rrd_xport(
210 int,
211 char **,
212 int *,
213 time_t *,
214 time_t *,
215 unsigned long *,
216 unsigned long *,
217 char ***,
218 rrd_value_t **);
219 int rrd_flushcached (int argc, char **argv);
221 void rrd_freemem(
222 void *mem);
224 /* thread-safe (hopefully) */
225 int rrd_create_r(
226 const char *filename,
227 unsigned long pdp_step,
228 time_t last_up,
229 /* int no_overwrite, */
230 int argc,
231 const char **argv);
232 int rrd_create_r2(
233 const char *filename,
234 unsigned long pdp_step,
235 time_t last_up,
236 int no_overwrite,
237 int argc,
238 const char **argv);
239 rrd_info_t *rrd_info_r(
240 char *);
241 /* NOTE: rrd_update_r and rrd_update_v_r are only thread-safe if no at-style
242 time specifications get used!!! */
244 int rrd_update_r(
245 const char *filename,
246 const char *_template,
247 int argc,
248 const char **argv);
249 int rrd_update_v_r(
250 const char *filename,
251 const char *_template,
252 int argc,
253 const char **argv,
254 rrd_info_t * pcdp_summary);
255 int rrd_fetch_r (
256 const char *filename,
257 const char *cf,
258 time_t *start,
259 time_t *end,
260 unsigned long *step,
261 unsigned long *ds_cnt,
262 char ***ds_namv,
263 rrd_value_t **data);
264 int rrd_dump_r(
265 const char *filename,
266 char *outname);
267 time_t rrd_last_r (const char *filename);
268 int rrd_lastupdate_r (const char *filename,
269 time_t *ret_last_update,
270 unsigned long *ret_ds_count,
271 char ***ret_ds_names,
272 char ***ret_last_ds);
273 time_t rrd_first_r(
274 const char *filename,
275 int rraindex);
277 int rrd_dump_cb_r(
278 const char *filename,
279 int opt_header,
280 rrd_output_callback_t cb,
281 void *user);
283 /* Transplanted from rrd_parsetime.h */
284 typedef enum {
285 ABSOLUTE_TIME,
286 RELATIVE_TO_START_TIME,
287 RELATIVE_TO_END_TIME,
288 RELATIVE_TO_EPOCH
289 } rrd_timetype_t;
291 #define TIME_OK NULL
293 typedef struct rrd_time_value {
294 rrd_timetype_t type;
295 long offset;
296 struct tm tm;
297 } rrd_time_value_t;
299 char *rrd_parsetime(
300 const char *spec,
301 rrd_time_value_t * ptv);
302 /* END rrd_parsetime.h */
304 typedef struct rrd_context {
305 char lib_errstr[256];
306 char rrd_error[4096];
307 } rrd_context_t;
309 /* returns the current per-thread rrd_context */
310 rrd_context_t *rrd_get_context(void);
312 #ifdef WIN32
313 /* this was added by the win32 porters Christof.Wegmann@exitgames.com */
314 rrd_context_t *rrd_force_new_context(void);
315 #endif
317 int rrd_proc_start_end(
318 rrd_time_value_t *,
319 rrd_time_value_t *,
320 time_t *,
321 time_t *);
323 /* HELPER FUNCTIONS */
324 void rrd_set_error(
325 char *,
326 ...);
327 void rrd_clear_error(
328 void);
329 int rrd_test_error(
330 void);
331 char *rrd_get_error(
332 void);
334 /* rrd_strerror is thread safe, but still it uses a global buffer
335 (but one per thread), thus subsequent calls within a single
336 thread overwrite the same buffer */
337 const char *rrd_strerror(
338 int err);
340 /** MULTITHREADED HELPER FUNCTIONS */
341 rrd_context_t *rrd_new_context(
342 void);
343 void rrd_free_context(
344 rrd_context_t * buf);
346 /* void rrd_set_error_r (rrd_context_t *, char *, ...); */
347 /* void rrd_clear_error_r(rrd_context_t *); */
348 /* int rrd_test_error_r (rrd_context_t *); */
349 /* char *rrd_get_error_r (rrd_context_t *); */
351 /** UTILITY FUNCTIONS */
353 long rrd_random(void);
355 int rrd_add_ptr_chunk(void ***dest, size_t *dest_size, void *src,
356 size_t *alloc, size_t chunk);
357 int rrd_add_ptr(void ***dest, size_t *dest_size, void *src);
358 int rrd_add_strdup(char ***dest, size_t *dest_size, char *src);
359 int rrd_add_strdup_chunk(char ***dest, size_t *dest_size, char *src,
360 size_t *alloc, size_t chunk);
361 void rrd_free_ptrs(void ***src, size_t *cnt);
363 int rrd_mkdir_p(const char *pathname, mode_t mode);
365 /*
366 * The following functions are _internal_ functions needed to read the raw RRD
367 * files. Since they are _internal_ they may change with the file format and
368 * will be replaced with a more general interface in RRDTool 1.4. Don't use
369 * these functions unless you have good reasons to do so. If you do use these
370 * functions you will have to adapt your code for RRDTool 1.4!
371 *
372 * To enable the deprecated functions define `RRD_EXPORT_DEPRECATED' before
373 * including <rrd_test.h>. You have been warned! If you come back to the
374 * RRDTool mailing list and whine about your broken application, you will get
375 * hit with something smelly!
376 */
377 #if defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED)
379 # if defined(_RRD_TOOL_H)
380 # include "rrd_format.h"
381 # else
382 # include <rrd_format.h>
383 # endif
385 #if defined(__GNUC__) && defined (RRD_EXPORT_DEPRECATED)
386 # define RRD_DEPRECATED __attribute__((deprecated))
387 #else
388 # define RRD_DEPRECATED /**/
389 #endif
390 void rrd_free(
391 rrd_t *rrd)
392 RRD_DEPRECATED;
393 void rrd_init(
394 rrd_t *rrd)
395 RRD_DEPRECATED;
397 rrd_file_t *rrd_open(
398 const char *const file_name,
399 rrd_t *rrd,
400 unsigned rdwr)
401 RRD_DEPRECATED;
403 void rrd_dontneed(
404 rrd_file_t *rrd_file,
405 rrd_t *rrd)
406 RRD_DEPRECATED;
407 int rrd_close(
408 rrd_file_t *rrd_file)
409 RRD_DEPRECATED;
410 ssize_t rrd_read(
411 rrd_file_t *rrd_file,
412 void *buf,
413 size_t count)
414 RRD_DEPRECATED;
415 ssize_t rrd_write(
416 rrd_file_t *rrd_file,
417 const void *buf,
418 size_t count)
419 RRD_DEPRECATED;
420 void rrd_flush(
421 rrd_file_t *rrd_file)
422 RRD_DEPRECATED;
423 off_t rrd_seek(
424 rrd_file_t *rrd_file,
425 off_t off,
426 int whence)
427 RRD_DEPRECATED;
428 off_t rrd_tell(
429 rrd_file_t *rrd_file)
430 RRD_DEPRECATED;
431 int rrd_lock(
432 rrd_file_t *file)
433 RRD_DEPRECATED;
434 void rrd_notify_row(
435 rrd_file_t *rrd_file,
436 int rra_idx,
437 unsigned long rra_row,
438 time_t rra_time)
439 RRD_DEPRECATED;
440 unsigned long rrd_select_initial_row(
441 rrd_file_t *rrd_file,
442 int rra_idx,
443 rra_def_t *rra
444 )
445 RRD_DEPRECATED;
446 #endif /* defined(_RRD_TOOL_H) || defined(RRD_EXPORT_DEPRECATED) */
448 #endif /* _RRDLIB_H */
450 #ifdef __cplusplus
451 }
452 #endif