]> git.itanic.dy.fi Git - rrdd/blob - main.c
Rename the built in database to default_rrds
[rrdd] / main.c
1 #include <sys/types.h>
2 #include <unistd.h>
3 #include <getopt.h>
4
5 #include "process.h"
6 #include "rrdtool.h"
7 #include "parser.h"
8 #include "scheduler.h"
9 #include "debug.h"
10
11 #include "database.h"
12
13 struct user_options {
14         int max_jobs;
15 };
16
17 int read_args(int argc, char *argv[], struct user_options *opts)
18 {
19         int option_index = 0, c;
20         static struct option long_options[] = {
21                 { .val = 'j', .name = "jobs", .has_arg = 1, },
22                 { },
23         };
24         char short_options[] = "j:";
25
26         while (1) {
27                 c = getopt_long(argc, argv, short_options, long_options,
28                                 &option_index);
29
30                 if (c == -1)
31                         break;
32
33                 switch (c) {
34                 case 'j':
35                         opts->max_jobs = atoi(optarg);
36                         break;
37
38                 case '?':
39                         return -1;
40                 }
41         }
42         return 0;
43 }
44
45 int main(int argc, char *argv[])
46 {
47         struct user_options opts;
48         struct rrd_database *db, **db_list = NULL;
49         int sleeptime;
50
51         bzero(&opts, sizeof(opts));
52
53         if (read_args(argc, argv, &opts) < 0)
54                 return -1;
55
56         if (rrdtool_create_missing_databases(db_list))
57                 return 1;
58
59         if (init_jobcontrol(opts.max_jobs))
60                 return -1;
61
62         while (1) {
63                 pr_info("loop start\n");
64                 /*
65                  * Update all databases parallel in one shot
66                  */
67                 while ((db = get_outdated_db(db_list)))
68                         rrdtool_update_data(db);
69
70                 sleeptime = get_next_update(db_list);
71
72                 pr_info("Time to sleep %d seconds\n", sleeptime);
73                 poll_job_requests(sleeptime);
74         }
75         return 0;
76 }