rsstats
0.0.1
Redis Enterprise Statistic collector
main.c
Go to the documentation of this file.
1
19
#ifdef HAVE_CONFIG_H
20
#include "config.h"
21
#endif
22
23
#include "
ansi-color-codes.h
"
24
#include "
revision.h
"
25
#include "
csv.h
"
/* CSV manipulation functions */
26
#include "
clusterlst.h
"
/* Cluster list structure */
27
#ifndef NOCPPCHECK
28
#include "
rsstats-opts.h
"
/* Libopts generated options */
29
#endif
30
#include "
rptsample.h
"
31
#include "
rptbdbs.h
"
32
#include "
rptcluster.h
"
33
34
#include <stdlib.h>
35
#include <string.h>
36
37
int
main
(
int
argc,
char
** argv,
char
** env) {
38
FILE *reportfile;
39
FILE *configfile;
40
char
configline[1024];
41
cluster_t
* cluster;
42
43
(void)env;
/* Avoid unused warning/error */
44
printf(
BCYN
PACKAGE_NAME
" "
PACKAGE_VERSION
RESET
"\n"
);
45
#ifdef REVISION
46
printf(
"Revision "
BBLU
REVISION
RESET
);
47
#endif
48
#ifdef BBID
49
printf(
" Build #"
BBID);
50
#endif
51
printf(
"\n"
);
52
53
#pragma GCC diagnostic push
/* save the actual diag context */
54
#pragma GCC diagnostic ignored "-Wdate-time"
/* locally disable warnings because of non reproductible build triggered by pbuild */
55
printf(
"Compiled %s at %s\n"
,__DATE__, __TIME__);
56
#pragma GCC diagnostic pop
/* restore previous diag context */
57
printf(
"Copyright 2024 François Cerbelle\n"
);
58
printf(
"Report bugs to %s\n\n"
,
BYEL
PACKAGE_BUGREPORT
RESET
);
59
/* AutoGen option parsing and consumming */
60
{
61
int
arg_ct = optionProcess( &
rsstatsOptions
, argc, argv );
62
argc -= arg_ct;
63
argv += arg_ct;
64
}
65
66
printf(
"==> Read input file (cluster definitions): %s\n"
,
OPT_ARG
(INPUT));
67
/* Open the cluster definitions files */
68
configfile = fopen(
OPT_ARG
(INPUT),
"r"
);
69
if
(!configfile) {
70
perror(
"main open(configfile)"
);
71
exit(EXIT_FAILURE);
72
}
73
74
unsigned
int
lineno = 0;
75
while
(fgets(configline,
sizeof
(configline), configfile) !=
NULL
) {
76
lineno++;
77
78
/* Allocate a cluster record */
79
if
(
NULL
==(cluster=malloc(
sizeof
(
struct
cluster_s
)))) {
80
perror(
"main malloc(cluster)"
);
81
exit(EXIT_FAILURE);
82
}
83
84
/* Extract cluster information from the configline */
85
if
(
NULL
==(cluster->
host
=
csvtok
(configline))) {
86
fprintf(stderr,
"Bad configline (%s:%u)\n"
,
OPT_ARG
(INPUT), lineno);
87
free(cluster);
88
continue
;
89
}
90
if
(
NULL
==(cluster->
user
=
csvtok
(
NULL
))) {
91
fprintf(stderr,
"Bad configline (%s:%u)\n"
,
OPT_ARG
(INPUT), lineno);
92
free(cluster->
host
);
93
free(cluster);
94
continue
;
95
}
96
if
(
NULL
==(cluster->
pass
=
csvtok
(
NULL
))) {
97
fprintf(stderr,
"Bad configline (%s:%u)\n"
,
OPT_ARG
(INPUT), lineno);
98
free(cluster->
host
);
99
free(cluster->
user
);
100
free(cluster);
101
continue
;
102
}
103
if
(
NULL
==(cluster->
insecure
=
csvtok
(
NULL
))) {
104
fprintf(stderr,
"Bad configline (%s:%u)\n"
,
OPT_ARG
(INPUT), lineno);
105
free(cluster->
host
);
106
free(cluster->
user
);
107
free(cluster->
pass
);
108
free(cluster);
109
continue
;
110
}
111
if
(
NULL
==(cluster->
cacert
=
csvtok
(
NULL
))) {
112
fprintf(stderr,
"Bad configline (%s:%u)\n"
,
OPT_ARG
(INPUT), lineno);
113
free(cluster->
host
);
114
free(cluster->
user
);
115
free(cluster->
pass
);
116
free(cluster->
insecure
);
117
free(cluster);
118
continue
;
119
}
120
121
/* Check if the configline should be processed */
122
if
((
NULL
!=strstr(
OPT_ARG
(CLUSTERS),
"all"
))
123
||(
NULL
!=strstr(
OPT_ARG
(CLUSTERS),cluster->
host
)))
124
cluster->
enabled
=1;
125
else
126
cluster->
enabled
=0;
127
if
(
clusterlist_find
(cluster->
host
))
128
fprintf(stderr,
"Double cluster definition (%s @ %s:%u)\n"
,
129
cluster->
host
,
OPT_ARG
(INPUT), lineno);
130
clusterlist_add
(cluster);
131
}
132
fclose(configfile);
133
134
printf(
"==> Clusters to query : "
);
135
cluster=
clusterlist_first
();
136
while
(cluster) {
137
if
(cluster->
enabled
==1)
138
printf(
"%s "
,cluster->
host
);
139
cluster =
clusterlist_next
();
140
}
141
printf(
"\n"
);
142
143
printf(
"==> Open output file (report): %s\n"
,
OPT_ARG
(OUTPUT));
144
145
/* Open the output file */
146
reportfile = fopen(
OPT_ARG
(OUTPUT),
"w"
);
147
if
(!reportfile) {
148
perror(
"Opening output file"
);
149
exit(EXIT_FAILURE);
150
}
151
152
/* Execute sample report ? all or sample specified */
153
if
(
OPT_VALUE_REPORTS
&
REPORTS_SAMPLE
) {
154
printf(
"==> Running reports (sample)\n"
);
155
fprintf(reportfile,
"\nsample:\n"
);
156
report_sample_header
(reportfile);
157
/* Execute report against enabled clusters */
158
cluster=
clusterlist_first
();
159
while
(cluster) {
160
/* Check if the configline should be processed */
161
if
(cluster->
enabled
==1) {
162
printf(
"==> Running report (sample) on cluster %s\n"
,cluster->
host
);
163
report_sample
(reportfile, cluster);
164
}
165
cluster =
clusterlist_next
();
166
}
167
}
168
169
/* Execute cluster report ? all or cluster specified */
170
if
(
OPT_VALUE_REPORTS
&
REPORTS_CLUSTER
) {
171
printf(
"==> Running reports (cluster)\n"
);
172
fprintf(reportfile,
"\nclusters:\n"
);
173
report_cluster_header
(reportfile);
174
/* Execute report against enabled clusters */
175
cluster=
clusterlist_first
();
176
while
(cluster) {
177
/* Check if the configline should be processed */
178
if
(cluster->
enabled
==1) {
179
printf(
"==> Running report (clusters) on cluster %s\n"
,cluster->
host
);
180
report_cluster
(reportfile, cluster);
181
}
182
cluster =
clusterlist_next
();
183
}
184
}
185
186
/* Execute bdbs report ? all or bdbs specified */
187
if
(
OPT_VALUE_REPORTS
&
REPORTS_BDBS
) {
188
printf(
"==> Running reports (bdbs)\n"
);
189
fprintf(reportfile,
"\nbdbs:\n"
);
190
report_bdbs_header
(reportfile);
191
/* Execute report against enabled clusters */
192
cluster=
clusterlist_first
();
193
while
(cluster) {
194
/* Check if the configline should be processed */
195
if
(cluster->
enabled
==1) {
196
printf(
"==> Running report (bdbs) on cluster %s\n"
,cluster->
host
);
197
report_bdbs
(reportfile, cluster);
198
}
199
cluster =
clusterlist_next
();
200
}
201
}
202
203
fclose(reportfile);
204
205
#ifdef _WIN32
206
system(
"PAUSE"
);
/* For windows console window to wait. */
207
#endif
208
209
return
EXIT_SUCCESS;
210
}
211
/* vim: set tw=80: */
ansi-color-codes.h
BYEL
#define BYEL
Definition:
ansi-color-codes.h:23
BBLU
#define BBLU
Definition:
ansi-color-codes.h:24
RESET
#define RESET
Definition:
ansi-color-codes.h:80
BCYN
#define BCYN
Definition:
ansi-color-codes.h:26
clusterlist_first
cluster_t *(* clusterlist_first)()
Definition:
clusterlst.c:112
clusterlist_add
void(* clusterlist_add)(cluster_t *cluster)
Definition:
clusterlst.c:82
clusterlist_next
cluster_t *(* clusterlist_next)()
Definition:
clusterlst.c:124
clusterlist_find
cluster_t *(* clusterlist_find)(const char *host)
Definition:
clusterlst.c:101
clusterlst.h
Basic(non-thread-safe) single-chained list of record with sentinal.
csvtok
char * csvtok(char *source)
Definition:
csv.c:50
csv.h
<+DETAILED+>
main
int main(int argc, char **argv, char **env)
Definition:
main.c:37
revision.h
REVISION
#define REVISION
Definition:
revision.h:3
report_bdbs_header
void report_bdbs_header(FILE *reportfile)
Definition:
rptbdbs.c:38
report_bdbs
void report_bdbs(FILE *reportfile, const cluster_t *cluster)
Definition:
rptbdbs.c:71
rptbdbs.h
<+DETAILED+>
report_cluster
void report_cluster(FILE *reportfile, const cluster_t *cluster)
Definition:
rptcluster.c:79
report_cluster_header
void report_cluster_header(FILE *reportfile)
Definition:
rptcluster.c:38
rptcluster.h
<+DETAILED+>
report_sample
void report_sample(FILE *reportfile, const cluster_t *cluster)
Definition:
rptsample.c:42
report_sample_header
void report_sample_header(FILE *reportfile)
Definition:
rptsample.c:36
rptsample.h
Basic report without connection to test output format.
NULL
#define NULL
Definition:
rsstats-opts.c:64
rsstatsOptions
tOptions rsstatsOptions
The option definitions for rsstats.
Definition:
rsstats-opts.c:533
rsstats-opts.h
REPORTS_BDBS
#define REPORTS_BDBS
Definition:
rsstats-opts.h:150
REPORTS_CLUSTER
#define REPORTS_CLUSTER
Definition:
rsstats-opts.h:151
OPT_ARG
#define OPT_ARG(n)
The string argument to an option.
Definition:
rsstats-opts.h:103
REPORTS_SAMPLE
#define REPORTS_SAMPLE
Definition:
rsstats-opts.h:149
OPT_VALUE_REPORTS
#define OPT_VALUE_REPORTS
Definition:
rsstats-opts.h:153
cluster_s
Definition:
cluster.h:24
cluster_s::host
char * host
Definition:
cluster.h:26
cluster_s::insecure
char * insecure
Definition:
cluster.h:29
cluster_s::enabled
unsigned short int enabled
Definition:
cluster.h:25
cluster_s::pass
char * pass
Definition:
cluster.h:28
cluster_s::user
char * user
Definition:
cluster.h:27
cluster_s::cacert
char * cacert
Definition:
cluster.h:30
rsstats-0.0.1
src
main.c
Generated by
1.9.4