]> git.itanic.dy.fi Git - rrdd/blob - database.h
rrdtool: Add pre_draw_cmd
[rrdd] / database.h
1 #ifndef _TESTDATA_H
2 #define _TESTDATA_H
3
4 #include "rrdtool.h"
5 #include "parser.h"
6
7 const char blank[] = "COMMENT:       ";
8 #define numfmt " % 8.2lf "
9
10 #define SYSINFO_PATH            "./"
11 #define SYSINFO_RRD_PATH        SYSINFO_PATH "sysinfo.rrd"
12 #define SYSINFO_IMAGES_PATH     SYSINFO_PATH "images/"
13
14 #define SYSTEMP_RRD_PATH        "/root/systemp/systemp.rrd"
15
16 #define NETWORK_RRD_PATH        SYSINFO_PATH "network.rrd"
17
18 const char *cputext[] = {
19         "DEF:us=" SYSINFO_RRD_PATH ":User:AVERAGE",
20         "DEF:ni=" SYSINFO_RRD_PATH ":Nice:AVERAGE",
21         "DEF:sy=" SYSINFO_RRD_PATH ":Sys:AVERAGE",
22         "DEF:id=" SYSINFO_RRD_PATH ":Idle:AVERAGE",
23         "DEF:wa=" SYSINFO_RRD_PATH ":Wait:AVERAGE",
24         "DEF:in=" SYSINFO_RRD_PATH ":IRQ:AVERAGE",
25         "DEF:so=" SYSINFO_RRD_PATH ":SoftIRQ:AVERAGE",
26         "COMMENT:\\n",
27         blank,
28         "COMMENT:                   "
29         "MIN          MAX         AVG        Last\\n",
30         blank,
31         "AREA:sy#ff0000:System   ",
32         "GPRINT:sy:MIN:" numfmt,
33         "GPRINT:sy:MAX:" numfmt,
34         "GPRINT:sy:AVERAGE:" numfmt,
35         "GPRINT:sy:LAST:" numfmt "\\n",
36         blank,
37         "STACK:us#0000ff:User     ",
38         "GPRINT:us:MIN:" numfmt,
39         "GPRINT:us:MAX:" numfmt,
40         "GPRINT:us:AVERAGE:" numfmt,
41         "GPRINT:us:LAST:" numfmt "\\n",
42         blank,
43         "STACK:ni#00ff00:Nice     ",
44         "GPRINT:ni:MIN:" numfmt,
45         "GPRINT:ni:MAX:" numfmt,
46         "GPRINT:ni:AVERAGE:" numfmt,
47         "GPRINT:ni:LAST:" numfmt "\\n",
48         blank,
49         "STACK:id#ffffff:Idle     ",
50         "GPRINT:id:MIN:" numfmt,
51         "GPRINT:id:MAX:" numfmt,
52         "GPRINT:id:AVERAGE:" numfmt,
53         "GPRINT:id:LAST:" numfmt "\\n",
54         blank,
55         "STACK:wa#ff00ff:IO wait  ",
56         "GPRINT:wa:MIN:" numfmt,
57         "GPRINT:wa:MAX:" numfmt,
58         "GPRINT:wa:AVERAGE:" numfmt,
59         "GPRINT:wa:LAST:" numfmt "\\n",
60         blank,
61         "STACK:in#ffff00:IRQ      ",
62         "GPRINT:in:MIN:" numfmt,
63         "GPRINT:in:MAX:" numfmt,
64         "GPRINT:in:AVERAGE:" numfmt,
65         "GPRINT:in:LAST:" numfmt "\\n",
66         blank,
67         "STACK:so#00ffff:Soft IRQ ",
68         "GPRINT:so:MIN:" numfmt,
69         "GPRINT:so:MAX:" numfmt,
70         "GPRINT:so:AVERAGE:" numfmt,
71         "GPRINT:so:LAST:" numfmt "\\n",
72         "COMMENT: \\n",
73         0
74 };
75
76 const char *memtext[] = {
77         "DEF:fr=" SYSINFO_RRD_PATH ":Free:AVERAGE",
78         "DEF:bu=" SYSINFO_RRD_PATH ":Buffers:AVERAGE",
79         "DEF:ca=" SYSINFO_RRD_PATH ":Cached:AVERAGE",
80         "DEF:an=" SYSINFO_RRD_PATH ":Anon:AVERAGE",
81         "DEF:sl=" SYSINFO_RRD_PATH ":Slab:AVERAGE",
82         "DEF:ta=" SYSINFO_RRD_PATH ":Tables:AVERAGE",
83         "DEF:ot=" SYSINFO_RRD_PATH ":Other:AVERAGE",
84         "DEF:sw=" SYSINFO_RRD_PATH ":Swap:AVERAGE",
85         "COMMENT:\\n",
86         blank,
87         "COMMENT:                     "
88         "MIN          MAX         AVG        Last\\n",
89         blank,
90         "AREA:bu#ffff00:Buffers    ",
91         "GPRINT:bu:MIN:" numfmt,
92         "GPRINT:bu:MAX:" numfmt,
93         "GPRINT:bu:AVERAGE:" numfmt,
94         "GPRINT:bu:LAST:" numfmt "\\n",
95         blank,
96         "STACK:an#000000:AnonPages  ",
97         "GPRINT:an:MIN:" numfmt,
98         "GPRINT:an:MAX:" numfmt,
99         "GPRINT:an:AVERAGE:" numfmt,
100         "GPRINT:an:LAST:" numfmt "\\n",
101         blank,
102         "STACK:ca#00ff00:Cached     ",
103         "GPRINT:ca:MIN:" numfmt,
104         "GPRINT:ca:MAX:" numfmt,
105         "GPRINT:ca:AVERAGE:" numfmt,
106         "GPRINT:ca:LAST:" numfmt "\\n",
107         blank,
108         "STACK:fr#ffffff:Free       ",
109         "GPRINT:fr:MIN:" numfmt,
110         "GPRINT:fr:MAX:" numfmt,
111         "GPRINT:fr:AVERAGE:" numfmt,
112         "GPRINT:fr:LAST:" numfmt "\\n",
113         blank,
114         "STACK:sl#00ffff:Slab       ",
115         "GPRINT:sl:MIN:" numfmt,
116         "GPRINT:sl:MAX:" numfmt,
117         "GPRINT:sl:AVERAGE:" numfmt,
118         "GPRINT:sl:LAST:" numfmt "\\n",
119         blank,
120         "STACK:ta#0000ff:PageTables ",
121         "GPRINT:ta:MIN:" numfmt,
122         "GPRINT:ta:MAX:" numfmt,
123         "GPRINT:ta:AVERAGE:" numfmt,
124         "GPRINT:ta:LAST:" numfmt "\\n",
125         blank,
126         "STACK:ot#a0a0a0:Other      ",
127         "GPRINT:ot:MIN:" numfmt,
128         "GPRINT:ot:MAX:" numfmt,
129         "GPRINT:ot:AVERAGE:" numfmt,
130         "GPRINT:ot:LAST:" numfmt "\\n",
131         blank,
132         "STACK:sw#ff0000:Swap       ",
133         "GPRINT:sw:MIN:" numfmt,
134         "GPRINT:sw:MAX:" numfmt,
135         "GPRINT:sw:AVERAGE:" numfmt,
136         "GPRINT:sw:LAST:" numfmt "\\n",
137         "COMMENT: \\n",
138         0
139 };
140
141 const char *eth0text[] = {
142         "DEF:rxb=" NETWORK_RRD_PATH ":eth0rxb:AVERAGE",
143         "DEF:txb=" NETWORK_RRD_PATH ":eth0txb:AVERAGE",
144         "COMMENT:\\n",
145         blank,
146         "COMMENT:                          "
147         "MIN            MAX             AVG             Last\\n",
148         blank,
149         "LINE1:rxb#0000FF:eth0 receive     ",
150         "GPRINT:rxb:MIN:  % 3.2lf %sB",
151         "GPRINT:rxb:MAX:     % 3.2lf %sB",
152         "GPRINT:rxb:AVERAGE:      % 3.2lf %sB",
153         "GPRINT:rxb:LAST:      % 3.2lf %sB\\n",
154         blank,
155         "LINE1:txb#00FF00:eth0 transmit    ",
156         "GPRINT:txb:MIN:  % 3.2lf %sB",
157         "GPRINT:txb:MAX:     % 3.2lf %sB",
158         "GPRINT:txb:AVERAGE:      % 3.2lf %sB",
159         "GPRINT:txb:LAST:      % 3.2lf %sB\\n",
160         "COMMENT: \\n",
161         0
162 };
163
164 const char *eth1text[] = {
165         "DEF:rxb=" NETWORK_RRD_PATH ":eth1rxb:AVERAGE",
166         "DEF:txb=" NETWORK_RRD_PATH ":eth1txb:AVERAGE",
167         "COMMENT:\\n",
168         blank,
169         "COMMENT:                          "
170         "MIN            MAX             AVG             Last\\n",
171         blank,
172         "LINE1:rxb#0000FF:eth1 receive     ",
173         "GPRINT:rxb:MIN:  % 3.2lf %sB",
174         "GPRINT:rxb:MAX:     % 3.2lf %sB",
175         "GPRINT:rxb:AVERAGE:      % 3.2lf %sB",
176         "GPRINT:rxb:LAST:      % 3.2lf %sB\\n",
177         blank,
178         "LINE1:txb#00FF00:eth1 transmit    ",
179         "GPRINT:txb:MIN:  % 3.2lf %sB",
180         "GPRINT:txb:MAX:     % 3.2lf %sB",
181         "GPRINT:txb:AVERAGE:      % 3.2lf %sB",
182         "GPRINT:txb:LAST:      % 3.2lf %sB\\n",
183         "COMMENT: \\n",
184         0
185 };
186
187 const char *systemptext[] = {
188         "DEF:sda_c=" SYSTEMP_RRD_PATH ":sda:AVERAGE",
189         "DEF:SYS_c=" SYSTEMP_RRD_PATH ":SYS:AVERAGE",
190         "DEF:CPU_c=" SYSTEMP_RRD_PATH ":CPU:AVERAGE",
191         "COMMENT:\\n",
192         blank,
193         "COMMENT:                          "
194         "MIN            MAX             AVG             Last\\n",
195         blank,
196         "LINE1:sda_c#0000FF:SAMSUNG HD501LJ      ",
197         "GPRINT:sda_c:MIN:  %5.2lf °C",
198         "GPRINT:sda_c:MAX:     %5.2lf °C",
199         "GPRINT:sda_c:AVERAGE:      %5.2lf °C",
200         "GPRINT:sda_c:LAST:      %5.2lf °C\\n",
201         blank,
202         "LINE1:SYS_c#00FF00:Sys Temp              ",
203         "GPRINT:SYS_c:MIN: %5.2lf °C",
204         "GPRINT:SYS_c:MAX:     %5.2lf °C",
205         "GPRINT:SYS_c:AVERAGE:      %5.2lf °C",
206         "GPRINT:SYS_c:LAST:      %5.2lf °C\\n",
207         blank,
208         "LINE1:CPU_c#FF0000:Intel Core2 Quad     ",
209         "GPRINT:CPU_c:MIN:  %5.2lf °C",    
210         "GPRINT:CPU_c:MAX:     %5.2lf °C",    
211         "GPRINT:CPU_c:AVERAGE:      %5.2lf °C",    
212         "GPRINT:CPU_c:LAST:      %5.2lf °C\\n", 
213         "COMMENT: \\n",
214         0
215 };
216
217 const char *cpuoptions[] = {
218         "--alt-autoscale-max",
219         "--lower-limit", "0",
220         "--vertical-label",
221         "CPU Tics",
222         0
223 };
224
225 const char *memoptions[] = {
226         "--alt-autoscale-max",
227         "--lower-limit", "0",
228         "--vertical-label",
229         "Mem usage (MB)",
230         "--units-exponent", "0",
231         "--base", "1024",
232         0
233 };
234
235 const char *eth0options[] = {
236         "--alt-autoscale-max",
237         "--vertical-label", "Bytes",
238         "--lower-limit", "0",
239         0
240 };
241
242 const char *eth1options[] = {
243         "--alt-autoscale-max",
244         "--vertical-label", "Bytes",
245         "--lower-limit", "0",
246         0
247 };
248
249 const char *systempoptions[] = {
250         "--alt-autoscale",
251         "--vertical-label", "Temp °C",
252         0
253 };
254
255 #define DEFINE_IMAGE(rrdname, _filename, _width, _height, time)         \
256         static struct rrd_image rrdname ## daily = {                    \
257                 .image_filename = _filename "_daily.png",               \
258                 .width = _width,                                        \
259                 .height = _height,                                      \
260                 .timestart = "end-" #time "d",                          \
261                 .timeend = "now",                                       \
262                 .imageformat = "PNG",                                   \
263                 .options = (const char **)&rrdname ## options,          \
264                 .text = (const char **)&rrdname ## text,                \
265         };                                                              \
266         static struct rrd_image rrdname ## weekly = {                   \
267                 .image_filename = _filename "_weekly.png",              \
268                 .width = _width,                                        \
269                 .height = _height,                                      \
270                 .timestart = "end-" #time "w",                          \
271                 .timeend = "now",                                       \
272                 .imageformat = "PNG",                                   \
273                 .options = (const char **)&rrdname ## options,          \
274                 .text = (const char **)&rrdname ## text,                \
275         };                                                              \
276         static struct rrd_image rrdname ## monthly = {                  \
277                 .image_filename = _filename "_monthly.png",             \
278                 .width = _width,                                        \
279                 .height = _height,                                      \
280                 .timestart = "end-" #time "m",                          \
281                 .timeend = "now",                                       \
282                 .imageformat = "PNG",                                   \
283                 .options = (const char **)&rrdname ## options,          \
284                 .text = (const char **)&rrdname ## text,                \
285         };                                                              \
286         static struct rrd_image rrdname ## yearly = {                   \
287                 .image_filename = _filename "_yearly.png",              \
288                 .width = _width,                                        \
289                 .height = _height,                                      \
290                 .timestart = "end-" #time "y",                          \
291                 .timeend = "now",                                       \
292                 .imageformat = "PNG",                                   \
293                 .options = (const char **)&rrdname ## options,          \
294                 .text = (const char **)&rrdname ## text,                \
295         };
296
297 DEFINE_IMAGE(cpu,       SYSINFO_PATH "/images/cpu", 720, 480, 1);
298 DEFINE_IMAGE(mem,       SYSINFO_PATH "/images/mem", 720, 480, 1);
299 DEFINE_IMAGE(systemp,   SYSINFO_PATH "/images/systemp", 720,480,1);
300 DEFINE_IMAGE(eth0,      SYSINFO_PATH "/images/eth0", 720, 200, 1);
301 DEFINE_IMAGE(eth1,      SYSINFO_PATH "/images/eth1", 720, 200, 1);
302
303 static struct rrd_image *cpu_mem_images[] = {
304         &cpudaily,
305         &cpuweekly,
306         &cpumonthly,
307         &cpuyearly,
308         &memdaily,
309         &memweekly,
310         &memmonthly,
311         &memyearly,
312         0
313 };
314
315 static struct rrd_image *network_images[] = {
316         &eth0daily,
317         &eth0weekly,
318         &eth0monthly,
319         &eth0yearly,
320         &eth1daily,
321         &eth1weekly,
322         &eth1monthly,
323         &eth1yearly,
324         NULL,
325 };
326
327 static struct rrd_image *systemp_images[] = {
328         &systempdaily,
329         &systempweekly,
330         &systempmonthly,
331         &systempyearly,
332         0
333 };
334
335 #define SOURCE_ENTRY(_name, _type, _heartbeat, _min, _max) \
336         {                                                  \
337                 .name = _name,                             \
338                 .type = _type,                             \
339                 .heartbeat = _heartbeat,                   \
340                 .min = _min,                               \
341                 .max = _max,                               \
342         },
343
344 #define ARCHIVE_ENTRY(_type, _xff, _steps, _rows) \
345         {                                         \
346                 .type = _type,                    \
347                 .xff = _xff,                      \
348                 .steps = _steps,                  \
349                 .rows = _rows,                    \
350         },
351
352 struct rrd_data_source cpumem_sources[] = {
353         SOURCE_ENTRY("User",    "COUNTER", 240, 0, 1200)
354         SOURCE_ENTRY("Nice",    "COUNTER", 240, 0, 1200)
355         SOURCE_ENTRY("Sys",     "COUNTER", 240, 0, 1200)
356         SOURCE_ENTRY("Idle",    "COUNTER", 240, 0, 1200)
357         SOURCE_ENTRY("Wait",    "COUNTER", 240, 0, 1200)
358         SOURCE_ENTRY("IRQ",     "COUNTER", 240, 0, 1200)
359         SOURCE_ENTRY("SoftIRQ", "COUNTER", 240, 0, 1200)
360         SOURCE_ENTRY("Free",    "GAUGE", 240, 0, 32768)
361         SOURCE_ENTRY("Buffers", "GAUGE", 240, 0, 32768)
362         SOURCE_ENTRY("Cached",  "GAUGE", 240, 0, 32768)
363         SOURCE_ENTRY("Active",  "GAUGE", 240, 0, 32768)
364         SOURCE_ENTRY("Inactive","GAUGE", 240, 0, 32768)
365         SOURCE_ENTRY("SwapFree","GAUGE", 240, 0, 32768)
366         SOURCE_ENTRY("Anon",    "GAUGE", 240, 0, 32768)
367         SOURCE_ENTRY("Slab",    "GAUGE", 240, 0, 32768)
368         SOURCE_ENTRY("Tables",  "GAUGE", 240, 0, 32768)
369         SOURCE_ENTRY("Other",   "GAUGE", 240, 0, 32768)
370         SOURCE_ENTRY("Swap",    "GAUGE", 240, 0, 32768)
371         {},
372 };
373
374 struct rrd_archive cpumem_archives[] = {
375         ARCHIVE_ENTRY("AVERAGE", 0.5, 1, 720)
376         ARCHIVE_ENTRY("AVERAGE", 0.5, 7, 720)
377         ARCHIVE_ENTRY("AVERAGE", 0.5, 31, 720)
378         ARCHIVE_ENTRY("AVERAGE", 0.5, 365, 720)
379         ARCHIVE_ENTRY("MIN", 0.5, 1, 720)
380         ARCHIVE_ENTRY("MIN", 0.5, 7, 720)
381         ARCHIVE_ENTRY("MIN", 0.5, 31, 720)
382         ARCHIVE_ENTRY("MIN", 0.5, 365, 720)
383         ARCHIVE_ENTRY("MAX", 0.5, 1, 720)
384         ARCHIVE_ENTRY("MAX", 0.5, 7, 720)
385         ARCHIVE_ENTRY("MAX", 0.5, 31, 720)
386         ARCHIVE_ENTRY("MAX", 0.5, 365, 720)
387         {},
388 };
389
390 struct rrd_data_source network_sources[] = {
391         SOURCE_ENTRY("eth0rxb", "COUNTER", 240, 0, 120000000000)
392         SOURCE_ENTRY("eth0rxp", "COUNTER", 240, 0, 120000000000)
393         SOURCE_ENTRY("eth0txb", "COUNTER", 240, 0, 120000000000)
394         SOURCE_ENTRY("eth0txp", "COUNTER", 240, 0, 120000000000)
395         SOURCE_ENTRY("eth1rxb", "COUNTER", 240, 0, 120000000000)
396         SOURCE_ENTRY("eth1rxp", "COUNTER", 240, 0, 120000000000)
397         SOURCE_ENTRY("eth1txb", "COUNTER", 240, 0, 120000000000)
398         SOURCE_ENTRY("eth1txp", "COUNTER", 240, 0, 120000000000)
399         {},
400 };
401
402 struct rrd_archive network_archives[] = {
403         ARCHIVE_ENTRY("AVERAGE", 0.5, 1, 720)
404         ARCHIVE_ENTRY("AVERAGE", 0.5, 7, 720)
405         ARCHIVE_ENTRY("AVERAGE", 0.5, 31, 720)
406         ARCHIVE_ENTRY("AVERAGE", 0.5, 365, 720)
407         ARCHIVE_ENTRY("MIN", 0.5, 1, 720)
408         ARCHIVE_ENTRY("MIN", 0.5, 7, 720)
409         ARCHIVE_ENTRY("MIN", 0.5, 31, 720)
410         ARCHIVE_ENTRY("MIN", 0.5, 365, 720)
411         ARCHIVE_ENTRY("MAX", 0.5, 1, 720)
412         ARCHIVE_ENTRY("MAX", 0.5, 7, 720)
413         ARCHIVE_ENTRY("MAX", 0.5, 31, 720)
414         ARCHIVE_ENTRY("MAX", 0.5, 365, 720)
415         {},
416 };
417
418 static struct rrd_database cpumem_rrd = {
419         .filename       = SYSINFO_RRD_PATH,
420         .interval       = 120,
421         .parse          = cpu_mem_parser,
422         .images         = (struct rrd_image **)&cpu_mem_images,
423         .sources        = cpumem_sources,
424         .archives       = cpumem_archives,
425         .name           = "cpumem",
426 };
427
428 static struct rrd_database systemp_rrd = {
429         .interval       = 300,
430         .parse          = NULL,
431         .filename       = NULL,
432         .images         = (struct rrd_image **)&systemp_images,
433         .name           = "systemp",
434 };
435
436 const char *network_interfaces[] = {
437         "eth0",
438         "eth1",
439         NULL,
440 };
441
442 static struct rrd_database network_rrd = {
443         .name           = "network",
444         .filename       = NETWORK_RRD_PATH,
445         .interval       = 120,
446         .parse          = netstats_parser,
447         .sources        = network_sources,
448         .archives       = network_archives,
449         .parser_data    = network_interfaces,
450         .images         = network_images,
451 };
452
453 static struct rrd_database *default_rrds[] = {
454         &cpumem_rrd,
455         &systemp_rrd,
456         &network_rrd,
457         0
458 };
459
460 #endif