@cryptotaxi247 / netdata-1 / commits / 67f3ff605

allow including statsd config files

Costa Tsaousis (ktsaou) committed Feb 2, 2018 at 20:54 UTC 67f3ff605a90b9496eb90c3c9d6760e1cd6592d6
1 file changed +17 -10
src/statsd.c
+17 -10
@@ -1044,23 +1044,18 @@ static STATSD_APP_CHART_DIM *add_dimension_to_app_chart(
1044 return dim;
1045 }
1046
1047 -int statsd_readfile(const char *path, const char *filename) {
1047 +static int statsd_readfile(const char *path, const char *filename, STATSD_APP *app, STATSD_APP_CHART *chart, DICTIONARY *dict) {
1048 debug(D_STATSD, "STATSD configuration reading file '%s/%s'", path, filename);
1049
1050 - char buffer[STATSD_CONF_LINE_MAX + 1];
1051 -
1052 - FILE *fp = NULL;
1050 + char *buffer = mallocz(STATSD_CONF_LINE_MAX + 1);
1051 snprintfz(buffer, STATSD_CONF_LINE_MAX, "%s/%s", path, filename);
1054 - fp = fopen(buffer, "r");
1052 + FILE *fp = fopen(buffer, "r");
1053 if(!fp) {
1054 error("STATSD: cannot open file '%s'.", buffer);
1055 + freez(buffer);
1056 return -1;
1057 }
1058
1060 - STATSD_APP *app = NULL;
1061 - STATSD_APP_CHART *chart = NULL;
1062 - DICTIONARY *dict = NULL;
1063 -
1059 size_t line = 0;
1060 char *s;
1061 while(fgets(buffer, STATSD_CONF_LINE_MAX, fp) != NULL) {
@@ -1072,8 +1067,19 @@ int statsd_readfile(const char *path, const char *filename) {
1067 debug(D_STATSD, "STATSD: ignoring line %zu of file '%s/%s', it is empty.", line, path, filename);
1068 continue;
1069 }
1070 +
1071 debug(D_STATSD, "STATSD: processing line %zu of file '%s/%s': %s", line, path, filename, buffer);
1072
1073 + if(*s == 'i' && strncmp(s, "include", 7) == 0) {
1074 + s = trim(&s[7]);
1075 + if(s && *s)
1076 + statsd_readfile(path, s, app, chart, dict);
1077 + else
1078 + error("STATSD: ignoring line %zu of file '%s/%s', include filename is empty", line, path, s);
1079 +
1080 + continue;
1081 + }
1082 +
1083 int len = (int) strlen(s);
1084 if (*s == '[' && s[len - 1] == ']') {
1085 // new section
@@ -1296,6 +1302,7 @@ int statsd_readfile(const char *path, const char *filename) {
1302 }
1303 }
1304
1305 + freez(buffer);
1306 fclose(fp);
1307 return 0;
1308 }
@@ -1336,7 +1343,7 @@ static void statsd_readdir(const char *path) {
1343
1344 else if((de->d_type == DT_LNK || de->d_type == DT_REG || de->d_type == DT_UNKNOWN) &&
1345 len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
1339 - statsd_readfile(path, de->d_name);
1346 + statsd_readfile(path, de->d_name, NULL, NULL, NULL);
1347 }
1348
1349 else debug(D_STATSD, "STATSD: ignoring file '%s'", de->d_name);