@cryptotaxi247 / netdata-1 / commits / 41a00e696

added -ch option to set container host prefix for /proc and /sys #10

Costa Tsaousis (ktsaou) committed Oct 12, 2015 at 23:56 UTC 41a00e696182c5ca610543d2126eaa32cfd18e0b
15 files changed +76 -14
src/common.c
+2
@@ -14,6 +14,8 @@
14 #include "log.h"
15 #include "common.h"
16
17 +char *global_host_prefix = "";
18 +
19 /*
20 // http://stackoverflow.com/questions/7666509/hash-function-for-string
21 uint32_t simple_hash(const char *name)
src/common.h
+2
@@ -16,6 +16,8 @@ extern int savememory(const char *filename, void *mem, unsigned long size);
16
17 extern int fd_is_valid(int fd);
18
19 +extern char *global_host_prefix;
20 +
21 #ifdef __GNUC__
22 // gcc branch optimization
23 // #warning "Using GCC branch optimizations"
src/main.c
+6
@@ -188,6 +188,7 @@ int main(int argc, char **argv)
188 else if(strcmp(argv[i], "-u") == 0 && (i+1) < argc) { config_set("global", "run as user", argv[i+1]); i++; }
189 else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) { config_set("global", "history", argv[i+1]); i++; }
190 else if(strcmp(argv[i], "-t") == 0 && (i+1) < argc) { config_set("global", "update every", argv[i+1]); i++; }
191 + else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) { config_set("global", "host access prefix", argv[i+1]); i++; }
192 else if(strcmp(argv[i], "--unittest") == 0) {
193 if(unit_test_storage()) exit(1);
194 exit(0);
@@ -215,6 +216,7 @@ int main(int argc, char **argv)
216 fprintf(stderr, " -t UPDATE_TIMER can be from 1 to %d seconds. Default: %d.\n", UPDATE_EVERY_MAX, UPDATE_EVERY);
217 fprintf(stderr, " -p LISTEN_PORT can be from 1 to %d. Default: %d.\n", 65535, LISTEN_PORT);
218 fprintf(stderr, " -u USERNAME can be any system username to run as. Default: none.\n");
219 + fprintf(stderr, " -ch path to access host /proc and /sys when running in a container. Default: empty.\n");
220 fprintf(stderr, " -df FLAGS debug options. Default: 0x%8llx.\n", debug_flags);
221 exit(1);
222 }
@@ -238,6 +240,10 @@ int main(int argc, char **argv)
240
241 // --------------------------------------------------------------------
242
243 + global_host_prefix = config_get("global", "host access prefix", "");
244 +
245 + // --------------------------------------------------------------------
246 +
247 output_log_file = config_get("global", "debug log", LOG_DIR "/debug.log");
248 if(strcmp(output_log_file, "syslog") == 0) {
249 output_log_syslog = 1;
src/proc_diskstats.c
+11 -3
@@ -17,7 +17,7 @@
17
18 int do_proc_diskstats(int update_every, unsigned long long dt) {
19 static procfile *ff = NULL;
20 - static char *path_to_get_hw_sector_size = NULL;
20 + static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
21 static int enable_new_disks = -1;
22 static int do_io = -1, do_ops = -1, do_merged_ops = -1, do_iotime = -1, do_cur_ops = -1;
23
@@ -31,10 +31,18 @@ int do_proc_diskstats(int update_every, unsigned long long dt) {
31
32 if(dt) {};
33
34 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/diskstats", "filename to monitor", "/proc/diskstats"), " \t", PROCFILE_FLAG_DEFAULT);
34 + if(!ff) {
35 + char filename[FILENAME_MAX + 1];
36 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/diskstats");
37 + ff = procfile_open(config_get("plugin:proc:/proc/diskstats", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
38 + }
39 if(!ff) return 1;
40
37 - if(!path_to_get_hw_sector_size) path_to_get_hw_sector_size = config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", "/sys/block/%s/queue/hw_sector_size");
41 + if(!path_to_get_hw_sector_size[0]) {
42 + char filename[FILENAME_MAX + 1];
43 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/block/%s/queue/hw_sector_size");
44 + snprintf(path_to_get_hw_sector_size, FILENAME_MAX, "%s%s", global_host_prefix, config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", filename));
45 + }
46
47 ff = procfile_readall(ff);
48 if(!ff) return 0; // we return 0, so that we will retry to open it next time
src/proc_interrupts.c
+5 -1
@@ -31,7 +31,11 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
31
32 if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/interrupts", "interrupts per core", 0);
33
34 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", "/proc/interrupts"), " \t", PROCFILE_FLAG_DEFAULT);
34 + if(!ff) {
35 + char filename[FILENAME_MAX + 1];
36 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/interrupts");
37 + ff = procfile_open(config_get("plugin:proc:/proc/interrupts", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
38 + }
39 if(!ff) return 1;
40
41 ff = procfile_readall(ff);
src/proc_meminfo.c
+5 -1
@@ -28,7 +28,11 @@ int do_proc_meminfo(int update_every, unsigned long long dt) {
28
29 if(dt) {};
30
31 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/meminfo", "filename to monitor", "/proc/meminfo"), " \t:", PROCFILE_FLAG_DEFAULT);
31 + if(!ff) {
32 + char filename[FILENAME_MAX + 1];
33 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/meminfo");
34 + ff = procfile_open(config_get("plugin:proc:/proc/meminfo", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
35 + }
36 if(!ff) return 1;
37
38 ff = procfile_readall(ff);
src/proc_net_dev.c
+5 -1
@@ -15,7 +15,11 @@ int do_proc_net_dev(int update_every, unsigned long long dt) {
15
16 if(dt) {};
17
18 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/dev", "filename to monitor", "/proc/net/dev"), " \t,:|", PROCFILE_FLAG_DEFAULT);
18 + if(!ff) {
19 + char filename[FILENAME_MAX + 1];
20 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/dev");
21 + ff = procfile_open(config_get("plugin:proc:/proc/net/dev", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
22 + }
23 if(!ff) return 1;
24
25 ff = procfile_readall(ff);
src/proc_net_ip_vs_stats.c
+5 -1
@@ -21,7 +21,11 @@ int do_proc_net_ip_vs_stats(int update_every, unsigned long long dt) {
21
22 if(dt) {};
23
24 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/ip_vs_stats", "filename to monitor", "/proc/net/ip_vs_stats"), " \t,:|", PROCFILE_FLAG_DEFAULT);
24 + if(!ff) {
25 + char filename[FILENAME_MAX + 1];
26 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/ip_vs_stats");
27 + ff = procfile_open(config_get("plugin:proc:/proc/net/ip_vs_stats", "filename to monitor", filename), " \t,:|", PROCFILE_FLAG_DEFAULT);
28 + }
29 if(!ff) return 1;
30
31 ff = procfile_readall(ff);
src/proc_net_netstat.c
+5 -1
@@ -23,7 +23,11 @@ int do_proc_net_netstat(int update_every, unsigned long long dt) {
23
24 if(dt) {};
25
26 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", "/proc/net/netstat"), " \t:", PROCFILE_FLAG_DEFAULT);
26 + if(!ff) {
27 + char filename[FILENAME_MAX + 1];
28 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
29 + ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
30 + }
31 if(!ff) return 1;
32
33 ff = procfile_readall(ff);
src/proc_net_rpc_nfsd.c
+5 -1
@@ -138,7 +138,11 @@ int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
138
139 if(dt) {};
140
141 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/rpc/nfsd", "filename to monitor", "/proc/net/rpc/nfsd"), " \t", PROCFILE_FLAG_DEFAULT);
141 + if(!ff) {
142 + char filename[FILENAME_MAX + 1];
143 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/rpc/nfsd");
144 + ff = procfile_open(config_get("plugin:proc:/proc/net/rpc/nfsd", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
145 + }
146 if(!ff) return 1;
147
148 ff = procfile_readall(ff);
src/proc_net_snmp.c
+5 -1
@@ -32,7 +32,11 @@ int do_proc_net_snmp(int update_every, unsigned long long dt) {
32
33 if(dt) {};
34
35 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/snmp", "filename to monitor", "/proc/net/snmp"), " \t:", PROCFILE_FLAG_DEFAULT);
35 + if(!ff) {
36 + char filename[FILENAME_MAX + 1];
37 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/snmp");
38 + ff = procfile_open(config_get("plugin:proc:/proc/net/snmp", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
39 + }
40 if(!ff) return 1;
41
42 ff = procfile_readall(ff);
src/proc_net_stat_conntrack.c
+5 -1
@@ -26,7 +26,11 @@ int do_proc_net_stat_conntrack(int update_every, unsigned long long dt) {
26
27 if(dt) {};
28
29 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/net/stat/nf_conntrack", "filename to monitor", "/proc/net/stat/nf_conntrack"), " \t:", PROCFILE_FLAG_DEFAULT);
29 + if(!ff) {
30 + char filename[FILENAME_MAX + 1];
31 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/stat/nf_conntrack");
32 + ff = procfile_open(config_get("plugin:proc:/proc/net/stat/nf_conntrack", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
33 + }
34 if(!ff) return 1;
35
36 ff = procfile_readall(ff);
src/proc_stat.c
+5 -1
@@ -26,7 +26,11 @@ int do_proc_stat(int update_every, unsigned long long dt) {
26
27 if(dt) {};
28
29 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/stat", "filename to monitor", "/proc/stat"), " \t:", PROCFILE_FLAG_DEFAULT);
29 + if(!ff) {
30 + char filename[FILENAME_MAX + 1];
31 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/stat");
32 + ff = procfile_open(config_get("plugin:proc:/proc/stat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
33 + }
34 if(!ff) return 1;
35
36 ff = procfile_readall(ff);
src/proc_sys_kernel_random_entropy_avail.c
+5 -1
@@ -13,7 +13,11 @@ int do_proc_sys_kernel_random_entropy_avail(int update_every, unsigned long long
13
14 if(dt) {} ;
15
16 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", "/proc/sys/kernel/random/entropy_avail"), "", PROCFILE_FLAG_DEFAULT);
16 + if(!ff) {
17 + char filename[FILENAME_MAX + 1];
18 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/sys/kernel/random/entropy_avail");
19 + ff = procfile_open(config_get("plugin:proc:/proc/sys/kernel/random/entropy_avail", "filename to monitor", filename), "", PROCFILE_FLAG_DEFAULT);
20 + }
21 if(!ff) return 1;
22
23 ff = procfile_readall(ff);
src/proc_vmstat.c
+5 -1
@@ -24,7 +24,11 @@ int do_proc_vmstat(int update_every, unsigned long long dt) {
24
25 if(dt) {};
26
27 - if(!ff) ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", "/proc/vmstat"), " \t:", PROCFILE_FLAG_DEFAULT);
27 + if(!ff) {
28 + char filename[FILENAME_MAX + 1];
29 + snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/vmstat");
30 + ff = procfile_open(config_get("plugin:proc:/proc/vmstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
31 + }
32 if(!ff) return 1;
33
34 ff = procfile_readall(ff);