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