-
Notifications
You must be signed in to change notification settings - Fork 2
/
bolo-metrics.c
76 lines (65 loc) · 1.71 KB
/
bolo-metrics.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "bolo.h"
#include <getopt.h>
#include <time.h>
int
do_metrics(int argc, char **argv)
{
struct db *db;
struct dbkey *key;
{
char *key_str = NULL;
int idx = 0;
char c, *shorts = "hDk:";
struct option longs[] = {
{"help", no_argument, 0, 'h'},
{"debug", no_argument, 0, 'D'},
{"key", required_argument, 0, 'k'},
{0, 0, 0, 0},
};
while ((c = getopt_long(argc, argv, shorts, longs, &idx)) >= 0) {
switch (c) {
case 'h':
printf("USAGE: %s metrics [--key \"key-in-hex\"] [--debug] /path/to/db/\n\n", argv[0]);
printf("OPTIONS\n\n");
printf(" -h, --help Show this help screen.\n\n");
printf(" -k, --key KEY-IN-HEX The literal, hex-encoded database encryption key.\n");
printf(" -D, --debug Enable debugging mode.\n"
" (mostly useful only to bolo devs).\n\n");
return 0;
case 'D':
debugto(fileno(stderr));
break;
case 'k':
free(key_str);
key_str = strdup(optarg);
break;
}
}
key = NULL;
if (key_str) {
key = read_key(key_str);
if (!key) {
fprintf(stderr, "invalid database encryption key given\n");
return 1;
}
}
}
if (argc != optind+2) {
fprintf(stderr, "USAGE: %s metrics [--key \"key-in-hex\"] [--debug] /path/to/db/\n\n", argv[0]);
return 1;
}
db = db_mount(deslash(argv[optind+1]), key);
if (!db) {
fprintf(stderr, "%s: %s\n", argv[optind+1], error(errno));
return 2;
}
char *metric;
hash_each(db->main, &metric, NULL) {
printf("%s\n", metric);
}
if (db_unmount(db) != 0) {
fprintf(stderr, "warning: had trouble unmounting database at %s: %s\n",
argv[optind+1], error(errno));
}
return 0;
}