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