@cryptotaxi247 / netdata-1 / commits / 2cc264eff

modularize C source code (#4372)

* modularize cgroups and cmake; #4339 * modularized freeipmi.plugin * added comment about referencing parent files * modularized apps.plugin * modularized proc and diskspace * minor fixes * modularized plugins: checks, freebsd, idlejitter, nfacct, tc, macos, plugins.d * minor fixes 2 * modularized statsd * modularized cgroup-network * moved cgroup-network-helper.sh and cgroup-name.sh to cgroup.plugin * modularized health plugin * move rrd related info to rrd.h * added libnetdata * do not corrupt config.h * use dir-objects instead of static libraries * fixed cmake for new structure * use absolute paths to fix LGTM * enable automake subdir-objects and prettify its output * use relative files at the src directory for all plugins * fix compiler warning * synced automake and cmake * added config.h to cmake * abstracted basic os functions in libnetdata/os * fix zfs_common * removed apps.plugin dependency on freebsd plugin * health removed from plugins * modularized the registry * modularized the rest of it * include streaming files in cmake * use libnetdata as library * enable silent-rules only when they are available

Costa Tsaousis committed Oct 11, 2018 at 21:27 UTC 2cc264eff5925769a4ae082e9b23f31c00ef23ec
209 files changed +4882 -3702
.gitignore
+10 -1
@@ -1,7 +1,9 @@
1 .deps
2 .libs
3 +.dirstamp
4
5 *.o
6 +*.a
7 config.h.in
8 Makefile.in
9 *~
@@ -29,9 +31,16 @@ netdata.spec
31
32 # netdata binaries
33 netdata
34 +!netdata/
35 +
36 apps.plugin
37 +!apps.plugin/
38 +
39 freeipmi.plugin
40 +!freeipmi.plugin/
41 +
42 cgroup-network
43 +!cgroup-network/
44
45 # netdata makeself archives
46 *.tar.*
@@ -77,7 +86,7 @@ system/netdata-freebsd
86
87 conf.d/edit-config
88 plugins.d/alarm-notify.sh
80 -plugins.d/cgroup-name.sh
89 +src/plugins/linux-cgroups.plugin/cgroup-name.sh
90 plugins.d/charts.d.plugin
91 plugins.d/fping.plugin
92 plugins.d/node.d.plugin
CMakeLists.txt
+479 -236
@@ -3,269 +3,512 @@
3 # This file is only used for development (netdata in Clion)
4 # It can build netdata, but you are on your own...
5
6 -cmake_minimum_required(VERSION 3.3)
6 +cmake_minimum_required(VERSION 3.0.2)
7 project(netdata C)
8
9 -find_package (Threads)
10 -
11 -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-signedness -Werror=format-security -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1 -fstack-protector-all")
12 -
13 -set(NETDATA_FREEBSD_FILES
14 - src/plugin_freebsd.c
15 - src/plugin_freebsd.h
16 - src/freebsd_sysctl.c
17 - src/freebsd_getmntinfo.c
18 - src/freebsd_getifaddrs.c
19 - src/freebsd_devstat.c
20 - src/zfs_common.c
21 - src/zfs_common.h
22 - src/freebsd_kstat_zfs.c
23 - src/freebsd_ipfw.c
9 +find_package(Threads REQUIRED)
10 +find_package(PkgConfig REQUIRED)
11 +
12 +# default is "Debug"
13 +#set(CMAKE_BUILD_TYPE "Release")
14 +
15 +# set this to see the compilation commands
16 +#set(CMAKE_VERBOSE_MAKEFILE 1)
17 +
18 +
19 +# -----------------------------------------------------------------------------
20 +# Set compilation options according to build type
21 +
22 +IF("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
23 + message(STATUS "building for: debugging")
24 +
25 + ## unfortunately these produce errors
26 + #include(CheckCXXCompilerFlag)
27 + #CHECK_CXX_COMPILER_FLAG("-Wformat-signedness" CXX_FORMAT_SIGNEDNESS)
28 + #CHECK_CXX_COMPILER_FLAG("-Werror=format-security" CXX_FORMAT_SECURITY)
29 + #CHECK_CXX_COMPILER_FLAG("-fstack-protector-all" CXX_STACK_PROTECTOR)
30 + set(CXX_FORMAT_SIGNEDNESS "-Wformat-signedness")
31 + set(CXX_FORMAT_SECURITY "-Werror=format-security")
32 + set(CXX_STACK_PROTECTOR "-fstack-protector-all")
33 +
34 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -ggdb -Wall -Wextra -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1 ${CXX_FORMAT_SIGNEDNESS} ${CXX_FORMAT_SECURITY} ${CXX_STACK_PROTECTOR}")
35 +ELSE()
36 + message(STATUS "building for: release")
37 + cmake_policy(SET CMP0069 "NEW")
38 + include(CheckIPOSupported)
39 + check_ipo_supported(RESULT ipo_supported OUTPUT error)
40 + IF(${ipo_supported})
41 + message(STATUS "link time optimization: supported")
42 + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
43 + ELSE()
44 + message(STATUS "link time optimization: not supported")
45 + ENDIF()
46 +ENDIF()
47 +
48 +
49 +# -----------------------------------------------------------------------------
50 +# O/S Detection
51 +
52 +# these are defined in common.h too
53 +SET(LINUX False)
54 +SET(FREEBSD False)
55 +SET(MACOS False)
56 +
57 +# Detect the operating system
58 +IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
59 + SET(TARGET_OS_NAME "macos")
60 + SET(TARGET_OS 3)
61 + SET(MACOS True)
62 +ELSEIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
63 + SET(TARGET_OS_NAME "freebsd")
64 + SET(TARGET_OS 2)
65 + SET(FREEBSD True)
66 +ELSE()
67 + SET(TARGET_OS_NAME "linux")
68 + SET(TARGET_OS 1)
69 + SET(LINUX True)
70 +ENDIF()
71 +
72 +# show the operating system on the console
73 +message(STATUS "operating system: ${TARGET_OS_NAME} (TARGET_OS=${TARGET_OS})")
74 +
75 +
76 +# -----------------------------------------------------------------------------
77 +# Detect libuuid
78 +
79 +pkg_check_modules(UUID REQUIRED uuid)
80 +set(NETDATA_COMMON_CFLAGS ${NETDATA_COMMON_CFLAGS} ${UUID_CFLAGS_OTHER})
81 +set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} ${UUID_LIBRARIES})
82 +set(NETDATA_COMMON_INCLUDE_DIRS ${NETDATA_COMMON_INCLUDE_DIRS} ${UUID_INCLUDE_DIRS})
83 +
84 +# -----------------------------------------------------------------------------
85 +# Detect libz
86 +
87 +pkg_check_modules(ZLIB REQUIRED zlib)
88 +set(NETDATA_COMMON_CFLAGS ${NETDATA_COMMON_CFLAGS} ${ZLIB_CFLAGS_OTHER})
89 +set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} ${ZLIB_LIBRARIES})
90 +set(NETDATA_COMMON_INCLUDE_DIRS ${NETDATA_COMMON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS})
91 +
92 +
93 +# -----------------------------------------------------------------------------
94 +# Detect libcap
95 +
96 +IF(LINUX)
97 + pkg_check_modules(CAP QUIET libcap)
98 + # later we use:
99 + # ${CAP_LIBRARIES}
100 + # ${CAP_CFLAGS_OTHER}
101 + # ${CAP_INCLUDE_DIRS}
102 +ENDIF(LINUX)
103 +
104 +
105 +# -----------------------------------------------------------------------------
106 +# Detect libipmimonitoring
107 +
108 +IF(LINUX)
109 + pkg_check_modules(IPMI libipmimonitoring)
110 + # later we use:
111 + # ${IPMI_LIBRARIES}
112 + # ${IPMI_CFLAGS_OTHER}
113 + # ${IPMI_INCLUDE_DIRS}
114 +ENDIF(LINUX)
115 +
116 +
117 +# -----------------------------------------------------------------------------
118 +# Detect libmnl
119 +IF(LINUX)
120 + pkg_check_modules(MNL libmnl)
121 + # later we use:
122 + # ${MNL_LIBRARIES}
123 + # ${MNL_CFLAGS_OTHER}
124 + # ${MNL_INCLUDE_DIRS}
125 +ENDIF(LINUX)
126 +
127 +# -----------------------------------------------------------------------------
128 +# Detect libmnl
129 +
130 +IF(LINUX)
131 + pkg_check_modules(NFACCT libnetfilter_acct)
132 + # later we use:
133 + # ${NFACCT_LIBRARIES}
134 + # ${NFACCT_CFLAGS_OTHER}
135 + # ${NFACCT_INCLUDE_DIRS}
136 +ENDIF(LINUX)
137 +
138 +# -----------------------------------------------------------------------------
139 +# netdata files
140 +
141 +set(LIBNETDATA_FILES
142 + src/libnetdata/adaptive_resortable_list.c
143 + src/libnetdata/adaptive_resortable_list.h
144 + src/libnetdata/appconfig.c
145 + src/libnetdata/appconfig.h
146 + src/libnetdata/avl.c
147 + src/libnetdata/avl.h
148 + src/libnetdata/clocks.c
149 + src/libnetdata/clocks.h
150 + src/libnetdata/common.c
151 + src/libnetdata/dictionary.c
152 + src/libnetdata/dictionary.h
153 + src/libnetdata/eval.c
154 + src/libnetdata/eval.h
155 + src/libnetdata/inlined.h
156 + src/libnetdata/libnetdata.h
157 + src/libnetdata/locks.c
158 + src/libnetdata/locks.h
159 + src/libnetdata/log.c
160 + src/libnetdata/log.h
161 + src/libnetdata/os.c
162 + src/libnetdata/os.h
163 + src/libnetdata/popen.c
164 + src/libnetdata/popen.h
165 + src/libnetdata/procfile.c
166 + src/libnetdata/procfile.h
167 + src/libnetdata/simple_pattern.c
168 + src/libnetdata/simple_pattern.h
169 + src/libnetdata/socket.c
170 + src/libnetdata/socket.h
171 + src/libnetdata/statistical.c
172 + src/libnetdata/statistical.h
173 + src/libnetdata/storage_number.c
174 + src/libnetdata/storage_number.h
175 + src/libnetdata/threads.c
176 + src/libnetdata/threads.h
177 + src/libnetdata/web_buffer.c
178 + src/libnetdata/web_buffer.h
179 + src/libnetdata/url.c
180 + src/libnetdata/url.h
181 + )
182 +
183 +add_library(libnetdata OBJECT ${LIBNETDATA_FILES})
184 +
185 +set(APPS_PLUGIN_FILES
186 + src/plugins/apps.plugin/apps_plugin.c
187 + )
188 +
189 +set(CHECKS_PLUGIN_FILES
190 + src/plugins/checks.plugin/plugin_checks.c
191 + src/plugins/checks.plugin/plugin_checks.h
192 + )
193 +
194 +set(FREEBSD_PLUGIN_FILES
195 + src/plugins/freebsd.plugin/plugin_freebsd.c
196 + src/plugins/freebsd.plugin/plugin_freebsd.h
197 + src/plugins/freebsd.plugin/freebsd_sysctl.c
198 + src/plugins/freebsd.plugin/freebsd_getmntinfo.c
199 + src/plugins/freebsd.plugin/freebsd_getifaddrs.c
200 + src/plugins/freebsd.plugin/freebsd_devstat.c
201 + src/plugins/freebsd.plugin/freebsd_kstat_zfs.c
202 + src/plugins/freebsd.plugin/freebsd_ipfw.c
203 + src/plugins/linux-proc.plugin/zfs_common.c
204 + src/plugins/linux-proc.plugin/zfs_common.h
205 + )
206 +
207 +set(HEALTH_PLUGIN_FILES
208 + src/health/health.c
209 + src/health/health.h
210 + src/health/health_config.c
211 + src/health/health_json.c
212 + src/health/health_log.c
213 + )
214 +
215 +set(IDLEJITTER_PLUGIN_FILES
216 + src/plugins/idlejitter.plugin/plugin_idlejitter.c
217 + src/plugins/idlejitter.plugin/plugin_idlejitter.h
218 + )
219 +
220 +set(CGROUPS_PLUGIN_FILES
221 + src/plugins/linux-cgroups.plugin/sys_fs_cgroup.c
222 + src/plugins/linux-cgroups.plugin/sys_fs_cgroup.h
223 + )
224 +
225 +set(CGROUP_NETWORK_FILES
226 + src/plugins/linux-cgroups.plugin/cgroup-network.c
227 + )
228 +
229 +set(DISKSPACE_PLUGIN_FILES
230 + src/plugins/linux-diskspace.plugin/plugin_diskspace.h
231 + src/plugins/linux-diskspace.plugin/plugin_diskspace.c
232 )
233
26 -set(NETDATA_MACOS_FILES
27 - src/plugin_macos.c
28 - src/plugin_macos.h
29 - src/macos_sysctl.c
30 - src/macos_mach_smi.c
31 - src/macos_fw.c
234 +set(FREEIPMI_PLUGIN_FILES
235 + src/plugins/linux-freeipmi.plugin/freeipmi_plugin.c
236 )
237
34 -set(NETDATA_LINUX_FILES
35 - src/ipc.c
36 - src/ipc.h
37 - src/plugin_proc.c
38 - src/plugin_proc.h
39 - src/plugin_proc_diskspace.c
40 - src/plugin_proc_diskspace.h
41 - src/proc_diskstats.c
42 - src/proc_interrupts.c
43 - src/proc_softirqs.c
44 - src/proc_loadavg.c
45 - src/proc_meminfo.c
46 - src/proc_net_dev.c
47 - src/proc_net_ip_vs_stats.c
48 - src/proc_net_netstat.c
49 - src/proc_net_rpc_nfs.c
50 - src/proc_net_rpc_nfsd.c
51 - src/proc_net_snmp.c
52 - src/proc_net_snmp6.c
53 - src/proc_net_sctp_snmp.c
54 - src/proc_net_sockstat.c
55 - src/proc_net_sockstat6.c
56 - src/proc_net_softnet_stat.c
57 - src/proc_net_stat_conntrack.c
58 - src/proc_net_stat_synproxy.c
59 - src/zfs_common.c
60 - src/zfs_common.h
61 - src/proc_spl_kstat_zfs.c
62 - src/proc_stat.c
63 - src/proc_sys_kernel_random_entropy_avail.c
64 - src/proc_vmstat.c
65 - src/proc_uptime.c
66 - src/sys_kernel_mm_ksm.c
67 - src/sys_fs_cgroup.c
68 - src/sys_fs_btrfs.c
69 - src/threads.c src/threads.h)
70 -
71 -set(NETDATA_COMMON_FILES
72 - src/adaptive_resortable_list.c
73 - src/adaptive_resortable_list.h
74 - src/appconfig.c
75 - src/appconfig.h
76 - src/avl.c
77 - src/avl.h
78 - src/backend_prometheus.c
79 - src/backend_prometheus.h
80 - src/backends.c
81 - src/backends.h
82 - src/clocks.c
83 - src/clocks.h
238 +set(NFACCT_PLUGIN_FILES
239 + src/plugins/linux-nfacct.plugin/plugin_nfacct.c
240 + src/plugins/linux-nfacct.plugin/plugin_nfacct.h
241 + )
242 +
243 +set(PROC_PLUGIN_FILES
244 + src/plugins/linux-proc.plugin/ipc.c
245 + src/plugins/linux-proc.plugin/plugin_proc.c
246 + src/plugins/linux-proc.plugin/plugin_proc.h
247 + src/plugins/linux-proc.plugin/proc_diskstats.c
248 + src/plugins/linux-proc.plugin/proc_interrupts.c
249 + src/plugins/linux-proc.plugin/proc_softirqs.c
250 + src/plugins/linux-proc.plugin/proc_loadavg.c
251 + src/plugins/linux-proc.plugin/proc_meminfo.c
252 + src/plugins/linux-proc.plugin/proc_net_dev.c
253 + src/plugins/linux-proc.plugin/proc_net_ip_vs_stats.c
254 + src/plugins/linux-proc.plugin/proc_net_netstat.c
255 + src/plugins/linux-proc.plugin/proc_net_rpc_nfs.c
256 + src/plugins/linux-proc.plugin/proc_net_rpc_nfsd.c
257 + src/plugins/linux-proc.plugin/proc_net_snmp.c
258 + src/plugins/linux-proc.plugin/proc_net_snmp6.c
259 + src/plugins/linux-proc.plugin/proc_net_sctp_snmp.c
260 + src/plugins/linux-proc.plugin/proc_net_sockstat.c
261 + src/plugins/linux-proc.plugin/proc_net_sockstat6.c
262 + src/plugins/linux-proc.plugin/proc_net_softnet_stat.c
263 + src/plugins/linux-proc.plugin/proc_net_stat_conntrack.c
264 + src/plugins/linux-proc.plugin/proc_net_stat_synproxy.c
265 + src/plugins/linux-proc.plugin/proc_self_mountinfo.c
266 + src/plugins/linux-proc.plugin/proc_self_mountinfo.h
267 + src/plugins/linux-proc.plugin/zfs_common.c
268 + src/plugins/linux-proc.plugin/zfs_common.h
269 + src/plugins/linux-proc.plugin/proc_spl_kstat_zfs.c
270 + src/plugins/linux-proc.plugin/proc_stat.c
271 + src/plugins/linux-proc.plugin/proc_sys_kernel_random_entropy_avail.c
272 + src/plugins/linux-proc.plugin/proc_vmstat.c
273 + src/plugins/linux-proc.plugin/proc_uptime.c
274 + src/plugins/linux-proc.plugin/sys_kernel_mm_ksm.c
275 + src/plugins/linux-proc.plugin/sys_devices_system_edac_mc.c
276 + src/plugins/linux-proc.plugin/sys_devices_system_node.c
277 + src/plugins/linux-proc.plugin/sys_fs_btrfs.c
278 + )
279 +
280 +set(TC_PLUGIN_FILES
281 + src/plugins/linux-tc.plugin/plugin_tc.c
282 + src/plugins/linux-tc.plugin/plugin_tc.h
283 + )
284 +
285 +set(MACOS_PLUGIN_FILES
286 + src/plugins/macos.plugin/plugin_macos.c
287 + src/plugins/macos.plugin/plugin_macos.h
288 + src/plugins/macos.plugin/macos_sysctl.c
289 + src/plugins/macos.plugin/macos_mach_smi.c
290 + src/plugins/macos.plugin/macos_fw.c
291 + )
292 +
293 +set(PLUGINSD_PLUGIN_FILES
294 + src/plugins/plugins.d.plugin/plugins_d.c
295 + src/plugins/plugins.d.plugin/plugins_d.h
296 + )
297 +
298 +set(REGISTRY_PLUGIN_FILES
299 + src/registry/registry.c
300 + src/registry/registry.h
301 + src/registry/registry_db.c
302 + src/registry/registry_init.c
303 + src/registry/registry_internals.c
304 + src/registry/registry_internals.h
305 + src/registry/registry_log.c
306 + src/registry/registry_machine.c
307 + src/registry/registry_machine.h
308 + src/registry/registry_person.c
309 + src/registry/registry_person.h
310 + src/registry/registry_url.c
311 + src/registry/registry_url.h
312 + )
313 +
314 +set(STATSD_PLUGIN_FILES
315 + src/plugins/statsd.plugin/statsd.c
316 + src/plugins/statsd.plugin/statsd.h
317 + )
318 +
319 +set(RRD_PLUGIN_FILES
320 + src/database/rrdcalc.c
321 + src/database/rrdcalc.h
322 + src/database/rrdcalctemplate.c
323 + src/database/rrdcalctemplate.h
324 + src/database/rrddim.c
325 + src/database/rrddimvar.c
326 + src/database/rrddimvar.h
327 + src/database/rrdfamily.c
328 + src/database/rrdhost.c
329 + src/database/rrd.c
330 + src/database/rrd.h
331 + src/database/rrdset.c
332 + src/database/rrdsetvar.c
333 + src/database/rrdsetvar.h
334 + src/database/rrdvar.c
335 + src/database/rrdvar.h
336 + )
337 +
338 +set(WEB_PLUGIN_FILES
339 + src/webserver/web_client.c
340 + src/webserver/web_client.h
341 + src/webserver/web_server.c
342 + src/webserver/web_server.h
343 + )
344 +
345 +set(API_PLUGIN_FILES
346 + src/api/rrd2json.c
347 + src/api/rrd2json.h
348 + src/api/web_api_v1.c
349 + src/api/web_api_v1.h
350 + src/api/web_buffer_svg.c
351 + src/api/web_buffer_svg.h
352 + )
353 +
354 +set(STREAMING_PLUGIN_FILES
355 + src/streaming/rrdpush.c
356 + src/streaming/rrdpush.h
357 + )
358 +
359 +set(BACKENDS_PLUGIN_FILES
360 + src/backends/backends.c
361 + src/backends/backends.h
362 + src/backends/graphite/graphite.c
363 + src/backends/graphite/graphite.h
364 + src/backends/json/json.c
365 + src/backends/json/json.h
366 + src/backends/opentsdb/opentsdb.c
367 + src/backends/opentsdb/opentsdb.h
368 + src/backends/prometheus/backend_prometheus.c
369 + src/backends/prometheus/backend_prometheus.h
370 + )
371 +
372 +set(NETDATA_FILES
373 + src/plugins/all.h
374 src/common.c
375 src/common.h
376 src/daemon.c
377 src/daemon.h
88 - src/dictionary.c
89 - src/dictionary.h
90 - src/eval.c
91 - src/eval.h
378 src/global_statistics.c
379 src/global_statistics.h
94 - src/health.c
95 - src/health.h
96 - src/health_config.c
97 - src/health_json.c
98 - src/health_log.c
99 - src/inlined.h
100 - src/locks.c
101 - src/locks.h
102 - src/log.c
103 - src/log.h
380 src/main.c
381 src/main.h
106 - src/plugin_checks.c
107 - src/plugin_checks.h
108 - src/plugin_idlejitter.c
109 - src/plugin_idlejitter.h
110 - src/plugin_nfacct.c
111 - src/plugin_nfacct.h
112 - src/plugin_tc.c
113 - src/plugin_tc.h
114 - src/plugins_d.c
115 - src/plugins_d.h
116 - src/popen.c
117 - src/popen.h
118 - src/proc_self_mountinfo.c
119 - src/proc_self_mountinfo.h
120 - src/procfile.c
121 - src/procfile.h
122 - src/registry.c
123 - src/registry.h
124 - src/registry_db.c
125 - src/registry_init.c
126 - src/registry_internals.c
127 - src/registry_internals.h
128 - src/registry_log.c
129 - src/registry_machine.c
130 - src/registry_machine.h
131 - src/registry_person.c
132 - src/registry_person.h
133 - src/registry_url.c
134 - src/registry_url.h
135 - src/rrd.c
136 - src/rrd.h
137 - src/rrd2json.c
138 - src/rrd2json.h
139 - src/rrdcalc.c
140 - src/rrdcalctemplate.c
141 - src/rrddim.c
142 - src/rrddimvar.c
143 - src/rrdfamily.c
144 - src/rrdhost.c
145 - src/rrdpush.c
146 - src/rrdpush.h
147 - src/rrdset.c
148 - src/rrdsetvar.c
149 - src/rrdvar.c
382 src/signals.c
383 src/signals.h
152 - src/simple_pattern.c
153 - src/simple_pattern.h
154 - src/socket.c
155 - src/socket.h
156 - src/statistical.c
157 - src/statistical.h
158 - src/statsd.c
159 - src/statsd.h
160 - src/storage_number.c
161 - src/storage_number.h
162 - src/sys_devices_system_edac_mc.c
163 - src/sys_devices_system_node.c
384 src/unit_test.c
385 src/unit_test.h
166 - src/url.c
167 - src/url.h
168 - src/web_api_v1.c
169 - src/web_api_v1.h
170 - src/web_buffer.c
171 - src/web_buffer.h
172 - src/web_buffer_svg.c
173 - src/web_buffer_svg.h
174 - src/web_client.c
175 - src/web_client.h
176 - src/web_server.c
177 - src/web_server.h
178 - config.h
386 + ${API_PLUGIN_FILES}
387 + ${BACKENDS_PLUGIN_FILES}
388 + ${CHECKS_PLUGIN_FILES}
389 + ${HEALTH_PLUGIN_FILES}
390 + ${IDLEJITTER_PLUGIN_FILES}
391 + ${PLUGINSD_PLUGIN_FILES}
392 + ${RRD_PLUGIN_FILES}
393 + ${REGISTRY_PLUGIN_FILES}
394 + ${STATSD_PLUGIN_FILES}
395 + ${STREAMING_PLUGIN_FILES}
396 + ${WEB_PLUGIN_FILES}
397 )
398
181 -set(APPS_PLUGIN_SOURCE_FILES
182 - src/appconfig.c
183 - src/appconfig.h
184 - src/apps_plugin.c
185 - src/avl.c
186 - src/avl.h
187 - src/adaptive_resortable_list.c
188 - src/adaptive_resortable_list.h
189 - src/common.c
190 - src/common.h
191 - src/clocks.c
192 - src/clocks.h
193 - src/inlined.h
194 - src/locks.c
195 - src/locks.h
196 - src/log.c
197 - src/log.h
198 - src/procfile.c
199 - src/procfile.h
200 - src/threads.c
201 - src/threads.h
202 - src/web_buffer.c
203 - src/web_buffer.h
204 - config.h
205 - )
399 +IF(LINUX AND MNL_LIBRARIES AND NFACCT_LIBRARIES)
400 + message(STATUS "nfacct.plugin: enabled (will work only if netdata runs as root)")
401 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DINTERNAL_PLUGIN_NFACCT=1")
402 +ELSE()
403 + message(STATUS "nfacct.plugin: disabled (requires libmnl and libnetfilter_acct)")
404 +ENDIF()
405
207 -set(FREEIPMI_PLUGIN_SOURCE_FILES
208 - src/freeipmi_plugin.c
209 - src/common.c
210 - src/common.h
211 - src/clocks.c
212 - src/clocks.h
213 - src/inlined.h
214 - src/locks.c
215 - src/locks.h
216 - src/log.c
217 - src/log.h
218 - src/procfile.c
219 - src/procfile.h
220 - src/threads.c
221 - src/threads.h
222 - config.h
223 - )
406 +include_directories(AFTER .)
407
225 -set(CGROUP_NETWORK_SOURCE_FILES
226 - src/cgroup-network.c
227 - src/common.c
228 - src/common.h
229 - src/clocks.c
230 - src/clocks.h
231 - src/inlined.h
232 - src/locks.c
233 - src/locks.h
234 - src/log.c
235 - src/log.h
236 - src/popen.c
237 - src/popen.h
238 - src/procfile.c
239 - src/procfile.h
240 - src/signals.c
241 - src/signals.h
242 - src/storage_number.c
243 - src/storage_number.h
244 - src/threads.c
245 - src/threads.h
246 - src/web_buffer.c
247 - src/web_buffer.h
248 - config.h
249 - )
408 +add_definitions(
409 + -DHAVE_CONFIG_H
410 + -DTARGET_OS=${TARGET_OS}
411 + -DCACHE_DIR="/var/cache/netdata"
412 + -DCONFIG_DIR="/etc/netdata"
413 + -DLIBCONFIG_DIR="/usr/lib/netdata/conf.d"
414 + -DLOG_DIR="/var/log/netdata"
415 + -DPLUGINS_DIR="/usr/libexec/netdata"
416 + -DWEB_DIR="/usr/share/netdata"
417 + -DVARLIB_DIR="/var/lib/netdata"
418 +)
419
251 -include_directories(AFTER .)
420 +# -----------------------------------------------------------------------------
421 +# netdata
422 +
423 +set(NETDATA_COMMON_LIBRARIES ${NETDATA_COMMON_LIBRARIES} m ${CMAKE_THREAD_LIBS_INIT})
424 +
425 +IF(LINUX)
426 + add_executable(netdata config.h ${NETDATA_FILES}
427 + ${CGROUPS_PLUGIN_FILES}
428 + ${DISKSPACE_PLUGIN_FILES}
429 + ${NFACCT_PLUGIN_FILES}
430 + ${PROC_PLUGIN_FILES}
431 + ${TC_PLUGIN_FILES}
432 + )
433 + target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES}
434 + ${MNL_LIBRARIES}
435 + ${NFACCT_LIBRARIES}
436 + )
437 + target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS}
438 + ${MNL_INCLUDE_DIRS}
439 + ${NFACCT_INCLUDE_DIRS}
440 + )
441 + target_compile_options(netdata PUBLIC ${NETDATA_COMMON_CFLAGS}
442 + ${MNL_CFLAGS_OTHER}
443 + ${NFACCT_CFLAGS_OTHER}
444 + )
445 +
446 + SET(ENABLE_PLUGIN_CGROUP_NETWORK True)
447 + SET(ENABLE_PLUGIN_APPS True)
448 + IF(IPMI_LIBRARIES)
449 + SET(ENABLE_PLUGIN_FREEIPMI True)
450 + ELSE()
451 + SET(ENABLE_PLUGIN_FREEIPMI False)
452 + ENDIF()
453 +
454 +ELSEIF(FREEBSD)
455 + add_executable(netdata config.h ${NETDATA_FILES} ${FREEBSD_PLUGIN_FILES})
456 + target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES})
457 + target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
458 + target_compile_options(netdata PUBLIC ${NETDATA_COMMON_CFLAGS})
459 + SET(ENABLE_PLUGIN_CGROUP_NETWORK False)
460 + SET(ENABLE_PLUGIN_APPS True)
461 + SET(ENABLE_PLUGIN_FREEIPMI False)
462 +
463 +ELSEIF(MACOS)
464 + add_executable(netdata config.h ${NETDATA_FILES} ${MACOS_PLUGIN_FILES})
465 + target_link_libraries (netdata libnetdata ${NETDATA_COMMON_LIBRARIES})
466 + target_include_directories(netdata PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
467 + target_compile_options(netdata PUBLIC ${NETDATA_COMMON_CFLAGS})
468 + SET(ENABLE_PLUGIN_CGROUP_NETWORK False)
469 + SET(ENABLE_PLUGIN_APPS False)
470 + SET(ENABLE_PLUGIN_FREEIPMI False)
471 +
472 +ENDIF()
473 +
474 +
475 +# -----------------------------------------------------------------------------
476 +# apps.plugin
477
253 -add_definitions(-DHAVE_CONFIG_H -DCACHE_DIR="/var/cache/netdata" -DCONFIG_DIR="/etc/netdata" -DLIBCONFIG_DIR="/usr/lib/netdata/conf.d" -DLOG_DIR="/var/log/netdata" -DPLUGINS_DIR="/usr/libexec/netdata" -DWEB_DIR="/usr/share/netdata" -DVARLIB_DIR="/var/lib/netdata")
478 +IF(ENABLE_PLUGIN_APPS)
479 + message(STATUS "apps.plugin: enabled")
480 + add_executable(apps.plugin config.h ${APPS_PLUGIN_FILES})
481 + target_link_libraries (apps.plugin libnetdata ${NETDATA_COMMON_LIBRARIES} ${CAP_LIBRARIES})
482 + target_include_directories(apps.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS} ${CAP_INCLUDE_DIRS})
483 + target_compile_options(apps.plugin PUBLIC ${NETDATA_COMMON_CFLAGS} ${CAP_CFLAGS_OTHER})
484 +ELSE()
485 + message(STATUS "apps.plugin: disabled")
486 +ENDIF()
487
255 -add_executable(netdata ${NETDATA_COMMON_FILES} ${NETDATA_LINUX_FILES})
256 -target_link_libraries (netdata m z uuid mnl netfilter_acct ${CMAKE_THREAD_LIBS_INIT})
488
258 -add_executable(netdata_freebsd ${NETDATA_COMMON_FILES} ${NETDATA_FREEBSD_FILES})
259 -target_link_libraries (netdata_freebsd m z uuid ${CMAKE_THREAD_LIBS_INIT})
489 +# -----------------------------------------------------------------------------
490 +# freeipmi.plugin
491
261 -add_executable(netdata_macos ${NETDATA_COMMON_FILES} ${NETDATA_MACOS_FILES})
262 -target_link_libraries (netdata_macos m z uuid ${CMAKE_THREAD_LIBS_INIT})
492 +IF(ENABLE_PLUGIN_FREEIPMI)
493 + message(STATUS "freeipmi.plugin: enabled")
494 + add_executable(freeipmi.plugin config.h ${FREEIPMI_PLUGIN_FILES})
495 + target_link_libraries (freeipmi.plugin libnetdata ${NETDATA_COMMON_LIBRARIES} ${IPMI_LIBRARIES})
496 + target_include_directories(apps.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS} ${IPMI_INCLUDE_DIRS})
497 + target_compile_options(apps.plugin PUBLIC ${NETDATA_COMMON_CFLAGS} ${IPMI_CFLAGS_OTHER})
498 +ELSE()
499 + message(STATUS "freeipmi.plugin: disabled (depends on libipmimonitoring)")
500 +ENDIF()
501
264 -add_executable(apps.plugin ${APPS_PLUGIN_SOURCE_FILES} src/inlined.h)
265 -target_link_libraries (apps.plugin m cap ${CMAKE_THREAD_LIBS_INIT})
502
267 -add_executable(freeipmi.plugin ${FREEIPMI_PLUGIN_SOURCE_FILES})
268 -target_link_libraries (freeipmi.plugin ipmimonitoring ${CMAKE_THREAD_LIBS_INIT})
503 +# -----------------------------------------------------------------------------
504 +# cgroup-network
505
270 -add_executable(cgroup-network ${CGROUP_NETWORK_SOURCE_FILES})
271 -target_link_libraries (cgroup-network m ${CMAKE_THREAD_LIBS_INIT})
506 +IF(ENABLE_PLUGIN_CGROUP_NETWORK)
507 + message(STATUS "cgroup-network: enabled")
508 + add_executable(cgroup-network config.h ${CGROUP_NETWORK_FILES})
509 + target_link_libraries (cgroup-network libnetdata ${NETDATA_COMMON_LIBRARIES})
510 + target_include_directories(apps.plugin PUBLIC ${NETDATA_COMMON_INCLUDE_DIRS})
511 + target_compile_options(apps.plugin PUBLIC ${NETDATA_COMMON_CFLAGS})
512 +ELSE()
513 + message(STATUS "cgroup-network: disabled (requires Linux)")
514 +ENDIF()
configure.ac
+73 -12
@@ -37,9 +37,17 @@ AC_CONFIG_AUX_DIR([.])
37 AC_CONFIG_HEADERS([config.h])
38 AC_CONFIG_MACRO_DIR([build/m4])
39 AC_CONFIG_SRCDIR([src/main.c])
40 -AM_INIT_AUTOMAKE([tar-pax])
40 +define([AUTOMATE_INIT_OPTIONS], [tar-pax subdir-objects])
41 +m4_ifdef([AM_SILENT_RULES], [
42 + define([AUTOMATE_INIT_OPTIONS], [tar-pax silent-rules subdir-objects])
43 + ])
44 +AM_INIT_AUTOMAKE(AUTOMATE_INIT_OPTIONS)
45 +m4_ifdef([AM_SILENT_RULES], [
46 + AM_SILENT_RULES([yes])
47 + ])
48 AC_CANONICAL_HOST
49 AC_PROG_CC
50 +AM_PROG_CC_C_O
51 AC_PROG_INSTALL
52 PKG_PROG_PKG_CONFIG
53 AC_USE_SYSTEM_EXTENSIONS
@@ -170,21 +178,24 @@ AC_MSG_CHECKING([operating system])
178 case "$host_os" in
179 freebsd*)
180 build_target=freebsd
181 + build_target_id=2
182 CFLAGS="${CFLAGS} -I/usr/local/include"
183 ;;
184 darwin*)
185 build_target=macos
186 + build_target_id=3
187 LDFLAGS="${LDFLAGS} -framework CoreFoundation -framework IOKit"
188 ;;
189 *)
190 build_target=linux
191 + build_target_id=1
192 ;;
193 esac
194
195 AM_CONDITIONAL([FREEBSD], [test "${build_target}" = "freebsd"])
196 AM_CONDITIONAL([MACOS], [test "${build_target}" = "macos"])
197 AM_CONDITIONAL([LINUX], [test "${build_target}" = "linux"])
187 -AC_MSG_RESULT([${build_target}])
198 +AC_MSG_RESULT([${build_target} with id ${build_target_id}])
199
200
201 # -----------------------------------------------------------------------------
@@ -486,18 +497,42 @@ AC_MSG_RESULT([${enable_lto}])
497
498 AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])
499
489 -AC_SUBST([varlibdir], ["\$(localstatedir)/lib/netdata"])
490 -AC_SUBST([registrydir], ["\$(localstatedir)/lib/netdata/registry"])
491 -AC_SUBST([cachedir], ["\$(localstatedir)/cache/netdata"])
492 -AC_SUBST([chartsdir], ["\$(libexecdir)/netdata/charts.d"])
493 -AC_SUBST([nodedir], ["\$(libexecdir)/netdata/node.d"])
494 -AC_SUBST([pythondir], ["\$(libexecdir)/netdata/python.d"])
495 -AC_SUBST([configdir], ["\$(sysconfdir)/netdata"])
496 -AC_SUBST([libconfigdir], ["\$(libdir)/netdata/conf.d"])
497 -AC_SUBST([logdir], ["\$(localstatedir)/log/netdata"])
498 -AC_SUBST([pluginsdir], ["\$(libexecdir)/netdata/plugins.d"])
500 +varlibdir="${localstatedir}/lib/netdata"
501 +registrydir="${localstatedir}/lib/netdata/registry"
502 +cachedir="${localstatedir}/cache/netdata"
503 +chartsdir="${libexecdir}/netdata/charts.d"
504 +nodedir="${libexecdir}/netdata/node.d"
505 +pythondir="${libexecdir}/netdata/python.d"
506 +configdir="${sysconfdir}/netdata"
507 +libconfigdir="${libdir}/netdata/conf.d"
508 +logdir="${localstatedir}/log/netdata"
509 +pluginsdir="${libexecdir}/netdata/plugins.d"
510 +
511 +AC_SUBST([build_target])
512 +AC_SUBST([varlibdir])
513 +AC_SUBST([registrydir])
514 +AC_SUBST([cachedir])
515 +AC_SUBST([chartsdir])
516 +AC_SUBST([nodedir])
517 +AC_SUBST([pythondir])
518 +AC_SUBST([configdir])
519 +AC_SUBST([libconfigdir])
520 +AC_SUBST([logdir])
521 +AC_SUBST([pluginsdir])
522 AC_SUBST([webdir])
523
524 +CPPFLAGS="\
525 + -DTARGET_OS=${build_target_id} \
526 + -DVARLIB_DIR=\"\\\"${varlibdir}\\\"\" \
527 + -DCACHE_DIR=\"\\\"${cachedir}\\\"\" \
528 + -DCONFIG_DIR=\"\\\"${configdir}\\\"\" \
529 + -DLIBCONFIG_DIR=\"\\\"${libconfigdir}\\\"\" \
530 + -DLOG_DIR=\"\\\"${logdir}\\\"\" \
531 + -DPLUGINS_DIR=\"\\\"${pluginsdir}\\\"\" \
532 + -DRUN_DIR=\"\\\"${localstatedir}/run/netdata\\\"\" \
533 + -DWEB_DIR=\"\\\"${webdir}\\\"\" \
534 +"
535 +
536 AC_SUBST([OPTIONAL_MATH_CLFAGS])
537 AC_SUBST([OPTIONAL_MATH_LIBS])
538 AC_SUBST([OPTIONAL_NFACCT_CLFAGS])
@@ -519,7 +554,33 @@ AC_CONFIG_FILES([
554 python.d/Makefile
555 node.d/Makefile
556 plugins.d/Makefile
557 + src/api/Makefile
558 + src/backends/graphite/Makefile
559 + src/backends/json/Makefile
560 + src/backends/Makefile
561 + src/backends/opentsdb/Makefile
562 + src/backends/prometheus/Makefile
563 + src/database/Makefile
564 + src/health/Makefile
565 + src/libnetdata/Makefile
566 src/Makefile
567 + src/plugins/apps.plugin/Makefile
568 + src/plugins/checks.plugin/Makefile
569 + src/plugins/freebsd.plugin/Makefile
570 + src/plugins/idlejitter.plugin/Makefile
571 + src/plugins/linux-cgroups.plugin/Makefile
572 + src/plugins/linux-diskspace.plugin/Makefile
573 + src/plugins/linux-freeipmi.plugin/Makefile
574 + src/plugins/linux-nfacct.plugin/Makefile
575 + src/plugins/linux-proc.plugin/Makefile
576 + src/plugins/linux-tc.plugin/Makefile
577 + src/plugins/macos.plugin/Makefile
578 + src/plugins/Makefile
579 + src/plugins/plugins.d.plugin/Makefile
580 + src/plugins/statsd.plugin/Makefile
581 + src/registry/Makefile
582 + src/streaming/Makefile
583 + src/webserver/Makefile
584 system/Makefile
585 web/Makefile
586 diagrams/Makefile
plugins.d/Makefile.am
-4
@@ -5,7 +5,6 @@
5 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
6 CLEANFILES = \
7 alarm-notify.sh \
8 - cgroup-name.sh \
8 charts.d.plugin \
9 fping.plugin \
10 node.d.plugin \
@@ -25,8 +24,6 @@ dist_plugins_SCRIPTS = \
24 alarm-email.sh \
25 alarm-notify.sh \
26 alarm-test.sh \
28 - cgroup-name.sh \
29 - cgroup-network-helper.sh \
27 charts.d.dryrun-helper.sh \
28 charts.d.plugin \
29 fping.plugin \
@@ -38,7 +35,6 @@ dist_plugins_SCRIPTS = \
35
36 dist_noinst_DATA = \
37 alarm-notify.sh.in \
41 - cgroup-name.sh.in \
38 charts.d.plugin.in \
39 fping.plugin.in \
40 node.d.plugin.in \
src/Makefile.am
+312 -255
@@ -1,18 +1,18 @@
1 -#
2 -# Copyright (C) 2015 Alon Bar-Lev <alon.barlev@gmail.com>
1 # SPDX-License-Identifier: GPL-3.0-or-later
4 -#
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
5
7 -AM_CPPFLAGS = \
8 - -DVARLIB_DIR="\"$(varlibdir)\"" \
9 - -DCACHE_DIR="\"$(cachedir)\"" \
10 - -DCONFIG_DIR="\"$(configdir)\"" \
11 - -DLIBCONFIG_DIR="\"$(libconfigdir)\"" \
12 - -DLOG_DIR="\"$(logdir)\"" \
13 - -DPLUGINS_DIR="\"$(pluginsdir)\"" \
14 - -DRUN_DIR="\"$(localstatedir)/run/netdata\"" \
15 - -DWEB_DIR="\"$(webdir)\"" \
6 +SUBDIRS = \
7 + api \
8 + backends \
9 + database \
10 + health \
11 + libnetdata \
12 + plugins \
13 + registry \
14 + streaming \
15 + webserver \
16 $(NULL)
17
18 AM_CFLAGS = \
@@ -20,287 +20,344 @@ AM_CFLAGS = \
20 $(OPTIONAL_NFACCT_CLFAGS) \
21 $(OPTIONAL_ZLIB_CFLAGS) \
22 $(OPTIONAL_UUID_CFLAGS) \
23 - $(OPTIONAL_LIBCAP_CFLAGS) \
24 - $(OPTIONAL_IPMIMONITORING_CFLAGS)\
23 + $(OPTIONAL_LIBCAP_LIBS) \
24 + $(OPTIONAL_IPMIMONITORING_CFLAGS) \
25 $(NULL)
26
27 -sbin_PROGRAMS = netdata
27 +sbin_PROGRAMS =
28 dist_cache_DATA = .keep
29 dist_varlib_DATA = .keep
30 dist_registry_DATA = .keep
31 dist_log_DATA = .keep
32 plugins_PROGRAMS =
33
34 -if ENABLE_PLUGIN_APPS
35 -plugins_PROGRAMS += apps.plugin
36 -endif
34 +LIBNETDATA_FILES = \
35 + libnetdata/adaptive_resortable_list.c \
36 + libnetdata/adaptive_resortable_list.h \
37 + libnetdata/appconfig.c \
38 + libnetdata/appconfig.h \
39 + libnetdata/avl.c \
40 + libnetdata/avl.h \
41 + libnetdata/clocks.c \
42 + libnetdata/clocks.h \
43 + libnetdata/common.c \
44 + libnetdata/dictionary.c \
45 + libnetdata/dictionary.h \
46 + libnetdata/eval.c \
47 + libnetdata/eval.h \
48 + libnetdata/inlined.h \
49 + libnetdata/libnetdata.h \
50 + libnetdata/locks.c \
51 + libnetdata/locks.h \
52 + libnetdata/log.c \
53 + libnetdata/log.h \
54 + libnetdata/popen.c \
55 + libnetdata/popen.h \
56 + libnetdata/procfile.c \
57 + libnetdata/procfile.h \
58 + libnetdata/os.c \
59 + libnetdata/os.h \
60 + libnetdata/simple_pattern.c \
61 + libnetdata/simple_pattern.h \
62 + libnetdata/socket.c \
63 + libnetdata/socket.h \
64 + libnetdata/statistical.c \
65 + libnetdata/statistical.h \
66 + libnetdata/storage_number.c \
67 + libnetdata/storage_number.h \
68 + libnetdata/threads.c \
69 + libnetdata/threads.h \
70 + libnetdata/web_buffer.c \
71 + libnetdata/web_buffer.h \
72 + libnetdata/url.c \
73 + libnetdata/url.h \
74 + $(NULL)
75
38 -if ENABLE_PLUGIN_FREEIPMI
39 -plugins_PROGRAMS += freeipmi.plugin
40 -endif
76 +APPS_PLUGIN_FILES = \
77 + plugins/apps.plugin/apps_plugin.c \
78 + $(LIBNETDATA_FILES) \
79 + $(NULL)
80
42 -if ENABLE_PLUGIN_CGROUP_NETWORK
43 -plugins_PROGRAMS += cgroup-network
44 -endif
81 +CHECKS_PLUGIN_FILES = \
82 + plugins/checks.plugin/plugin_checks.c \
83 + plugins/checks.plugin/plugin_checks.h \
84 + $(NULL)
85 +
86 +FREEBSD_PLUGIN_FILES = \
87 + plugins/freebsd.plugin/plugin_freebsd.c \
88 + plugins/freebsd.plugin/plugin_freebsd.h \
89 + plugins/freebsd.plugin/freebsd_sysctl.c \
90 + plugins/freebsd.plugin/freebsd_getmntinfo.c \
91 + plugins/freebsd.plugin/freebsd_getifaddrs.c \
92 + plugins/freebsd.plugin/freebsd_devstat.c \
93 + plugins/freebsd.plugin/freebsd_kstat_zfs.c \
94 + plugins/freebsd.plugin/freebsd_ipfw.c \
95 + plugins/linux-proc.plugin/zfs_common.c \
96 + plugins/linux-proc.plugin/zfs_common.h \
97 + $(NULL)
98 +
99 +HEALTH_PLUGIN_FILES = \
100 + health/health.c \
101 + health/health.h \
102 + health/health_config.c \
103 + health/health_json.c \
104 + health/health_log.c \
105 + $(NULL)
106 +
107 +IDLEJITTER_PLUGIN_FILES = \
108 + plugins/idlejitter.plugin/plugin_idlejitter.c \
109 + plugins/idlejitter.plugin/plugin_idlejitter.h \
110 + $(NULL)
111 +
112 +CGROUPS_PLUGIN_FILES = \
113 + plugins/linux-cgroups.plugin/sys_fs_cgroup.c \
114 + plugins/linux-cgroups.plugin/sys_fs_cgroup.h \
115 + $(NULL)
116 +
117 +CGROUP_NETWORK_FILES = \
118 + plugins/linux-cgroups.plugin/cgroup-network.c \
119 + $(LIBNETDATA_FILES) \
120 + $(NULL)
121 +
122 +DISKSPACE_PLUGIN_FILES = \
123 + plugins/linux-diskspace.plugin/plugin_diskspace.h \
124 + plugins/linux-diskspace.plugin/plugin_diskspace.c \
125 + $(NULL)
126 +
127 +FREEIPMI_PLUGIN_FILES = \
128 + plugins/linux-freeipmi.plugin/freeipmi_plugin.c \
129 + $(LIBNETDATA_FILES) \
130 + $(NULL)
131 +
132 +NFACCT_PLUGIN_FILES = \
133 + plugins/linux-nfacct.plugin/plugin_nfacct.c \
134 + plugins/linux-nfacct.plugin/plugin_nfacct.h \
135 + $(NULL)
136 +
137 +PROC_PLUGIN_FILES = \
138 + plugins/linux-proc.plugin/ipc.c \
139 + plugins/linux-proc.plugin/plugin_proc.c \
140 + plugins/linux-proc.plugin/plugin_proc.h \
141 + plugins/linux-proc.plugin/proc_diskstats.c \
142 + plugins/linux-proc.plugin/proc_interrupts.c \
143 + plugins/linux-proc.plugin/proc_softirqs.c \
144 + plugins/linux-proc.plugin/proc_loadavg.c \
145 + plugins/linux-proc.plugin/proc_meminfo.c \
146 + plugins/linux-proc.plugin/proc_net_dev.c \
147 + plugins/linux-proc.plugin/proc_net_ip_vs_stats.c \
148 + plugins/linux-proc.plugin/proc_net_netstat.c \
149 + plugins/linux-proc.plugin/proc_net_rpc_nfs.c \
150 + plugins/linux-proc.plugin/proc_net_rpc_nfsd.c \
151 + plugins/linux-proc.plugin/proc_net_snmp.c \
152 + plugins/linux-proc.plugin/proc_net_snmp6.c \
153 + plugins/linux-proc.plugin/proc_net_sctp_snmp.c \
154 + plugins/linux-proc.plugin/proc_net_sockstat.c \
155 + plugins/linux-proc.plugin/proc_net_sockstat6.c \
156 + plugins/linux-proc.plugin/proc_net_softnet_stat.c \
157 + plugins/linux-proc.plugin/proc_net_stat_conntrack.c \
158 + plugins/linux-proc.plugin/proc_net_stat_synproxy.c \
159 + plugins/linux-proc.plugin/proc_self_mountinfo.c \
160 + plugins/linux-proc.plugin/proc_self_mountinfo.h \
161 + plugins/linux-proc.plugin/zfs_common.c \
162 + plugins/linux-proc.plugin/zfs_common.h \
163 + plugins/linux-proc.plugin/proc_spl_kstat_zfs.c \
164 + plugins/linux-proc.plugin/proc_stat.c \
165 + plugins/linux-proc.plugin/proc_sys_kernel_random_entropy_avail.c \
166 + plugins/linux-proc.plugin/proc_vmstat.c \
167 + plugins/linux-proc.plugin/proc_uptime.c \
168 + plugins/linux-proc.plugin/sys_kernel_mm_ksm.c \
169 + plugins/linux-proc.plugin/sys_devices_system_edac_mc.c \
170 + plugins/linux-proc.plugin/sys_devices_system_node.c \
171 + plugins/linux-proc.plugin/sys_fs_btrfs.c \
172 + $(NULL)
173 +
174 +TC_PLUGIN_FILES = \
175 + plugins/linux-tc.plugin/plugin_tc.c \
176 + plugins/linux-tc.plugin/plugin_tc.h \
177 + $(NULL)
178 +
179 +MACOS_PLUGIN_FILES = \
180 + plugins/macos.plugin/plugin_macos.c \
181 + plugins/macos.plugin/plugin_macos.h \
182 + plugins/macos.plugin/macos_sysctl.c \
183 + plugins/macos.plugin/macos_mach_smi.c \
184 + plugins/macos.plugin/macos_fw.c \
185 + $(NULL)
186 +
187 +PLUGINSD_PLUGIN_FILES = \
188 + plugins/plugins.d.plugin/plugins_d.c \
189 + plugins/plugins.d.plugin/plugins_d.h \
190 + $(NULL)
191 +
192 +RRD_PLUGIN_FILES = \
193 + database/rrdcalc.c \
194 + database/rrdcalc.h \
195 + database/rrdcalctemplate.c \
196 + database/rrdcalctemplate.h \
197 + database/rrddim.c \
198 + database/rrddimvar.c \
199 + database/rrddimvar.h \
200 + database/rrdfamily.c \
201 + database/rrdhost.c \
202 + database/rrd.c \
203 + database/rrd.h \
204 + database/rrdset.c \
205 + database/rrdsetvar.c \
206 + database/rrdsetvar.h \
207 + database/rrdvar.c \
208 + database/rrdvar.h \
209 + $(NULL)
210 +
211 +API_PLUGIN_FILES = \
212 + api/rrd2json.c \
213 + api/rrd2json.h \
214 + api/web_api_v1.c \
215 + api/web_api_v1.h \
216 + api/web_buffer_svg.c \
217 + api/web_buffer_svg.h \
218 + $(NULL)
219 +
220 +STREAMING_PLUGIN_FILES = \
221 + streaming/rrdpush.c \
222 + streaming/rrdpush.h \
223 + $(NULL)
224 +
225 +REGISTRY_PLUGIN_FILES = \
226 + registry/registry.c \
227 + registry/registry.h \
228 + registry/registry_db.c \
229 + registry/registry_init.c \
230 + registry/registry_internals.c \
231 + registry/registry_internals.h \
232 + registry/registry_log.c \
233 + registry/registry_machine.c \
234 + registry/registry_machine.h \
235 + registry/registry_person.c \
236 + registry/registry_person.h \
237 + registry/registry_url.c \
238 + registry/registry_url.h \
239 + $(NULL)
240 +
241 +STATSD_PLUGIN_FILES = \
242 + plugins/statsd.plugin/statsd.c \
243 + plugins/statsd.plugin/statsd.h \
244 + $(NULL)
245 +
246 +WEB_PLGUGIN_FILES = \
247 + webserver/web_client.c \
248 + webserver/web_client.h \
249 + webserver/web_server.c \
250 + webserver/web_server.h \
251 + $(NULL)
252
46 -netdata_SOURCES = \
47 - adaptive_resortable_list.c \
48 - adaptive_resortable_list.h \
49 - appconfig.c \
50 - appconfig.h \
51 - avl.c \
52 - avl.h \
53 - backend_prometheus.c \
54 - backend_prometheus.h \
55 - backends.c \
56 - backends.h \
57 - clocks.c \
58 - clocks.h \
253 +BACKENDS_PLUGIN_FILES = \
254 + backends/backends.c \
255 + backends/backends.h \
256 + backends/graphite/graphite.c \
257 + backends/graphite/graphite.h \
258 + backends/json/json.c \
259 + backends/json/json.h \
260 + backends/opentsdb/opentsdb.c \
261 + backends/opentsdb/opentsdb.h \
262 + backends/prometheus/backend_prometheus.c \
263 + backends/prometheus/backend_prometheus.h \
264 + $(NULL)
265 +
266 +WEB_PLUGIN_FILES = \
267 + webserver/web_client.c \
268 + webserver/web_client.h \
269 + webserver/web_server.c \
270 + webserver/web_server.h \
271 + $(NULL)
272 +
273 +NETDATA_FILES = \
274 + plugins/all.h \
275 common.c \
276 common.h \
277 daemon.c \
278 daemon.h \
63 - dictionary.c \
64 - dictionary.h \
65 - eval.c \
66 - eval.h \
279 global_statistics.c \
280 global_statistics.h \
69 - health.c \
70 - health.h \
71 - health_config.c \
72 - health_json.c \
73 - health_log.c \
74 - inlined.h \
75 - locks.c \
76 - locks.h \
77 - log.c \
78 - log.h \
281 main.c \
282 main.h \
81 - plugin_checks.c \
82 - plugin_checks.h \
83 - plugin_idlejitter.c \
84 - plugin_idlejitter.h \
85 - plugins_d.c \
86 - plugins_d.h \
87 - popen.c \
88 - popen.h \
89 - procfile.c \
90 - procfile.h \
91 - registry.c \
92 - registry.h \
93 - registry_db.c \
94 - registry_init.c \
95 - registry_internals.c \
96 - registry_internals.h \
97 - registry_log.c \
98 - registry_machine.c \
99 - registry_machine.h \
100 - registry_person.c \
101 - registry_person.h \
102 - registry_url.c \
103 - registry_url.h \
104 - rrd.c \
105 - rrd.h \
106 - rrd2json.c \
107 - rrd2json.h \
108 - rrdcalc.c \
109 - rrdcalctemplate.c \
110 - rrddim.c \
111 - rrddimvar.c \
112 - rrdfamily.c \
113 - rrdhost.c \
114 - rrdpush.c \
115 - rrdpush.h \
116 - rrdset.c \
117 - rrdsetvar.c \
118 - rrdvar.c \
283 signals.c \
284 signals.h \
121 - simple_pattern.c \
122 - simple_pattern.h \
123 - socket.c \
124 - socket.h \
125 - statistical.c \
126 - statistical.h \
127 - statsd.c \
128 - statsd.h \
129 - storage_number.c \
130 - storage_number.h \
131 - threads.c \
132 - threads.h \
285 unit_test.c \
286 unit_test.h \
135 - url.c \
136 - url.h \
137 - web_api_v1.c \
138 - web_api_v1.h \
139 - web_buffer.c \
140 - web_buffer.h \
141 - web_buffer_svg.c \
142 - web_buffer_svg.h \
143 - web_client.c \
144 - web_client.h \
145 - web_server.c \
146 - web_server.h \
287 + $(LIBNETDATA_FILES) \
288 + $(API_PLUGIN_FILES) \
289 + $(BACKENDS_PLUGIN_FILES) \
290 + $(CHECKS_PLUGIN_FILES) \
291 + $(HEALTH_PLUGIN_FILES) \
292 + $(IDLEJITTER_PLUGIN_FILES) \
293 + $(PLUGINSD_PLUGIN_FILES) \
294 + $(REGISTRY_PLUGIN_FILES) \
295 + $(RRD_PLUGIN_FILES) \
296 + $(STREAMING_PLUGIN_FILES) \
297 + $(STATSD_PLUGIN_FILES) \
298 + $(WEB_PLUGIN_FILES) \
299 $(NULL)
300
301 if FREEBSD
150 -netdata_SOURCES += \
151 - plugin_freebsd.c \
152 - plugin_freebsd.h \
153 - freebsd_sysctl.c \
154 - freebsd_getmntinfo.c \
155 - freebsd_getifaddrs.c \
156 - freebsd_devstat.c \
157 - zfs_common.c \
158 - zfs_common.h \
159 - freebsd_kstat_zfs.c \
160 - freebsd_ipfw.c \
161 - $(NULL)
162 -else
302 + NETDATA_FILES += \
303 + $(FREEBSD_PLUGIN_FILES) \
304 + $(NULL)
305 +endif
306 +
307 if MACOS
164 -netdata_SOURCES += \
165 - plugin_macos.c \
166 - plugin_macos.h \
167 - macos_sysctl.c \
168 - macos_mach_smi.c \
169 - macos_fw.c \
170 - $(NULL)
171 -else
172 -netdata_SOURCES += \
173 - ipc.c \
174 - ipc.h \
175 - plugin_nfacct.c \
176 - plugin_nfacct.h \
177 - plugin_proc.c \
178 - plugin_proc.h \
179 - plugin_proc_diskspace.c \
180 - plugin_proc_diskspace.h \
181 - plugin_tc.c \
182 - plugin_tc.h \
183 - proc_diskstats.c \
184 - proc_interrupts.c \
185 - proc_softirqs.c \
186 - proc_loadavg.c \
187 - proc_meminfo.c \
188 - proc_net_dev.c \
189 - proc_net_ip_vs_stats.c \
190 - proc_net_netstat.c \
191 - proc_net_rpc_nfs.c \
192 - proc_net_rpc_nfsd.c \
193 - proc_net_snmp.c \
194 - proc_net_snmp6.c \
195 - proc_net_sctp_snmp.c \
196 - proc_net_sockstat.c \
197 - proc_net_sockstat6.c \
198 - proc_net_softnet_stat.c \
199 - proc_net_stat_conntrack.c \
200 - proc_net_stat_synproxy.c \
201 - proc_self_mountinfo.c \
202 - proc_self_mountinfo.h \
203 - zfs_common.c \
204 - zfs_common.h \
205 - proc_spl_kstat_zfs.c \
206 - proc_stat.c \
207 - proc_sys_kernel_random_entropy_avail.c \
208 - proc_vmstat.c \
209 - proc_uptime.c \
210 - sys_kernel_mm_ksm.c \
211 - sys_devices_system_edac_mc.c \
212 - sys_devices_system_node.c \
213 - sys_fs_cgroup.c \
214 - sys_fs_btrfs.c \
215 - $(NULL)
308 + NETDATA_FILES += \
309 + $(MACOS_PLUGIN_FILES) \
310 + $(NULL)
311 endif
312 +
313 +if LINUX
314 + NETDATA_FILES += \
315 + $(CGROUPS_PLUGIN_FILES) \
316 + $(DISKSPACE_PLUGIN_FILES) \
317 + $(NFACCT_PLUGIN_FILES) \
318 + $(PROC_PLUGIN_FILES) \
319 + $(TC_PLUGIN_FILES) \
320 + $(NULL)
321 +
322 endif
323
219 -netdata_LDADD = \
324 +NETDATA_COMMON_LIBS = \
325 $(OPTIONAL_MATH_LIBS) \
221 - $(OPTIONAL_NFACCT_LIBS) \
326 $(OPTIONAL_ZLIB_LIBS) \
327 $(OPTIONAL_UUID_LIBS) \
328 $(NULL)
329
226 -apps_plugin_SOURCES = \
227 - apps_plugin.c \
228 - avl.c \
229 - avl.h \
230 - clocks.c \
231 - clocks.h \
232 - common.c \
233 - common.h \
234 - inlined.h \
235 - locks.c \
236 - locks.h \
237 - log.c log.h \
238 - procfile.c \
239 - procfile.h \
240 - threads.c \
241 - threads.h \
242 - web_buffer.c \
243 - web_buffer.h \
244 - $(NULL)
245 -
246 -if FREEBSD
247 -apps_plugin_SOURCES += \
248 - plugin_freebsd.h \
249 - $(NULL)
250 -else
251 -apps_plugin_SOURCES += \
252 - adaptive_resortable_list.c \
253 - adaptive_resortable_list.h \
254 - $(NULL)
255 -endif
330
257 -apps_plugin_LDADD = \
258 - $(OPTIONAL_MATH_LIBS) \
259 - $(OPTIONAL_LIBCAP_LIBS) \
331 +sbin_PROGRAMS += netdata
332 +netdata_SOURCES = ../config.h $(NETDATA_FILES)
333 +netdata_LDADD = \
334 + $(NETDATA_COMMON_LIBS) \
335 + $(OPTIONAL_NFACCT_LIBS) \
336 $(NULL)
337
262 -freeipmi_plugin_SOURCES = \
263 - freeipmi_plugin.c \
264 - clocks.c \
265 - clocks.h \
266 - common.c \
267 - common.h \
268 - inlined.h \
269 - locks.c \
270 - locks.h \
271 - log.c log.h \
272 - procfile.c \
273 - procfile.h \
274 - threads.c \
275 - threads.h \
276 - $(NULL)
338 +if ENABLE_PLUGIN_APPS
339 + plugins_PROGRAMS += apps.plugin
340 + apps_plugin_SOURCES = ../config.h $(APPS_PLUGIN_FILES)
341 + apps_plugin_LDADD = \
342 + $(NETDATA_COMMON_LIBS) \
343 + $(OPTIONAL_LIBCAP_LIBS) \
344 + $(NULL)
345 +endif
346
278 -freeipmi_plugin_LDADD = \
279 - $(OPTIONAL_IPMIMONITORING_LIBS) \
280 - $(NULL)
347 +if ENABLE_PLUGIN_CGROUP_NETWORK
348 + plugins_PROGRAMS += cgroup-network
349 + cgroup_network_SOURCES = ../config.h $(CGROUP_NETWORK_FILES)
350 + cgroup_network_LDADD = \
351 + $(NETDATA_COMMON_LIBS) \
352 + $(NULL)
353 +endif
354
282 -cgroup_network_SOURCES = \
283 - cgroup-network.c \
284 - clocks.c \
285 - clocks.h \
286 - common.c \
287 - common.h \
288 - inlined.h \
289 - locks.c \
290 - locks.h \
291 - log.c \
292 - log.h \
293 - procfile.c \
294 - procfile.h \
295 - popen.c \
296 - popen.h \
297 - signals.c \
298 - signals.h \
299 - threads.c \
300 - threads.h \
301 - $(NULL)
355 +if ENABLE_PLUGIN_FREEIPMI
356 + plugins_PROGRAMS += freeipmi.plugin
357 + freeipmi_plugin_SOURCES = ../config.h $(FREEIPMI_PLUGIN_FILES)
358 + freeipmi_plugin_LDADD = \
359 + $(NETDATA_COMMON_LIBS) \
360 + $(OPTIONAL_IPMIMONITORING_LIBS) \
361 + $(NULL)
362 +endif
363
303 -cgroup_network_LDADD = \
304 - $(OPTIONAL_MATH_LIBS) \
305 - $(OPTIONAL_LIBCAP_LIBS) \
306 - $(NULL)
src/api/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/api/rrd2json.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "web_api_v1.h"
4
5 void rrd_stats_api_v1_chart_with_data(RRDSET *st, BUFFER *wb, size_t *dimensions_count, size_t *memory_used)
6 {
src/api/rrd2json.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_RRD2JSON_H
4 #define NETDATA_RRD2JSON_H 1
5
6 +#include "web_api_v1.h"
7 +
8 #define HOSTNAME_MAX 1024
9
10 #define API_RELATIVE_TIME_MAX (3 * 365 * 86400)
src/api/web_api_v1.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "web_api_v1.h"
4
5 static struct {
6 const char *name;
src/api/web_api_v1.h renamed
+4
@@ -3,6 +3,10 @@
3 #ifndef NETDATA_WEB_API_V1_H
4 #define NETDATA_WEB_API_V1_H 1
5
6 +#include "../common.h"
7 +#include "web_buffer_svg.h"
8 +#include "rrd2json.h"
9 +
10 extern int web_client_api_request_v1_data_group(char *name, int def);
11 extern uint32_t web_client_api_request_v1_data_options(char *o);
12 extern uint32_t web_client_api_request_v1_data_format(char *name);
src/api/web_buffer_svg.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4
5 #define BADGE_HORIZONTAL_PADDING 4
6 #define VERDANA_KERNING 0.2
src/api/web_buffer_svg.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_WEB_BUFFER_SVG_H
4 #define NETDATA_WEB_BUFFER_SVG_H 1
5
6 +#include "web_api_v1.h"
7 +
8 extern void buffer_svg(BUFFER *wb, const char *label, calculated_number value, const char *units, const char *label_color, const char *value_color, int precision, int scale, uint32_t options);
9 extern char *format_value_and_unit(char *value_string, size_t value_string_len, calculated_number value, const char *units, int precision);
10
src/backends/Makefile.am new
+11
@@ -0,0 +1,11 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
6 +SUBDIRS = \
7 + graphite \
8 + json \
9 + opentsdb \
10 + prometheus \
11 + $(NULL)
src/backends/backends.c renamed
+3 -320
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4
5 // ----------------------------------------------------------------------------
6 // How backends work in netdata:
@@ -31,7 +31,7 @@ BACKEND_OPTIONS global_backend_options = BACKEND_SOURCE_DATA_AVERAGE | BACKEND_O
31 // ----------------------------------------------------------------------------
32 // helper functions for backends
33
34 -static inline size_t backend_name_copy(char *d, const char *s, size_t usable) {
34 +size_t backend_name_copy(char *d, const char *s, size_t usable) {
35 size_t n;
36
37 for(n = 0; *s && n < usable ; d++, s++, n++) {
@@ -143,7 +143,7 @@ inline calculated_number backend_calculate_value_from_stored_data(
143 // discard a response received by a backend
144 // after logging a simple of it to error.log
145
146 -static inline int discard_response(BUFFER *b, const char *backend) {
146 +int discard_response(BUFFER *b, const char *backend) {
147 char sample[1024];
148 const char *s = buffer_tostring(b);
149 char *d = sample, *e = &sample[sizeof(sample) - 1];
@@ -161,323 +161,6 @@ static inline int discard_response(BUFFER *b, const char *backend) {
161 }
162
163
164 -// ----------------------------------------------------------------------------
165 -// graphite backend
166 -
167 -static inline int format_dimension_collected_graphite_plaintext(
168 - BUFFER *b // the buffer to write data to
169 - , const char *prefix // the prefix to use
170 - , RRDHOST *host // the host this chart comes from
171 - , const char *hostname // the hostname (to override host->hostname)
172 - , RRDSET *st // the chart
173 - , RRDDIM *rd // the dimension
174 - , time_t after // the start timestamp
175 - , time_t before // the end timestamp
176 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
177 -) {
178 - (void)host;
179 - (void)after;
180 - (void)before;
181 -
182 - char chart_name[RRD_ID_LENGTH_MAX + 1];
183 - char dimension_name[RRD_ID_LENGTH_MAX + 1];
184 - backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
185 - backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
186 -
187 - buffer_sprintf(
188 - b
189 - , "%s.%s.%s.%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n"
190 - , prefix
191 - , hostname
192 - , chart_name
193 - , dimension_name
194 - , (host->tags)?";":""
195 - , (host->tags)?host->tags:""
196 - , rd->last_collected_value
197 - , (unsigned long long)rd->last_collected_time.tv_sec
198 - );
199 -
200 - return 1;
201 -}
202 -
203 -static inline int format_dimension_stored_graphite_plaintext(
204 - BUFFER *b // the buffer to write data to
205 - , const char *prefix // the prefix to use
206 - , RRDHOST *host // the host this chart comes from
207 - , const char *hostname // the hostname (to override host->hostname)
208 - , RRDSET *st // the chart
209 - , RRDDIM *rd // the dimension
210 - , time_t after // the start timestamp
211 - , time_t before // the end timestamp
212 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
213 -) {
214 - (void)host;
215 -
216 - char chart_name[RRD_ID_LENGTH_MAX + 1];
217 - char dimension_name[RRD_ID_LENGTH_MAX + 1];
218 - backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
219 - backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
220 -
221 - time_t first_t = after, last_t = before;
222 - calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
223 -
224 - if(!isnan(value)) {
225 -
226 - buffer_sprintf(
227 - b
228 - , "%s.%s.%s.%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n"
229 - , prefix
230 - , hostname
231 - , chart_name
232 - , dimension_name
233 - , (host->tags)?";":""
234 - , (host->tags)?host->tags:""
235 - , value
236 - , (unsigned long long) last_t
237 - );
238 -
239 - return 1;
240 - }
241 - return 0;
242 -}
243 -
244 -static inline int process_graphite_response(BUFFER *b) {
245 - return discard_response(b, "graphite");
246 -}
247 -
248 -
249 -// ----------------------------------------------------------------------------
250 -// opentsdb backend
251 -
252 -static inline int format_dimension_collected_opentsdb_telnet(
253 - BUFFER *b // the buffer to write data to
254 - , const char *prefix // the prefix to use
255 - , RRDHOST *host // the host this chart comes from
256 - , const char *hostname // the hostname (to override host->hostname)
257 - , RRDSET *st // the chart
258 - , RRDDIM *rd // the dimension
259 - , time_t after // the start timestamp
260 - , time_t before // the end timestamp
261 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
262 -) {
263 - (void)host;
264 - (void)after;
265 - (void)before;
266 -
267 - char chart_name[RRD_ID_LENGTH_MAX + 1];
268 - char dimension_name[RRD_ID_LENGTH_MAX + 1];
269 - backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
270 - backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
271 -
272 - buffer_sprintf(
273 - b
274 - , "put %s.%s.%s %llu " COLLECTED_NUMBER_FORMAT " host=%s%s%s\n"
275 - , prefix
276 - , chart_name
277 - , dimension_name
278 - , (unsigned long long)rd->last_collected_time.tv_sec
279 - , rd->last_collected_value
280 - , hostname
281 - , (host->tags)?" ":""
282 - , (host->tags)?host->tags:""
283 - );
284 -
285 - return 1;
286 -}
287 -
288 -static inline int format_dimension_stored_opentsdb_telnet(
289 - BUFFER *b // the buffer to write data to
290 - , const char *prefix // the prefix to use
291 - , RRDHOST *host // the host this chart comes from
292 - , const char *hostname // the hostname (to override host->hostname)
293 - , RRDSET *st // the chart
294 - , RRDDIM *rd // the dimension
295 - , time_t after // the start timestamp
296 - , time_t before // the end timestamp
297 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
298 -) {
299 - (void)host;
300 -
301 - time_t first_t = after, last_t = before;
302 - calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
303 -
304 - char chart_name[RRD_ID_LENGTH_MAX + 1];
305 - char dimension_name[RRD_ID_LENGTH_MAX + 1];
306 - backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
307 - backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
308 -
309 - if(!isnan(value)) {
310 -
311 - buffer_sprintf(
312 - b
313 - , "put %s.%s.%s %llu " CALCULATED_NUMBER_FORMAT " host=%s%s%s\n"
314 - , prefix
315 - , chart_name
316 - , dimension_name
317 - , (unsigned long long) last_t
318 - , value
319 - , hostname
320 - , (host->tags)?" ":""
321 - , (host->tags)?host->tags:""
322 - );
323 -
324 - return 1;
325 - }
326 - return 0;
327 -}
328 -
329 -static inline int process_opentsdb_response(BUFFER *b) {
330 - return discard_response(b, "opentsdb");
331 -}
332 -
333 -
334 -// ----------------------------------------------------------------------------
335 -// json backend
336 -
337 -static inline int format_dimension_collected_json_plaintext(
338 - BUFFER *b // the buffer to write data to
339 - , const char *prefix // the prefix to use
340 - , RRDHOST *host // the host this chart comes from
341 - , const char *hostname // the hostname (to override host->hostname)
342 - , RRDSET *st // the chart
343 - , RRDDIM *rd // the dimension
344 - , time_t after // the start timestamp
345 - , time_t before // the end timestamp
346 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
347 -) {
348 - (void)host;
349 - (void)after;
350 - (void)before;
351 - (void)backend_options;
352 -
353 - const char *tags_pre = "", *tags_post = "", *tags = host->tags;
354 - if(!tags) tags = "";
355 -
356 - if(*tags) {
357 - if(*tags == '{' || *tags == '[' || *tags == '"') {
358 - tags_pre = "\"host_tags\":";
359 - tags_post = ",";
360 - }
361 - else {
362 - tags_pre = "\"host_tags\":\"";
363 - tags_post = "\",";
364 - }
365 - }
366 -
367 - buffer_sprintf(b, "{"
368 - "\"prefix\":\"%s\","
369 - "\"hostname\":\"%s\","
370 - "%s%s%s"
371 -
372 - "\"chart_id\":\"%s\","
373 - "\"chart_name\":\"%s\","
374 - "\"chart_family\":\"%s\","
375 - "\"chart_context\": \"%s\","
376 - "\"chart_type\":\"%s\","
377 - "\"units\": \"%s\","
378 -
379 - "\"id\":\"%s\","
380 - "\"name\":\"%s\","
381 - "\"value\":" COLLECTED_NUMBER_FORMAT ","
382 -
383 - "\"timestamp\": %llu}\n",
384 - prefix,
385 - hostname,
386 - tags_pre, tags, tags_post,
387 -
388 - st->id,
389 - st->name,
390 - st->family,
391 - st->context,
392 - st->type,
393 - st->units,
394 -
395 - rd->id,
396 - rd->name,
397 - rd->last_collected_value,
398 -
399 - (unsigned long long) rd->last_collected_time.tv_sec
400 - );
401 -
402 - return 1;
403 -}
404 -
405 -static inline int format_dimension_stored_json_plaintext(
406 - BUFFER *b // the buffer to write data to
407 - , const char *prefix // the prefix to use
408 - , RRDHOST *host // the host this chart comes from
409 - , const char *hostname // the hostname (to override host->hostname)
410 - , RRDSET *st // the chart
411 - , RRDDIM *rd // the dimension
412 - , time_t after // the start timestamp
413 - , time_t before // the end timestamp
414 - , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
415 -) {
416 - (void)host;
417 -
418 - time_t first_t = after, last_t = before;
419 - calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
420 -
421 - if(!isnan(value)) {
422 - const char *tags_pre = "", *tags_post = "", *tags = host->tags;
423 - if(!tags) tags = "";
424 -
425 - if(*tags) {
426 - if(*tags == '{' || *tags == '[' || *tags == '"') {
427 - tags_pre = "\"host_tags\":";
428 - tags_post = ",";
429 - }
430 - else {
431 - tags_pre = "\"host_tags\":\"";
432 - tags_post = "\",";
433 - }
434 - }
435 -
436 - buffer_sprintf(b, "{"
437 - "\"prefix\":\"%s\","
438 - "\"hostname\":\"%s\","
439 - "%s%s%s"
440 -
441 - "\"chart_id\":\"%s\","
442 - "\"chart_name\":\"%s\","
443 - "\"chart_family\":\"%s\","
444 - "\"chart_context\": \"%s\","
445 - "\"chart_type\":\"%s\","
446 - "\"units\": \"%s\","
447 -
448 - "\"id\":\"%s\","
449 - "\"name\":\"%s\","
450 - "\"value\":" CALCULATED_NUMBER_FORMAT ","
451 -
452 - "\"timestamp\": %llu}\n",
453 - prefix,
454 - hostname,
455 - tags_pre, tags, tags_post,
456 -
457 - st->id,
458 - st->name,
459 - st->family,
460 - st->context,
461 - st->type,
462 - st->units,
463 -
464 - rd->id,
465 - rd->name,
466 - value,
467 -
468 - (unsigned long long) last_t
469 - );
470 -
471 - return 1;
472 - }
473 - return 0;
474 -}
475 -
476 -static inline int process_json_response(BUFFER *b) {
477 - return discard_response(b, "json");
478 -}
479 -
480 -
164 // ----------------------------------------------------------------------------
165 // the backend thread
166
src/backends/backends.h renamed
+12
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_BACKENDS_H
4 #define NETDATA_BACKENDS_H 1
5
6 +#include "../common.h"
7 +
8 typedef enum backend_options {
9 BACKEND_OPTION_NONE = 0,
10
@@ -35,4 +37,14 @@ extern calculated_number backend_calculate_value_from_stored_data(
37 , time_t *last_timestamp // the timestamp that should be reported to backend
38 );
39
40 +#ifdef BACKENDS_INTERNALS
41 +extern size_t backend_name_copy(char *d, const char *s, size_t usable);
42 +extern int discard_response(BUFFER *b, const char *backend);
43 +#endif // BACKENDS_INTERNALS
44 +
45 +#include "prometheus/backend_prometheus.h"
46 +#include "graphite/graphite.h"
47 +#include "json/json.h"
48 +#include "opentsdb/opentsdb.h"
49 +
50 #endif /* NETDATA_BACKENDS_H */
src/backends/graphite/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/backends/graphite/graphite.c new
+90
@@ -0,0 +1,90 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#define BACKENDS_INTERNALS
4 +#include "graphite.h"
5 +
6 +// ----------------------------------------------------------------------------
7 +// graphite backend
8 +
9 +int format_dimension_collected_graphite_plaintext(
10 + BUFFER *b // the buffer to write data to
11 + , const char *prefix // the prefix to use
12 + , RRDHOST *host // the host this chart comes from
13 + , const char *hostname // the hostname (to override host->hostname)
14 + , RRDSET *st // the chart
15 + , RRDDIM *rd // the dimension
16 + , time_t after // the start timestamp
17 + , time_t before // the end timestamp
18 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
19 +) {
20 + (void)host;
21 + (void)after;
22 + (void)before;
23 +
24 + char chart_name[RRD_ID_LENGTH_MAX + 1];
25 + char dimension_name[RRD_ID_LENGTH_MAX + 1];
26 + backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
27 + backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
28 +
29 + buffer_sprintf(
30 + b
31 + , "%s.%s.%s.%s%s%s " COLLECTED_NUMBER_FORMAT " %llu\n"
32 + , prefix
33 + , hostname
34 + , chart_name
35 + , dimension_name
36 + , (host->tags)?";":""
37 + , (host->tags)?host->tags:""
38 + , rd->last_collected_value
39 + , (unsigned long long)rd->last_collected_time.tv_sec
40 + );
41 +
42 + return 1;
43 +}
44 +
45 +int format_dimension_stored_graphite_plaintext(
46 + BUFFER *b // the buffer to write data to
47 + , const char *prefix // the prefix to use
48 + , RRDHOST *host // the host this chart comes from
49 + , const char *hostname // the hostname (to override host->hostname)
50 + , RRDSET *st // the chart
51 + , RRDDIM *rd // the dimension
52 + , time_t after // the start timestamp
53 + , time_t before // the end timestamp
54 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
55 +) {
56 + (void)host;
57 +
58 + char chart_name[RRD_ID_LENGTH_MAX + 1];
59 + char dimension_name[RRD_ID_LENGTH_MAX + 1];
60 + backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
61 + backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
62 +
63 + time_t first_t = after, last_t = before;
64 + calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
65 +
66 + if(!isnan(value)) {
67 +
68 + buffer_sprintf(
69 + b
70 + , "%s.%s.%s.%s%s%s " CALCULATED_NUMBER_FORMAT " %llu\n"
71 + , prefix
72 + , hostname
73 + , chart_name
74 + , dimension_name
75 + , (host->tags)?";":""
76 + , (host->tags)?host->tags:""
77 + , value
78 + , (unsigned long long) last_t
79 + );
80 +
81 + return 1;
82 + }
83 + return 0;
84 +}
85 +
86 +int process_graphite_response(BUFFER *b) {
87 + return discard_response(b, "graphite");
88 +}
89 +
90 +
src/backends/graphite/graphite.h new
+35
@@ -0,0 +1,35 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +
4 +#ifndef NETDATA_BACKEND_GRAPHITE_H
5 +#define NETDATA_BACKEND_GRAPHITE_H
6 +
7 +#include "../backends.h"
8 +
9 +extern int format_dimension_collected_graphite_plaintext(
10 + BUFFER *b // the buffer to write data to
11 + , const char *prefix // the prefix to use
12 + , RRDHOST *host // the host this chart comes from
13 + , const char *hostname // the hostname (to override host->hostname)
14 + , RRDSET *st // the chart
15 + , RRDDIM *rd // the dimension
16 + , time_t after // the start timestamp
17 + , time_t before // the end timestamp
18 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
19 +);
20 +
21 +extern int format_dimension_stored_graphite_plaintext(
22 + BUFFER *b // the buffer to write data to
23 + , const char *prefix // the prefix to use
24 + , RRDHOST *host // the host this chart comes from
25 + , const char *hostname // the hostname (to override host->hostname)
26 + , RRDSET *st // the chart
27 + , RRDDIM *rd // the dimension
28 + , time_t after // the start timestamp
29 + , time_t before // the end timestamp
30 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
31 +);
32 +
33 +extern int process_graphite_response(BUFFER *b);
34 +
35 +#endif //NETDATA_BACKEND_GRAPHITE_H
src/backends/json/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/backends/json/json.c new
+152
@@ -0,0 +1,152 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#define BACKENDS_INTERNALS
4 +#include "json.h"
5 +
6 +// ----------------------------------------------------------------------------
7 +// json backend
8 +
9 +int format_dimension_collected_json_plaintext(
10 + BUFFER *b // the buffer to write data to
11 + , const char *prefix // the prefix to use
12 + , RRDHOST *host // the host this chart comes from
13 + , const char *hostname // the hostname (to override host->hostname)
14 + , RRDSET *st // the chart
15 + , RRDDIM *rd // the dimension
16 + , time_t after // the start timestamp
17 + , time_t before // the end timestamp
18 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
19 +) {
20 + (void)host;
21 + (void)after;
22 + (void)before;
23 + (void)backend_options;
24 +
25 + const char *tags_pre = "", *tags_post = "", *tags = host->tags;
26 + if(!tags) tags = "";
27 +
28 + if(*tags) {
29 + if(*tags == '{' || *tags == '[' || *tags == '"') {
30 + tags_pre = "\"host_tags\":";
31 + tags_post = ",";
32 + }
33 + else {
34 + tags_pre = "\"host_tags\":\"";
35 + tags_post = "\",";
36 + }
37 + }
38 +
39 + buffer_sprintf(b, "{"
40 + "\"prefix\":\"%s\","
41 + "\"hostname\":\"%s\","
42 + "%s%s%s"
43 +
44 + "\"chart_id\":\"%s\","
45 + "\"chart_name\":\"%s\","
46 + "\"chart_family\":\"%s\","
47 + "\"chart_context\": \"%s\","
48 + "\"chart_type\":\"%s\","
49 + "\"units\": \"%s\","
50 +
51 + "\"id\":\"%s\","
52 + "\"name\":\"%s\","
53 + "\"value\":" COLLECTED_NUMBER_FORMAT ","
54 +
55 + "\"timestamp\": %llu}\n",
56 + prefix,
57 + hostname,
58 + tags_pre, tags, tags_post,
59 +
60 + st->id,
61 + st->name,
62 + st->family,
63 + st->context,
64 + st->type,
65 + st->units,
66 +
67 + rd->id,
68 + rd->name,
69 + rd->last_collected_value,
70 +
71 + (unsigned long long) rd->last_collected_time.tv_sec
72 + );
73 +
74 + return 1;
75 +}
76 +
77 +int format_dimension_stored_json_plaintext(
78 + BUFFER *b // the buffer to write data to
79 + , const char *prefix // the prefix to use
80 + , RRDHOST *host // the host this chart comes from
81 + , const char *hostname // the hostname (to override host->hostname)
82 + , RRDSET *st // the chart
83 + , RRDDIM *rd // the dimension
84 + , time_t after // the start timestamp
85 + , time_t before // the end timestamp
86 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
87 +) {
88 + (void)host;
89 +
90 + time_t first_t = after, last_t = before;
91 + calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
92 +
93 + if(!isnan(value)) {
94 + const char *tags_pre = "", *tags_post = "", *tags = host->tags;
95 + if(!tags) tags = "";
96 +
97 + if(*tags) {
98 + if(*tags == '{' || *tags == '[' || *tags == '"') {
99 + tags_pre = "\"host_tags\":";
100 + tags_post = ",";
101 + }
102 + else {
103 + tags_pre = "\"host_tags\":\"";
104 + tags_post = "\",";
105 + }
106 + }
107 +
108 + buffer_sprintf(b, "{"
109 + "\"prefix\":\"%s\","
110 + "\"hostname\":\"%s\","
111 + "%s%s%s"
112 +
113 + "\"chart_id\":\"%s\","
114 + "\"chart_name\":\"%s\","
115 + "\"chart_family\":\"%s\","
116 + "\"chart_context\": \"%s\","
117 + "\"chart_type\":\"%s\","
118 + "\"units\": \"%s\","
119 +
120 + "\"id\":\"%s\","
121 + "\"name\":\"%s\","
122 + "\"value\":" CALCULATED_NUMBER_FORMAT ","
123 +
124 + "\"timestamp\": %llu}\n",
125 + prefix,
126 + hostname,
127 + tags_pre, tags, tags_post,
128 +
129 + st->id,
130 + st->name,
131 + st->family,
132 + st->context,
133 + st->type,
134 + st->units,
135 +
136 + rd->id,
137 + rd->name,
138 + value,
139 +
140 + (unsigned long long) last_t
141 + );
142 +
143 + return 1;
144 + }
145 + return 0;
146 +}
147 +
148 +int process_json_response(BUFFER *b) {
149 + return discard_response(b, "json");
150 +}
151 +
152 +
src/backends/json/json.h new
+34
@@ -0,0 +1,34 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_BACKEND_JSON_H
4 +#define NETDATA_BACKEND_JSON_H
5 +
6 +#include "../backends.h"
7 +
8 +extern int format_dimension_collected_json_plaintext(
9 + BUFFER *b // the buffer to write data to
10 + , const char *prefix // the prefix to use
11 + , RRDHOST *host // the host this chart comes from
12 + , const char *hostname // the hostname (to override host->hostname)
13 + , RRDSET *st // the chart
14 + , RRDDIM *rd // the dimension
15 + , time_t after // the start timestamp
16 + , time_t before // the end timestamp
17 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
18 +);
19 +
20 +extern int format_dimension_stored_json_plaintext(
21 + BUFFER *b // the buffer to write data to
22 + , const char *prefix // the prefix to use
23 + , RRDHOST *host // the host this chart comes from
24 + , const char *hostname // the hostname (to override host->hostname)
25 + , RRDSET *st // the chart
26 + , RRDDIM *rd // the dimension
27 + , time_t after // the start timestamp
28 + , time_t before // the end timestamp
29 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
30 +);
31 +
32 +extern int process_json_response(BUFFER *b);
33 +
34 +#endif //NETDATA_BACKEND_JSON_H
src/backends/opentsdb/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/backends/opentsdb/opentsdb.c new
+90
@@ -0,0 +1,90 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#define BACKENDS_INTERNALS
4 +#include "opentsdb.h"
5 +
6 +// ----------------------------------------------------------------------------
7 +// opentsdb backend
8 +
9 +int format_dimension_collected_opentsdb_telnet(
10 + BUFFER *b // the buffer to write data to
11 + , const char *prefix // the prefix to use
12 + , RRDHOST *host // the host this chart comes from
13 + , const char *hostname // the hostname (to override host->hostname)
14 + , RRDSET *st // the chart
15 + , RRDDIM *rd // the dimension
16 + , time_t after // the start timestamp
17 + , time_t before // the end timestamp
18 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
19 +) {
20 + (void)host;
21 + (void)after;
22 + (void)before;
23 +
24 + char chart_name[RRD_ID_LENGTH_MAX + 1];
25 + char dimension_name[RRD_ID_LENGTH_MAX + 1];
26 + backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
27 + backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
28 +
29 + buffer_sprintf(
30 + b
31 + , "put %s.%s.%s %llu " COLLECTED_NUMBER_FORMAT " host=%s%s%s\n"
32 + , prefix
33 + , chart_name
34 + , dimension_name
35 + , (unsigned long long)rd->last_collected_time.tv_sec
36 + , rd->last_collected_value
37 + , hostname
38 + , (host->tags)?" ":""
39 + , (host->tags)?host->tags:""
40 + );
41 +
42 + return 1;
43 +}
44 +
45 +int format_dimension_stored_opentsdb_telnet(
46 + BUFFER *b // the buffer to write data to
47 + , const char *prefix // the prefix to use
48 + , RRDHOST *host // the host this chart comes from
49 + , const char *hostname // the hostname (to override host->hostname)
50 + , RRDSET *st // the chart
51 + , RRDDIM *rd // the dimension
52 + , time_t after // the start timestamp
53 + , time_t before // the end timestamp
54 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
55 +) {
56 + (void)host;
57 +
58 + time_t first_t = after, last_t = before;
59 + calculated_number value = backend_calculate_value_from_stored_data(st, rd, after, before, backend_options, &first_t, &last_t);
60 +
61 + char chart_name[RRD_ID_LENGTH_MAX + 1];
62 + char dimension_name[RRD_ID_LENGTH_MAX + 1];
63 + backend_name_copy(chart_name, (backend_options & BACKEND_OPTION_SEND_NAMES && st->name)?st->name:st->id, RRD_ID_LENGTH_MAX);
64 + backend_name_copy(dimension_name, (backend_options & BACKEND_OPTION_SEND_NAMES && rd->name)?rd->name:rd->id, RRD_ID_LENGTH_MAX);
65 +
66 + if(!isnan(value)) {
67 +
68 + buffer_sprintf(
69 + b
70 + , "put %s.%s.%s %llu " CALCULATED_NUMBER_FORMAT " host=%s%s%s\n"
71 + , prefix
72 + , chart_name
73 + , dimension_name
74 + , (unsigned long long) last_t
75 + , value
76 + , hostname
77 + , (host->tags)?" ":""
78 + , (host->tags)?host->tags:""
79 + );
80 +
81 + return 1;
82 + }
83 + return 0;
84 +}
85 +
86 +int process_opentsdb_response(BUFFER *b) {
87 + return discard_response(b, "opentsdb");
88 +}
89 +
90 +
src/backends/opentsdb/opentsdb.h new
+35
@@ -0,0 +1,35 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_BACKEND_OPENTSDB_H
4 +#define NETDATA_BACKEND_OPENTSDB_H
5 +
6 +#include "../backends.h"
7 +
8 +extern int format_dimension_collected_opentsdb_telnet(
9 + BUFFER *b // the buffer to write data to
10 + , const char *prefix // the prefix to use
11 + , RRDHOST *host // the host this chart comes from
12 + , const char *hostname // the hostname (to override host->hostname)
13 + , RRDSET *st // the chart
14 + , RRDDIM *rd // the dimension
15 + , time_t after // the start timestamp
16 + , time_t before // the end timestamp
17 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
18 +);
19 +
20 +extern int format_dimension_stored_opentsdb_telnet(
21 + BUFFER *b // the buffer to write data to
22 + , const char *prefix // the prefix to use
23 + , RRDHOST *host // the host this chart comes from
24 + , const char *hostname // the hostname (to override host->hostname)
25 + , RRDSET *st // the chart
26 + , RRDDIM *rd // the dimension
27 + , time_t after // the start timestamp
28 + , time_t before // the end timestamp
29 + , BACKEND_OPTIONS backend_options // BACKEND_SOURCE_* bitmap
30 +);
31 +
32 +extern int process_opentsdb_response(BUFFER *b);
33 +
34 +
35 +#endif //NETDATA_BACKEND_OPENTSDB_H
src/backends/prometheus/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/backends/prometheus/backend_prometheus.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "backend_prometheus.h"
4
5 // ----------------------------------------------------------------------------
6 // PROMETHEUS
src/backends/prometheus/backend_prometheus.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_BACKEND_PROMETHEUS_H
4 #define NETDATA_BACKEND_PROMETHEUS_H 1
5
6 +#include "../backends.h"
7 +
8 typedef enum prometheus_output_flags {
9 PROMETHEUS_OUTPUT_NONE = 0,
10 PROMETHEUS_OUTPUT_HELP = (1 << 0),
src/common.c
-1617
@@ -2,14 +2,6 @@
2
3 #include "common.h"
4
5 -#ifdef __APPLE__
6 -#define INHERIT_NONE 0
7 -#endif /* __APPLE__ */
8 -#if defined(__FreeBSD__) || defined(__APPLE__)
9 -# define O_NOATIME 0
10 -# define MADV_DONTFORK INHERIT_NONE
11 -#endif /* __FreeBSD__ || __APPLE__*/
12 -
5 char *netdata_configured_hostname = NULL;
6 char *netdata_configured_user_config_dir = CONFIG_DIR;
7 char *netdata_configured_stock_config_dir = LIBCONFIG_DIR;
@@ -22,1612 +14,3 @@ char *netdata_configured_home_dir = CACHE_DIR;
14 char *netdata_configured_host_prefix = NULL;
15 char *netdata_configured_timezone = NULL;
16
25 -struct rlimit rlimit_nofile = { .rlim_cur = 1024, .rlim_max = 1024 };
26 -int enable_ksm = 1;
27 -
28 -volatile sig_atomic_t netdata_exit = 0;
29 -const char *os_type = NETDATA_OS_TYPE;
30 -const char *program_version = VERSION;
31 -
32 -// ----------------------------------------------------------------------------
33 -// memory allocation functions that handle failures
34 -
35 -// although netdata does not use memory allocations too often (netdata tries to
36 -// maintain its memory footprint stable during runtime, i.e. all buffers are
37 -// allocated during initialization and are adapted to current use throughout
38 -// its lifetime), these can be used to override the default system allocation
39 -// routines.
40 -
41 -#ifdef NETDATA_LOG_ALLOCATIONS
42 -static struct memory_statistics {
43 - volatile size_t malloc_calls_made;
44 - volatile size_t calloc_calls_made;
45 - volatile size_t realloc_calls_made;
46 - volatile size_t strdup_calls_made;
47 - volatile size_t free_calls_made;
48 - volatile size_t memory_calls_made;
49 - volatile size_t allocated_memory;
50 - volatile size_t mmapped_memory;
51 -} memory_statistics;
52 -
53 -static inline void print_allocations(const char *file, const char *function, const unsigned long line) {
54 - static struct memory_statistics old = { 0, 0, 0, 0, 0, 0, 0, 0 };
55 -
56 - //if(unlikely(!(memory_statistics.memory_calls_made % 5))) {
57 - fprintf(stderr, "(%04lu@%-10.10s:%-15.15s): Allocated %zu KB (+%zu B), mmapped %zu KB (+%zu B): malloc %zu (+%zu), calloc %zu (+%zu), realloc %zu (+%zu), strdup %zu (+%zu), free %zu (+%zu)\n",
58 - line, file, function,
59 - (memory_statistics.allocated_memory + 512) / 1024, memory_statistics.allocated_memory - old.allocated_memory,
60 - (memory_statistics.mmapped_memory + 512) / 1024, memory_statistics.mmapped_memory - old.mmapped_memory,
61 - memory_statistics.malloc_calls_made, memory_statistics.malloc_calls_made - old.malloc_calls_made,
62 - memory_statistics.calloc_calls_made, memory_statistics.calloc_calls_made - old.calloc_calls_made,
63 - memory_statistics.realloc_calls_made, memory_statistics.realloc_calls_made - old.realloc_calls_made,
64 - memory_statistics.strdup_calls_made, memory_statistics.strdup_calls_made - old.strdup_calls_made,
65 - memory_statistics.free_calls_made, memory_statistics.free_calls_made - old.free_calls_made
66 - );
67 -
68 - memcpy(&old, &memory_statistics, sizeof(struct memory_statistics));
69 - //}
70 -}
71 -
72 -static inline void malloc_accounting(const char *file, const char *function, const unsigned long line, size_t size) {
73 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
74 - __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
75 - __atomic_fetch_add(&memory_statistics.malloc_calls_made, 1, __ATOMIC_SEQ_CST);
76 - __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
77 -#else
78 - // this is for debugging - we don't care locking it
79 - memory_statistics.memory_calls_made++;
80 - memory_statistics.malloc_calls_made++;
81 - memory_statistics.allocated_memory += size;
82 -#endif
83 - print_allocations(file, function, line);
84 -}
85 -
86 -static inline void mmap_accounting(size_t size) {
87 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
88 - __atomic_fetch_add(&memory_statistics.malloc_calls_made, 1, __ATOMIC_SEQ_CST);
89 - __atomic_fetch_add(&memory_statistics.mmapped_memory, size, __ATOMIC_SEQ_CST);
90 -#else
91 - // this is for debugging - we don't care locking it
92 - memory_statistics.memory_calls_made++;
93 - memory_statistics.mmapped_memory += size;
94 -#endif
95 -}
96 -
97 -static inline void calloc_accounting(const char *file, const char *function, const unsigned long line, size_t size) {
98 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
99 - __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
100 - __atomic_fetch_add(&memory_statistics.calloc_calls_made, 1, __ATOMIC_SEQ_CST);
101 - __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
102 -#else
103 - // this is for debugging - we don't care locking it
104 - memory_statistics.memory_calls_made++;
105 - memory_statistics.calloc_calls_made++;
106 - memory_statistics.allocated_memory += size;
107 -#endif
108 - print_allocations(file, function, line);
109 -}
110 -
111 -static inline void realloc_accounting(const char *file, const char *function, const unsigned long line, void *ptr, size_t size) {
112 - (void)ptr;
113 -
114 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
115 - __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
116 - __atomic_fetch_add(&memory_statistics.realloc_calls_made, 1, __ATOMIC_SEQ_CST);
117 - __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
118 -#else
119 - // this is for debugging - we don't care locking it
120 - memory_statistics.memory_calls_made++;
121 - memory_statistics.realloc_calls_made++;
122 - memory_statistics.allocated_memory += size;
123 -#endif
124 - print_allocations(file, function, line);
125 -}
126 -
127 -static inline void strdup_accounting(const char *file, const char *function, const unsigned long line, const char *s) {
128 - size_t size = strlen(s) + 1;
129 -
130 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
131 - __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
132 - __atomic_fetch_add(&memory_statistics.strdup_calls_made, 1, __ATOMIC_SEQ_CST);
133 - __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
134 -#else
135 - // this is for debugging - we don't care locking it
136 - memory_statistics.memory_calls_made++;
137 - memory_statistics.strdup_calls_made++;
138 - memory_statistics.allocated_memory += size;
139 -#endif
140 - print_allocations(file, function, line);
141 -}
142 -
143 -static inline void free_accounting(const char *file, const char *function, const unsigned long line, void *ptr) {
144 - (void)file;
145 - (void)function;
146 - (void)line;
147 -
148 - if(likely(ptr)) {
149 -#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
150 - __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
151 - __atomic_fetch_add(&memory_statistics.free_calls_made, 1, __ATOMIC_SEQ_CST);
152 -#else
153 - // this is for debugging - we don't care locking it
154 - memory_statistics.memory_calls_made++;
155 - memory_statistics.free_calls_made++;
156 -#endif
157 - }
158 -}
159 -#endif
160 -
161 -#ifdef NETDATA_LOG_ALLOCATIONS
162 -char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s) {
163 - strdup_accounting(file, function, line, s);
164 -#else
165 -char *strdupz(const char *s) {
166 -#endif
167 -
168 - char *t = strdup(s);
169 - if (unlikely(!t)) fatal("Cannot strdup() string '%s'", s);
170 - return t;
171 -}
172 -
173 -#ifdef NETDATA_LOG_ALLOCATIONS
174 -void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size) {
175 - malloc_accounting(file, function, line, size);
176 -#else
177 -void *mallocz(size_t size) {
178 -#endif
179 -
180 - void *p = malloc(size);
181 - if (unlikely(!p)) fatal("Cannot allocate %zu bytes of memory.", size);
182 - return p;
183 -}
184 -
185 -#ifdef NETDATA_LOG_ALLOCATIONS
186 -void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size) {
187 - calloc_accounting(file, function, line, nmemb * size);
188 -#else
189 -void *callocz(size_t nmemb, size_t size) {
190 -#endif
191 -
192 - void *p = calloc(nmemb, size);
193 - if (unlikely(!p)) fatal("Cannot allocate %zu bytes of memory.", nmemb * size);
194 - return p;
195 -}
196 -
197 -#ifdef NETDATA_LOG_ALLOCATIONS
198 -void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size) {
199 - realloc_accounting(file, function, line, ptr, size);
200 -#else
201 -void *reallocz(void *ptr, size_t size) {
202 -#endif
203 -
204 - void *p = realloc(ptr, size);
205 - if (unlikely(!p)) fatal("Cannot re-allocate memory to %zu bytes.", size);
206 - return p;
207 -}
208 -
209 -#ifdef NETDATA_LOG_ALLOCATIONS
210 -void freez_int(const char *file, const char *function, const unsigned long line, void *ptr) {
211 - free_accounting(file, function, line, ptr);
212 -#else
213 -void freez(void *ptr) {
214 -#endif
215 -
216 - free(ptr);
217 -}
218 -
219 -void json_escape_string(char *dst, const char *src, size_t size) {
220 - const char *t;
221 - char *d = dst, *e = &dst[size - 1];
222 -
223 - for(t = src; *t && d < e ;t++) {
224 - if(unlikely(*t == '\\' || *t == '"')) {
225 - if(unlikely(d + 1 >= e)) break;
226 - *d++ = '\\';
227 - }
228 - *d++ = *t;
229 - }
230 -
231 - *d = '\0';
232 -}
233 -
234 -void json_fix_string(char *s) {
235 - unsigned char c;
236 - while((c = (unsigned char)*s)) {
237 - if(unlikely(c == '\\'))
238 - *s++ = '/';
239 - else if(unlikely(c == '"'))
240 - *s++ = '\'';
241 - else if(unlikely(isspace(c) || iscntrl(c)))
242 - *s++ = ' ';
243 - else if(unlikely(!isprint(c) || c > 127))
244 - *s++ = '_';
245 - else
246 - s++;
247 - }
248 -}
249 -
250 -int sleep_usec(usec_t usec) {
251 -
252 -#ifndef NETDATA_WITH_USLEEP
253 - // we expect microseconds (1.000.000 per second)
254 - // but timespec is nanoseconds (1.000.000.000 per second)
255 - struct timespec rem, req = {
256 - .tv_sec = (time_t) (usec / 1000000),
257 - .tv_nsec = (suseconds_t) ((usec % 1000000) * 1000)
258 - };
259 -
260 - while (nanosleep(&req, &rem) == -1) {
261 - if (likely(errno == EINTR)) {
262 - debug(D_SYSTEM, "nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
263 - req.tv_sec = rem.tv_sec;
264 - req.tv_nsec = rem.tv_nsec;
265 - } else {
266 - error("Cannot nanosleep() for %llu microseconds.", usec);
267 - break;
268 - }
269 - }
270 -
271 - return 0;
272 -#else
273 - int ret = usleep(usec);
274 - if(unlikely(ret == -1 && errno == EINVAL)) {
275 - // on certain systems, usec has to be up to 999999
276 - if(usec > 999999) {
277 - int counter = usec / 999999;
278 - while(counter--)
279 - usleep(999999);
280 -
281 - usleep(usec % 999999);
282 - }
283 - else {
284 - error("Cannot usleep() for %llu microseconds.", usec);
285 - return ret;
286 - }
287 - }
288 -
289 - if(ret != 0)
290 - error("usleep() failed for %llu microseconds.", usec);
291 -
292 - return ret;
293 -#endif
294 -}
295 -
296 -unsigned char netdata_map_chart_names[256] = {
297 - [0] = '\0', //
298 - [1] = '_', //
299 - [2] = '_', //
300 - [3] = '_', //
301 - [4] = '_', //
302 - [5] = '_', //
303 - [6] = '_', //
304 - [7] = '_', //
305 - [8] = '_', //
306 - [9] = '_', //
307 - [10] = '_', //
308 - [11] = '_', //
309 - [12] = '_', //
310 - [13] = '_', //
311 - [14] = '_', //
312 - [15] = '_', //
313 - [16] = '_', //
314 - [17] = '_', //
315 - [18] = '_', //
316 - [19] = '_', //
317 - [20] = '_', //
318 - [21] = '_', //
319 - [22] = '_', //
320 - [23] = '_', //
321 - [24] = '_', //
322 - [25] = '_', //
323 - [26] = '_', //
324 - [27] = '_', //
325 - [28] = '_', //
326 - [29] = '_', //
327 - [30] = '_', //
328 - [31] = '_', //
329 - [32] = '_', //
330 - [33] = '_', // !
331 - [34] = '_', // "
332 - [35] = '_', // #
333 - [36] = '_', // $
334 - [37] = '_', // %
335 - [38] = '_', // &
336 - [39] = '_', // '
337 - [40] = '_', // (
338 - [41] = '_', // )
339 - [42] = '_', // *
340 - [43] = '_', // +
341 - [44] = '.', // ,
342 - [45] = '-', // -
343 - [46] = '.', // .
344 - [47] = '/', // /
345 - [48] = '0', // 0
346 - [49] = '1', // 1
347 - [50] = '2', // 2
348 - [51] = '3', // 3
349 - [52] = '4', // 4
350 - [53] = '5', // 5
351 - [54] = '6', // 6
352 - [55] = '7', // 7
353 - [56] = '8', // 8
354 - [57] = '9', // 9
355 - [58] = '_', // :
356 - [59] = '_', // ;
357 - [60] = '_', // <
358 - [61] = '_', // =
359 - [62] = '_', // >
360 - [63] = '_', // ?
361 - [64] = '_', // @
362 - [65] = 'a', // A
363 - [66] = 'b', // B
364 - [67] = 'c', // C
365 - [68] = 'd', // D
366 - [69] = 'e', // E
367 - [70] = 'f', // F
368 - [71] = 'g', // G
369 - [72] = 'h', // H
370 - [73] = 'i', // I
371 - [74] = 'j', // J
372 - [75] = 'k', // K
373 - [76] = 'l', // L
374 - [77] = 'm', // M
375 - [78] = 'n', // N
376 - [79] = 'o', // O
377 - [80] = 'p', // P
378 - [81] = 'q', // Q
379 - [82] = 'r', // R
380 - [83] = 's', // S
381 - [84] = 't', // T
382 - [85] = 'u', // U
383 - [86] = 'v', // V
384 - [87] = 'w', // W
385 - [88] = 'x', // X
386 - [89] = 'y', // Y
387 - [90] = 'z', // Z
388 - [91] = '_', // [
389 - [92] = '/', // backslash
390 - [93] = '_', // ]
391 - [94] = '_', // ^
392 - [95] = '_', // _
393 - [96] = '_', // `
394 - [97] = 'a', // a
395 - [98] = 'b', // b
396 - [99] = 'c', // c
397 - [100] = 'd', // d
398 - [101] = 'e', // e
399 - [102] = 'f', // f
400 - [103] = 'g', // g
401 - [104] = 'h', // h
402 - [105] = 'i', // i
403 - [106] = 'j', // j
404 - [107] = 'k', // k
405 - [108] = 'l', // l
406 - [109] = 'm', // m
407 - [110] = 'n', // n
408 - [111] = 'o', // o
409 - [112] = 'p', // p
410 - [113] = 'q', // q
411 - [114] = 'r', // r
412 - [115] = 's', // s
413 - [116] = 't', // t
414 - [117] = 'u', // u
415 - [118] = 'v', // v
416 - [119] = 'w', // w
417 - [120] = 'x', // x
418 - [121] = 'y', // y
419 - [122] = 'z', // z
420 - [123] = '_', // {
421 - [124] = '_', // |
422 - [125] = '_', // }
423 - [126] = '_', // ~
424 - [127] = '_', //
425 - [128] = '_', //
426 - [129] = '_', //
427 - [130] = '_', //
428 - [131] = '_', //
429 - [132] = '_', //
430 - [133] = '_', //
431 - [134] = '_', //
432 - [135] = '_', //
433 - [136] = '_', //
434 - [137] = '_', //
435 - [138] = '_', //
436 - [139] = '_', //
437 - [140] = '_', //
438 - [141] = '_', //
439 - [142] = '_', //
440 - [143] = '_', //
441 - [144] = '_', //
442 - [145] = '_', //
443 - [146] = '_', //
444 - [147] = '_', //
445 - [148] = '_', //
446 - [149] = '_', //
447 - [150] = '_', //
448 - [151] = '_', //
449 - [152] = '_', //
450 - [153] = '_', //
451 - [154] = '_', //
452 - [155] = '_', //
453 - [156] = '_', //
454 - [157] = '_', //
455 - [158] = '_', //
456 - [159] = '_', //
457 - [160] = '_', //
458 - [161] = '_', //
459 - [162] = '_', //
460 - [163] = '_', //
461 - [164] = '_', //
462 - [165] = '_', //
463 - [166] = '_', //
464 - [167] = '_', //
465 - [168] = '_', //
466 - [169] = '_', //
467 - [170] = '_', //
468 - [171] = '_', //
469 - [172] = '_', //
470 - [173] = '_', //
471 - [174] = '_', //
472 - [175] = '_', //
473 - [176] = '_', //
474 - [177] = '_', //
475 - [178] = '_', //
476 - [179] = '_', //
477 - [180] = '_', //
478 - [181] = '_', //
479 - [182] = '_', //
480 - [183] = '_', //
481 - [184] = '_', //
482 - [185] = '_', //
483 - [186] = '_', //
484 - [187] = '_', //
485 - [188] = '_', //
486 - [189] = '_', //
487 - [190] = '_', //
488 - [191] = '_', //
489 - [192] = '_', //
490 - [193] = '_', //
491 - [194] = '_', //
492 - [195] = '_', //
493 - [196] = '_', //
494 - [197] = '_', //
495 - [198] = '_', //
496 - [199] = '_', //
497 - [200] = '_', //
498 - [201] = '_', //
499 - [202] = '_', //
500 - [203] = '_', //
501 - [204] = '_', //
502 - [205] = '_', //
503 - [206] = '_', //
504 - [207] = '_', //
505 - [208] = '_', //
506 - [209] = '_', //
507 - [210] = '_', //
508 - [211] = '_', //
509 - [212] = '_', //
510 - [213] = '_', //
511 - [214] = '_', //
512 - [215] = '_', //
513 - [216] = '_', //
514 - [217] = '_', //
515 - [218] = '_', //
516 - [219] = '_', //
517 - [220] = '_', //
518 - [221] = '_', //
519 - [222] = '_', //
520 - [223] = '_', //
521 - [224] = '_', //
522 - [225] = '_', //
523 - [226] = '_', //
524 - [227] = '_', //
525 - [228] = '_', //
526 - [229] = '_', //
527 - [230] = '_', //
528 - [231] = '_', //
529 - [232] = '_', //
530 - [233] = '_', //
531 - [234] = '_', //
532 - [235] = '_', //
533 - [236] = '_', //
534 - [237] = '_', //
535 - [238] = '_', //
536 - [239] = '_', //
537 - [240] = '_', //
538 - [241] = '_', //
539 - [242] = '_', //
540 - [243] = '_', //
541 - [244] = '_', //
542 - [245] = '_', //
543 - [246] = '_', //
544 - [247] = '_', //
545 - [248] = '_', //
546 - [249] = '_', //
547 - [250] = '_', //
548 - [251] = '_', //
549 - [252] = '_', //
550 - [253] = '_', //
551 - [254] = '_', //
552 - [255] = '_' //
553 -};
554 -
555 -// make sure the supplied string
556 -// is good for a netdata chart/dimension ID/NAME
557 -void netdata_fix_chart_name(char *s) {
558 - while ((*s = netdata_map_chart_names[(unsigned char) *s])) s++;
559 -}
560 -
561 -unsigned char netdata_map_chart_ids[256] = {
562 - [0] = '\0', //
563 - [1] = '_', //
564 - [2] = '_', //
565 - [3] = '_', //
566 - [4] = '_', //
567 - [5] = '_', //
568 - [6] = '_', //
569 - [7] = '_', //
570 - [8] = '_', //
571 - [9] = '_', //
572 - [10] = '_', //
573 - [11] = '_', //
574 - [12] = '_', //
575 - [13] = '_', //
576 - [14] = '_', //
577 - [15] = '_', //
578 - [16] = '_', //
579 - [17] = '_', //
580 - [18] = '_', //
581 - [19] = '_', //
582 - [20] = '_', //
583 - [21] = '_', //
584 - [22] = '_', //
585 - [23] = '_', //
586 - [24] = '_', //
587 - [25] = '_', //
588 - [26] = '_', //
589 - [27] = '_', //
590 - [28] = '_', //
591 - [29] = '_', //
592 - [30] = '_', //
593 - [31] = '_', //
594 - [32] = '_', //
595 - [33] = '_', // !
596 - [34] = '_', // "
597 - [35] = '_', // #
598 - [36] = '_', // $
599 - [37] = '_', // %
600 - [38] = '_', // &
601 - [39] = '_', // '
602 - [40] = '_', // (
603 - [41] = '_', // )
604 - [42] = '_', // *
605 - [43] = '_', // +
606 - [44] = '.', // ,
607 - [45] = '-', // -
608 - [46] = '.', // .
609 - [47] = '_', // /
610 - [48] = '0', // 0
611 - [49] = '1', // 1
612 - [50] = '2', // 2
613 - [51] = '3', // 3
614 - [52] = '4', // 4
615 - [53] = '5', // 5
616 - [54] = '6', // 6
617 - [55] = '7', // 7
618 - [56] = '8', // 8
619 - [57] = '9', // 9
620 - [58] = '_', // :
621 - [59] = '_', // ;
622 - [60] = '_', // <
623 - [61] = '_', // =
624 - [62] = '_', // >
625 - [63] = '_', // ?
626 - [64] = '_', // @
627 - [65] = 'a', // A
628 - [66] = 'b', // B
629 - [67] = 'c', // C
630 - [68] = 'd', // D
631 - [69] = 'e', // E
632 - [70] = 'f', // F
633 - [71] = 'g', // G
634 - [72] = 'h', // H
635 - [73] = 'i', // I
636 - [74] = 'j', // J
637 - [75] = 'k', // K
638 - [76] = 'l', // L
639 - [77] = 'm', // M
640 - [78] = 'n', // N
641 - [79] = 'o', // O
642 - [80] = 'p', // P
643 - [81] = 'q', // Q
644 - [82] = 'r', // R
645 - [83] = 's', // S
646 - [84] = 't', // T
647 - [85] = 'u', // U
648 - [86] = 'v', // V
649 - [87] = 'w', // W
650 - [88] = 'x', // X
651 - [89] = 'y', // Y
652 - [90] = 'z', // Z
653 - [91] = '_', // [
654 - [92] = '/', // backslash
655 - [93] = '_', // ]
656 - [94] = '_', // ^
657 - [95] = '_', // _
658 - [96] = '_', // `
659 - [97] = 'a', // a
660 - [98] = 'b', // b
661 - [99] = 'c', // c
662 - [100] = 'd', // d
663 - [101] = 'e', // e
664 - [102] = 'f', // f
665 - [103] = 'g', // g
666 - [104] = 'h', // h
667 - [105] = 'i', // i
668 - [106] = 'j', // j
669 - [107] = 'k', // k
670 - [108] = 'l', // l
671 - [109] = 'm', // m
672 - [110] = 'n', // n
673 - [111] = 'o', // o
674 - [112] = 'p', // p
675 - [113] = 'q', // q
676 - [114] = 'r', // r
677 - [115] = 's', // s
678 - [116] = 't', // t
679 - [117] = 'u', // u
680 - [118] = 'v', // v
681 - [119] = 'w', // w
682 - [120] = 'x', // x
683 - [121] = 'y', // y
684 - [122] = 'z', // z
685 - [123] = '_', // {
686 - [124] = '_', // |
687 - [125] = '_', // }
688 - [126] = '_', // ~
689 - [127] = '_', //
690 - [128] = '_', //
691 - [129] = '_', //
692 - [130] = '_', //
693 - [131] = '_', //
694 - [132] = '_', //
695 - [133] = '_', //
696 - [134] = '_', //
697 - [135] = '_', //
698 - [136] = '_', //
699 - [137] = '_', //
700 - [138] = '_', //
701 - [139] = '_', //
702 - [140] = '_', //
703 - [141] = '_', //
704 - [142] = '_', //
705 - [143] = '_', //
706 - [144] = '_', //
707 - [145] = '_', //
708 - [146] = '_', //
709 - [147] = '_', //
710 - [148] = '_', //
711 - [149] = '_', //
712 - [150] = '_', //
713 - [151] = '_', //
714 - [152] = '_', //
715 - [153] = '_', //
716 - [154] = '_', //
717 - [155] = '_', //
718 - [156] = '_', //
719 - [157] = '_', //
720 - [158] = '_', //
721 - [159] = '_', //
722 - [160] = '_', //
723 - [161] = '_', //
724 - [162] = '_', //
725 - [163] = '_', //
726 - [164] = '_', //
727 - [165] = '_', //
728 - [166] = '_', //
729 - [167] = '_', //
730 - [168] = '_', //
731 - [169] = '_', //
732 - [170] = '_', //
733 - [171] = '_', //
734 - [172] = '_', //
735 - [173] = '_', //
736 - [174] = '_', //
737 - [175] = '_', //
738 - [176] = '_', //
739 - [177] = '_', //
740 - [178] = '_', //
741 - [179] = '_', //
742 - [180] = '_', //
743 - [181] = '_', //
744 - [182] = '_', //
745 - [183] = '_', //
746 - [184] = '_', //
747 - [185] = '_', //
748 - [186] = '_', //
749 - [187] = '_', //
750 - [188] = '_', //
751 - [189] = '_', //
752 - [190] = '_', //
753 - [191] = '_', //
754 - [192] = '_', //
755 - [193] = '_', //
756 - [194] = '_', //
757 - [195] = '_', //
758 - [196] = '_', //
759 - [197] = '_', //
760 - [198] = '_', //
761 - [199] = '_', //
762 - [200] = '_', //
763 - [201] = '_', //
764 - [202] = '_', //
765 - [203] = '_', //
766 - [204] = '_', //
767 - [205] = '_', //
768 - [206] = '_', //
769 - [207] = '_', //
770 - [208] = '_', //
771 - [209] = '_', //
772 - [210] = '_', //
773 - [211] = '_', //
774 - [212] = '_', //
775 - [213] = '_', //
776 - [214] = '_', //
777 - [215] = '_', //
778 - [216] = '_', //
779 - [217] = '_', //
780 - [218] = '_', //
781 - [219] = '_', //
782 - [220] = '_', //
783 - [221] = '_', //
784 - [222] = '_', //
785 - [223] = '_', //
786 - [224] = '_', //
787 - [225] = '_', //
788 - [226] = '_', //
789 - [227] = '_', //
790 - [228] = '_', //
791 - [229] = '_', //
792 - [230] = '_', //
793 - [231] = '_', //
794 - [232] = '_', //
795 - [233] = '_', //
796 - [234] = '_', //
797 - [235] = '_', //
798 - [236] = '_', //
799 - [237] = '_', //
800 - [238] = '_', //
801 - [239] = '_', //
802 - [240] = '_', //
803 - [241] = '_', //
804 - [242] = '_', //
805 - [243] = '_', //
806 - [244] = '_', //
807 - [245] = '_', //
808 - [246] = '_', //
809 - [247] = '_', //
810 - [248] = '_', //
811 - [249] = '_', //
812 - [250] = '_', //
813 - [251] = '_', //
814 - [252] = '_', //
815 - [253] = '_', //
816 - [254] = '_', //
817 - [255] = '_' //
818 -};
819 -
820 -// make sure the supplied string
821 -// is good for a netdata chart/dimension ID/NAME
822 -void netdata_fix_chart_id(char *s) {
823 - while ((*s = netdata_map_chart_ids[(unsigned char) *s])) s++;
824 -}
825 -
826 -/*
827 -// http://stackoverflow.com/questions/7666509/hash-function-for-string
828 -uint32_t simple_hash(const char *name)
829 -{
830 - const char *s = name;
831 - uint32_t hash = 5381;
832 - int i;
833 -
834 - while((i = *s++)) hash = ((hash << 5) + hash) + i;
835 -
836 - // fprintf(stderr, "HASH: %lu %s\n", hash, name);
837 -
838 - return hash;
839 -}
840 -*/
841 -
842 -/*
843 -// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
844 -uint32_t simple_hash(const char *name) {
845 - unsigned char *s = (unsigned char *) name;
846 - uint32_t hval = 0x811c9dc5;
847 -
848 - // FNV-1a algorithm
849 - while (*s) {
850 - // multiply by the 32 bit FNV magic prime mod 2^32
851 - // NOTE: No need to optimize with left shifts.
852 - // GCC will use imul instruction anyway.
853 - // Tested with 'gcc -O3 -S'
854 - //hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
855 - hval *= 16777619;
856 -
857 - // xor the bottom with the current octet
858 - hval ^= (uint32_t) *s++;
859 - }
860 -
861 - // fprintf(stderr, "HASH: %u = %s\n", hval, name);
862 - return hval;
863 -}
864 -
865 -uint32_t simple_uhash(const char *name) {
866 - unsigned char *s = (unsigned char *) name;
867 - uint32_t hval = 0x811c9dc5, c;
868 -
869 - // FNV-1a algorithm
870 - while ((c = *s++)) {
871 - if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
872 - hval *= 16777619;
873 - hval ^= c;
874 - }
875 - return hval;
876 -}
877 -*/
878 -
879 -/*
880 -// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
881 -// one at a time hash
882 -uint32_t simple_hash(const char *name) {
883 - unsigned char *s = (unsigned char *)name;
884 - uint32_t h = 0;
885 -
886 - while(*s) {
887 - h += *s++;
888 - h += (h << 10);
889 - h ^= (h >> 6);
890 - }
891 -
892 - h += (h << 3);
893 - h ^= (h >> 11);
894 - h += (h << 15);
895 -
896 - // fprintf(stderr, "HASH: %u = %s\n", h, name);
897 -
898 - return h;
899 -}
900 -*/
901 -
902 -void strreverse(char *begin, char *end) {
903 - while (end > begin) {
904 - // clearer code.
905 - char aux = *end;
906 - *end-- = *begin;
907 - *begin++ = aux;
908 - }
909 -}
910 -
911 -char *strsep_on_1char(char **ptr, char c) {
912 - if(unlikely(!ptr || !*ptr))
913 - return NULL;
914 -
915 - // remember the position we started
916 - char *s = *ptr;
917 -
918 - // skip separators in front
919 - while(*s == c) s++;
920 - char *ret = s;
921 -
922 - // find the next separator
923 - while(*s++) {
924 - if(unlikely(*s == c)) {
925 - *s++ = '\0';
926 - *ptr = s;
927 - return ret;
928 - }
929 - }
930 -
931 - *ptr = NULL;
932 - return ret;
933 -}
934 -
935 -char *mystrsep(char **ptr, char *s) {
936 - char *p = "";
937 - while (p && !p[0] && *ptr) p = strsep(ptr, s);
938 - return (p);
939 -}
940 -
941 -char *trim(char *s) {
942 - // skip leading spaces
943 - while (*s && isspace(*s)) s++;
944 - if (!*s) return NULL;
945 -
946 - // skip tailing spaces
947 - // this way is way faster. Writes only one NUL char.
948 - ssize_t l = strlen(s);
949 - if (--l >= 0) {
950 - char *p = s + l;
951 - while (p > s && isspace(*p)) p--;
952 - *++p = '\0';
953 - }
954 -
955 - if (!*s) return NULL;
956 -
957 - return s;
958 -}
959 -
960 -inline char *trim_all(char *buffer) {
961 - char *d = buffer, *s = buffer;
962 -
963 - // skip spaces
964 - while(isspace(*s)) s++;
965 -
966 - while(*s) {
967 - // copy the non-space part
968 - while(*s && !isspace(*s)) *d++ = *s++;
969 -
970 - // add a space if we have to
971 - if(*s && isspace(*s)) {
972 - *d++ = ' ';
973 - s++;
974 - }
975 -
976 - // skip spaces
977 - while(isspace(*s)) s++;
978 - }
979 -
980 - *d = '\0';
981 -
982 - if(d > buffer) {
983 - d--;
984 - if(isspace(*d)) *d = '\0';
985 - }
986 -
987 - if(!buffer[0]) return NULL;
988 - return buffer;
989 -}
990 -
991 -static int memory_file_open(const char *filename, size_t size) {
992 - // info("memory_file_open('%s', %zu", filename, size);
993 -
994 - int fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
995 - if (fd != -1) {
996 - if (lseek(fd, size, SEEK_SET) == (off_t) size) {
997 - if (write(fd, "", 1) == 1) {
998 - if (ftruncate(fd, size))
999 - error("Cannot truncate file '%s' to size %zu. Will use the larger file.", filename, size);
1000 - }
1001 - else error("Cannot write to file '%s' at position %zu.", filename, size);
1002 - }
1003 - else error("Cannot seek file '%s' to size %zu.", filename, size);
1004 - }
1005 - else error("Cannot create/open file '%s'.", filename);
1006 -
1007 - return fd;
1008 -}
1009 -
1010 -// mmap_shared is used for memory mode = map
1011 -static void *memory_file_mmap(const char *filename, size_t size, int flags) {
1012 - // info("memory_file_mmap('%s', %zu", filename, size);
1013 - static int log_madvise = 1;
1014 -
1015 - int fd = -1;
1016 - if(filename) {
1017 - fd = memory_file_open(filename, size);
1018 - if(fd == -1) return MAP_FAILED;
1019 - }
1020 -
1021 - void *mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, fd, 0);
1022 - if (mem != MAP_FAILED) {
1023 -#ifdef NETDATA_LOG_ALLOCATIONS
1024 - mmap_accounting(size);
1025 -#endif
1026 - int advise = MADV_SEQUENTIAL | MADV_DONTFORK;
1027 - if (flags & MAP_SHARED) advise |= MADV_WILLNEED;
1028 -
1029 - if (madvise(mem, size, advise) != 0 && log_madvise) {
1030 - error("Cannot advise the kernel about shared memory usage.");
1031 - log_madvise--;
1032 - }
1033 - }
1034 -
1035 - if(fd != -1)
1036 - close(fd);
1037 -
1038 - return mem;
1039 -}
1040 -
1041 -#ifdef MADV_MERGEABLE
1042 -static void *memory_file_mmap_ksm(const char *filename, size_t size, int flags) {
1043 - // info("memory_file_mmap_ksm('%s', %zu", filename, size);
1044 - static int log_madvise_2 = 1, log_madvise_3 = 1;
1045 -
1046 - int fd = -1;
1047 - if(filename) {
1048 - fd = memory_file_open(filename, size);
1049 - if(fd == -1) return MAP_FAILED;
1050 - }
1051 -
1052 - void *mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags | MAP_ANONYMOUS, -1, 0);
1053 - if (mem != MAP_FAILED) {
1054 -#ifdef NETDATA_LOG_ALLOCATIONS
1055 - mmap_accounting(size);
1056 -#endif
1057 - if(fd != -1) {
1058 - if (lseek(fd, 0, SEEK_SET) == 0) {
1059 - if (read(fd, mem, size) != (ssize_t) size)
1060 - error("Cannot read from file '%s'", filename);
1061 - }
1062 - else error("Cannot seek to beginning of file '%s'.", filename);
1063 - }
1064 -
1065 - // don't use MADV_SEQUENTIAL|MADV_DONTFORK, they disable MADV_MERGEABLE
1066 - if (madvise(mem, size, MADV_SEQUENTIAL | MADV_DONTFORK) != 0 && log_madvise_2) {
1067 - error("Cannot advise the kernel about the memory usage (MADV_SEQUENTIAL|MADV_DONTFORK) of file '%s'.", filename);
1068 - log_madvise_2--;
1069 - }
1070 -
1071 - if (madvise(mem, size, MADV_MERGEABLE) != 0 && log_madvise_3) {
1072 - error("Cannot advise the kernel about the memory usage (MADV_MERGEABLE) of file '%s'.", filename);
1073 - log_madvise_3--;
1074 - }
1075 - }
1076 -
1077 - if(fd != -1)
1078 - close(fd);
1079 -
1080 - return mem;
1081 -}
1082 -#else
1083 -static void *memory_file_mmap_ksm(const char *filename, size_t size, int flags) {
1084 - // info("memory_file_mmap_ksm FALLBACK ('%s', %zu", filename, size);
1085 -
1086 - if(filename)
1087 - return memory_file_mmap(filename, size, flags);
1088 -
1089 - // when KSM is not available and no filename is given (memory mode = ram),
1090 - // we just report failure
1091 - return MAP_FAILED;
1092 -}
1093 -#endif
1094 -
1095 -void *mymmap(const char *filename, size_t size, int flags, int ksm) {
1096 - void *mem = NULL;
1097 -
1098 - if (filename && (flags & MAP_SHARED || !enable_ksm || !ksm))
1099 - // memory mode = map | save
1100 - // when KSM is not enabled
1101 - // MAP_SHARED is used for memory mode = map (no KSM possible)
1102 - mem = memory_file_mmap(filename, size, flags);
1103 -
1104 - else
1105 - // memory mode = save | ram
1106 - // when KSM is enabled
1107 - // for memory mode = ram, the filename is NULL
1108 - mem = memory_file_mmap_ksm(filename, size, flags);
1109 -
1110 - if(mem == MAP_FAILED) return NULL;
1111 -
1112 - errno = 0;
1113 - return mem;
1114 -}
1115 -
1116 -int memory_file_save(const char *filename, void *mem, size_t size) {
1117 - char tmpfilename[FILENAME_MAX + 1];
1118 -
1119 - snprintfz(tmpfilename, FILENAME_MAX, "%s.%ld.tmp", filename, (long) getpid());
1120 -
1121 - int fd = open(tmpfilename, O_RDWR | O_CREAT | O_NOATIME, 0664);
1122 - if (fd < 0) {
1123 - error("Cannot create/open file '%s'.", filename);
1124 - return -1;
1125 - }
1126 -
1127 - if (write(fd, mem, size) != (ssize_t) size) {
1128 - error("Cannot write to file '%s' %ld bytes.", filename, (long) size);
1129 - close(fd);
1130 - return -1;
1131 - }
1132 -
1133 - close(fd);
1134 -
1135 - if (rename(tmpfilename, filename)) {
1136 - error("Cannot rename '%s' to '%s'", tmpfilename, filename);
1137 - return -1;
1138 - }
1139 -
1140 - return 0;
1141 -}
1142 -
1143 -int fd_is_valid(int fd) {
1144 - return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
1145 -}
1146 -
1147 -char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
1148 - char *s = fgets(buf, (int)buf_size, fp);
1149 - if (!s) return NULL;
1150 -
1151 - char *t = s;
1152 - if (*t != '\0') {
1153 - // find the string end
1154 - while (*++t != '\0');
1155 -
1156 - // trim trailing spaces/newlines/tabs
1157 - while (--t > s && *t == '\n')
1158 - *t = '\0';
1159 - }
1160 -
1161 - if (len)
1162 - *len = t - s + 1;
1163 -
1164 - return s;
1165 -}
1166 -
1167 -int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args) {
1168 - int size = vsnprintf(dst, n, fmt, args);
1169 -
1170 - if (unlikely((size_t) size > n)) {
1171 - // truncated
1172 - size = (int)n;
1173 - }
1174 -
1175 - dst[size] = '\0';
1176 - return size;
1177 -}
1178 -
1179 -int snprintfz(char *dst, size_t n, const char *fmt, ...) {
1180 - va_list args;
1181 -
1182 - va_start(args, fmt);
1183 - int ret = vsnprintfz(dst, n, fmt, args);
1184 - va_end(args);
1185 -
1186 - return ret;
1187 -}
1188 -
1189 -// ----------------------------------------------------------------------------
1190 -// system functions
1191 -// to retrieve settings of the system
1192 -
1193 -int processors = 1;
1194 -long get_system_cpus(void) {
1195 - processors = 1;
1196 -
1197 - #ifdef __APPLE__
1198 - int32_t tmp_processors;
1199 -
1200 - if (unlikely(GETSYSCTL_BY_NAME("hw.logicalcpu", tmp_processors))) {
1201 - error("Assuming system has %d processors.", processors);
1202 - } else {
1203 - processors = tmp_processors;
1204 - }
1205 -
1206 - return processors;
1207 - #elif __FreeBSD__
1208 - int32_t tmp_processors;
1209 -
1210 - if (unlikely(GETSYSCTL_BY_NAME("hw.ncpu", tmp_processors))) {
1211 - error("Assuming system has %d processors.", processors);
1212 - } else {
1213 - processors = tmp_processors;
1214 - }
1215 -
1216 - return processors;
1217 - #else
1218 -
1219 - char filename[FILENAME_MAX + 1];
1220 - snprintfz(filename, FILENAME_MAX, "%s/proc/stat", netdata_configured_host_prefix);
1221 -
1222 - procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
1223 - if(!ff) {
1224 - error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
1225 - return processors;
1226 - }
1227 -
1228 - ff = procfile_readall(ff);
1229 - if(!ff) {
1230 - error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
1231 - return processors;
1232 - }
1233 -
1234 - processors = 0;
1235 - unsigned int i;
1236 - for(i = 0; i < procfile_lines(ff); i++) {
1237 - if(!procfile_linewords(ff, i)) continue;
1238 -
1239 - if(strncmp(procfile_lineword(ff, i, 0), "cpu", 3) == 0) processors++;
1240 - }
1241 - processors--;
1242 - if(processors < 1) processors = 1;
1243 -
1244 - procfile_close(ff);
1245 -
1246 - debug(D_SYSTEM, "System has %d processors.", processors);
1247 - return processors;
1248 -
1249 - #endif /* __APPLE__, __FreeBSD__ */
1250 -}
1251 -
1252 -pid_t pid_max = 32768;
1253 -pid_t get_system_pid_max(void) {
1254 - #ifdef __APPLE__
1255 - // As we currently do not know a solution to query pid_max from the os
1256 - // we use the number defined in bsd/sys/proc_internal.h in XNU sources
1257 - pid_max = 99999;
1258 - return pid_max;
1259 - #elif __FreeBSD__
1260 - int32_t tmp_pid_max;
1261 -
1262 - if (unlikely(GETSYSCTL_BY_NAME("kern.pid_max", tmp_pid_max))) {
1263 - pid_max = 99999;
1264 - error("Assuming system's maximum pid is %d.", pid_max);
1265 - } else {
1266 - pid_max = tmp_pid_max;
1267 - }
1268 -
1269 - return pid_max;
1270 - #else
1271 -
1272 - static char read = 0;
1273 - if(unlikely(read)) return pid_max;
1274 - read = 1;
1275 -
1276 - char filename[FILENAME_MAX + 1];
1277 - snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", netdata_configured_host_prefix);
1278 -
1279 - unsigned long long max = 0;
1280 - if(read_single_number_file(filename, &max) != 0) {
1281 - error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
1282 - return pid_max;
1283 - }
1284 -
1285 - if(!max) {
1286 - error("Cannot parse file '%s'. Assuming system supports %d pids.", filename, pid_max);
1287 - return pid_max;
1288 - }
1289 -
1290 - pid_max = (pid_t) max;
1291 - return pid_max;
1292 -
1293 - #endif /* __APPLE__, __FreeBSD__ */
1294 -}
1295 -
1296 -unsigned int system_hz;
1297 -void get_system_HZ(void) {
1298 - long ticks;
1299 -
1300 - if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
1301 - error("Cannot get system clock ticks");
1302 - }
1303 -
1304 - system_hz = (unsigned int) ticks;
1305 -}
1306 -
1307 -/*
1308 -// poor man cycle counting
1309 -static unsigned long tsc;
1310 -void begin_tsc(void) {
1311 - unsigned long a, d;
1312 - asm volatile ("cpuid\nrdtsc" : "=a" (a), "=d" (d) : "0" (0) : "ebx", "ecx");
1313 - tsc = ((unsigned long)d << 32) | (unsigned long)a;
1314 -}
1315 -unsigned long end_tsc(void) {
1316 - unsigned long a, d;
1317 - asm volatile ("rdtscp" : "=a" (a), "=d" (d) : : "ecx");
1318 - return (((unsigned long)d << 32) | (unsigned long)a) - tsc;
1319 -}
1320 -*/
1321 -
1322 -int recursively_delete_dir(const char *path, const char *reason) {
1323 - DIR *dir = opendir(path);
1324 - if(!dir) {
1325 - error("Cannot read %s directory to be deleted '%s'", reason?reason:"", path);
1326 - return -1;
1327 - }
1328 -
1329 - int ret = 0;
1330 - struct dirent *de = NULL;
1331 - while((de = readdir(dir))) {
1332 - if(de->d_type == DT_DIR
1333 - && (
1334 - (de->d_name[0] == '.' && de->d_name[1] == '\0')
1335 - || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1336 - ))
1337 - continue;
1338 -
1339 - char fullpath[FILENAME_MAX + 1];
1340 - snprintfz(fullpath, FILENAME_MAX, "%s/%s", path, de->d_name);
1341 -
1342 - if(de->d_type == DT_DIR) {
1343 - int r = recursively_delete_dir(fullpath, reason);
1344 - if(r > 0) ret += r;
1345 - continue;
1346 - }
1347 -
1348 - info("Deleting %s file '%s'", reason?reason:"", fullpath);
1349 - if(unlikely(unlink(fullpath) == -1))
1350 - error("Cannot delete %s file '%s'", reason?reason:"", fullpath);
1351 - else
1352 - ret++;
1353 - }
1354 -
1355 - info("Deleting empty directory '%s'", path);
1356 - if(unlikely(rmdir(path) == -1))
1357 - error("Cannot delete empty directory '%s'", path);
1358 - else
1359 - ret++;
1360 -
1361 - closedir(dir);
1362 -
1363 - return ret;
1364 -}
1365 -
1366 -static int is_virtual_filesystem(const char *path, char **reason) {
1367 -
1368 -#if defined(__APPLE__) || defined(__FreeBSD__)
1369 - (void)path;
1370 - (void)reason;
1371 -#else
1372 - struct statfs stat;
1373 - // stat.f_fsid.__val[0] is a file system id
1374 - // stat.f_fsid.__val[1] is the inode
1375 - // so their combination uniquely identifies the file/dir
1376 -
1377 - if (statfs(path, &stat) == -1) {
1378 - if(reason) *reason = "failed to statfs()";
1379 - return -1;
1380 - }
1381 -
1382 - if(stat.f_fsid.__val[0] != 0 || stat.f_fsid.__val[1] != 0) {
1383 - errno = EINVAL;
1384 - if(reason) *reason = "is not a virtual file system";
1385 - return -1;
1386 - }
1387 -#endif
1388 -
1389 - return 0;
1390 -}
1391 -
1392 -int verify_netdata_host_prefix() {
1393 - if(!netdata_configured_host_prefix)
1394 - netdata_configured_host_prefix = "";
1395 -
1396 - if(!*netdata_configured_host_prefix)
1397 - return 0;
1398 -
1399 - char buffer[FILENAME_MAX + 1];
1400 - char *path = netdata_configured_host_prefix;
1401 - char *reason = "unknown reason";
1402 - errno = 0;
1403 -
1404 - struct stat sb;
1405 - if (stat(path, &sb) == -1) {
1406 - reason = "failed to stat()";
1407 - goto failed;
1408 - }
1409 -
1410 - if((sb.st_mode & S_IFMT) != S_IFDIR) {
1411 - errno = EINVAL;
1412 - reason = "is not a directory";
1413 - goto failed;
1414 - }
1415 -
1416 - path = buffer;
1417 - snprintfz(path, FILENAME_MAX, "%s/proc", netdata_configured_host_prefix);
1418 - if(is_virtual_filesystem(path, &reason) == -1)
1419 - goto failed;
1420 -
1421 - snprintfz(path, FILENAME_MAX, "%s/sys", netdata_configured_host_prefix);
1422 - if(is_virtual_filesystem(path, &reason) == -1)
1423 - goto failed;
1424 -
1425 - if(netdata_configured_host_prefix && *netdata_configured_host_prefix)
1426 - info("Using host prefix directory '%s'", netdata_configured_host_prefix);
1427 -
1428 - return 0;
1429 -
1430 -failed:
1431 - error("Ignoring host prefix '%s': path '%s' %s", netdata_configured_host_prefix, path, reason);
1432 - netdata_configured_host_prefix = "";
1433 - return -1;
1434 -}
1435 -
1436 -char *strdupz_path_subpath(const char *path, const char *subpath) {
1437 - if(unlikely(!path || !*path)) path = ".";
1438 - if(unlikely(!subpath)) subpath = "";
1439 -
1440 - // skip trailing slashes in path
1441 - size_t len = strlen(path);
1442 - while(len > 0 && path[len - 1] == '/') len--;
1443 -
1444 - // skip leading slashes in subpath
1445 - while(subpath[0] == '/') subpath++;
1446 -
1447 - // if the last character in path is / and (there is a subpath or path is now empty)
1448 - // keep the trailing slash in path and remove the additional slash
1449 - char *slash = "/";
1450 - if(path[len] == '/' && (*subpath || len == 0)) {
1451 - slash = "";
1452 - len++;
1453 - }
1454 - else if(!*subpath) {
1455 - // there is no subpath
1456 - // no need for trailing slash
1457 - slash = "";
1458 - }
1459 -
1460 - char buffer[FILENAME_MAX + 1];
1461 - snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, subpath);
1462 - return strdupz(buffer);
1463 -}
1464 -
1465 -int path_is_dir(const char *path, const char *subpath) {
1466 - char *s = strdupz_path_subpath(path, subpath);
1467 -
1468 - size_t max_links = 100;
1469 -
1470 - int is_dir = 0;
1471 - struct stat statbuf;
1472 - while(max_links-- && stat(s, &statbuf) == 0) {
1473 - if((statbuf.st_mode & S_IFMT) == S_IFDIR) {
1474 - is_dir = 1;
1475 - break;
1476 - }
1477 - else if((statbuf.st_mode & S_IFMT) == S_IFLNK) {
1478 - char buffer[FILENAME_MAX + 1];
1479 - ssize_t l = readlink(s, buffer, FILENAME_MAX);
1480 - if(l > 0) {
1481 - buffer[l] = '\0';
1482 - freez(s);
1483 - s = strdupz(buffer);
1484 - continue;
1485 - }
1486 - else {
1487 - is_dir = 0;
1488 - break;
1489 - }
1490 - }
1491 - else {
1492 - is_dir = 0;
1493 - break;
1494 - }
1495 - }
1496 -
1497 - freez(s);
1498 - return is_dir;
1499 -}
1500 -
1501 -int path_is_file(const char *path, const char *subpath) {
1502 - char *s = strdupz_path_subpath(path, subpath);
1503 -
1504 - size_t max_links = 100;
1505 -
1506 - int is_file = 0;
1507 - struct stat statbuf;
1508 - while(max_links-- && stat(s, &statbuf) == 0) {
1509 - if((statbuf.st_mode & S_IFMT) == S_IFREG) {
1510 - is_file = 1;
1511 - break;
1512 - }
1513 - else if((statbuf.st_mode & S_IFMT) == S_IFLNK) {
1514 - char buffer[FILENAME_MAX + 1];
1515 - ssize_t l = readlink(s, buffer, FILENAME_MAX);
1516 - if(l > 0) {
1517 - buffer[l] = '\0';
1518 - freez(s);
1519 - s = strdupz(buffer);
1520 - continue;
1521 - }
1522 - else {
1523 - is_file = 0;
1524 - break;
1525 - }
1526 - }
1527 - else {
1528 - is_file = 0;
1529 - break;
1530 - }
1531 - }
1532 -
1533 - freez(s);
1534 - return is_file;
1535 -}
1536 -
1537 -void recursive_config_double_dir_load(const char *user_path, const char *stock_path, const char *subpath, int (*callback)(const char *filename, void *data), void *data, size_t depth) {
1538 - if(depth > 3) {
1539 - error("CONFIG: Max directory depth reached while reading user path '%s', stock path '%s', subpath '%s'", user_path, stock_path, subpath);
1540 - return;
1541 - }
1542 -
1543 - char *udir = strdupz_path_subpath(user_path, subpath);
1544 - char *sdir = strdupz_path_subpath(stock_path, subpath);
1545 -
1546 - debug(D_HEALTH, "CONFIG traversing user-config directory '%s', stock config directory '%s'", udir, sdir);
1547 -
1548 - DIR *dir = opendir(udir);
1549 - if (!dir) {
1550 - error("CONFIG cannot open user-config directory '%s'.", udir);
1551 - }
1552 - else {
1553 - struct dirent *de = NULL;
1554 - while((de = readdir(dir))) {
1555 - if(de->d_type == DT_DIR || de->d_type == DT_LNK) {
1556 - if( !de->d_name[0] ||
1557 - (de->d_name[0] == '.' && de->d_name[1] == '\0') ||
1558 - (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1559 - ) {
1560 - debug(D_HEALTH, "CONFIG ignoring user-config directory '%s/%s'", udir, de->d_name);
1561 - continue;
1562 - }
1563 -
1564 - if(path_is_dir(udir, de->d_name)) {
1565 - recursive_config_double_dir_load(udir, sdir, de->d_name, callback, data, depth + 1);
1566 - continue;
1567 - }
1568 - }
1569 -
1570 - if(de->d_type == DT_REG || de->d_type == DT_LNK) {
1571 - size_t len = strlen(de->d_name);
1572 - if(path_is_file(udir, de->d_name) &&
1573 - len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
1574 - char *filename = strdupz_path_subpath(udir, de->d_name);
1575 - callback(filename, data);
1576 - freez(filename);
1577 - }
1578 - else
1579 - debug(D_HEALTH, "CONFIG ignoring user-config file '%s/%s'", udir, de->d_name);
1580 - }
1581 - }
1582 -
1583 - closedir(dir);
1584 - }
1585 -
1586 - debug(D_HEALTH, "CONFIG traversing stock config directory '%s', user config directory '%s'", sdir, udir);
1587 -
1588 - dir = opendir(sdir);
1589 - if (!dir) {
1590 - error("CONFIG cannot open stock config directory '%s'.", sdir);
1591 - }
1592 - else {
1593 - struct dirent *de = NULL;
1594 - while((de = readdir(dir))) {
1595 - if(de->d_type == DT_DIR || de->d_type == DT_LNK) {
1596 - if( !de->d_name[0] ||
1597 - (de->d_name[0] == '.' && de->d_name[1] == '\0') ||
1598 - (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1599 - ) {
1600 - debug(D_HEALTH, "CONFIG ignoring stock config directory '%s/%s'", sdir, de->d_name);
1601 - continue;
1602 - }
1603 -
1604 - if(path_is_dir(sdir, de->d_name)) {
1605 - // we recurse in stock subdirectory, only when there is no corresponding
1606 - // user subdirectory - to avoid reading the files twice
1607 -
1608 - if(!path_is_dir(udir, de->d_name))
1609 - recursive_config_double_dir_load(udir, sdir, de->d_name, callback, data, depth + 1);
1610 -
1611 - continue;
1612 - }
1613 - }
1614 -
1615 - if(de->d_type == DT_REG || de->d_type == DT_LNK) {
1616 - size_t len = strlen(de->d_name);
1617 - if(path_is_file(sdir, de->d_name) && !path_is_file(udir, de->d_name) &&
1618 - len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
1619 - char *filename = strdupz_path_subpath(sdir, de->d_name);
1620 - callback(filename, data);
1621 - freez(filename);
1622 - }
1623 - else
1624 - debug(D_HEALTH, "CONFIG ignoring stock config file '%s/%s'", sdir, de->d_name);
1625 - }
1626 - }
1627 -
1628 - closedir(dir);
1629 - }
1630 -
1631 - freez(udir);
1632 - freez(sdir);
1633 -}
src/common.h
+26 -418
@@ -1,354 +1,49 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 #ifndef NETDATA_COMMON_H
4 #define NETDATA_COMMON_H 1
5
5 -#ifdef HAVE_CONFIG_H
6 -#include <config.h>
7 -#endif
6 +#include "libnetdata/libnetdata.h"
7
8 // ----------------------------------------------------------------------------
10 -// system include files for all netdata C programs
11 -
12 -/* select the memory allocator, based on autoconf findings */
13 -#if defined(ENABLE_JEMALLOC)
14 -
15 -#if defined(HAVE_JEMALLOC_JEMALLOC_H)
16 -#include <jemalloc/jemalloc.h>
17 -#else
18 -#include <malloc.h>
19 -#endif
20 -
21 -#elif defined(ENABLE_TCMALLOC)
22 -
23 -#include <google/tcmalloc.h>
24 -
25 -#else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
26 -
27 -#if !(defined(__FreeBSD__) || defined(__APPLE__))
28 -#include <malloc.h>
29 -#endif /* __FreeBSD__ || __APPLE__ */
30 -
31 -#endif
32 -
33 -#include <pthread.h>
34 -#include <errno.h>
35 -#include <stdio.h>
36 -#include <stdlib.h>
37 -#include <stdarg.h>
38 -#include <stddef.h>
39 -#include <ctype.h>
40 -#include <string.h>
41 -#include <strings.h>
42 -#include <arpa/inet.h>
43 -#include <netinet/tcp.h>
44 -#include <sys/ioctl.h>
45 -#include <libgen.h>
46 -
47 -#ifdef HAVE_NETINET_IN_H
48 -#include <netinet/in.h>
49 -#endif
50 -
51 -#ifdef HAVE_RESOLV_H
52 -#include <resolv.h>
53 -#endif
54 -
55 -#include <dirent.h>
56 -#include <fcntl.h>
57 -#include <getopt.h>
58 -#include <grp.h>
59 -#include <pwd.h>
60 -#include <locale.h>
61 -
62 -#ifdef HAVE_NETDB_H
63 -#include <netdb.h>
64 -#endif
65 -
66 -#include <net/if.h>
67 -
68 -#include <poll.h>
69 -#include <signal.h>
70 -#include <syslog.h>
71 -#include <sys/mman.h>
72 -
73 -#ifdef HAVE_SYS_PRCTL_H
74 -#include <sys/prctl.h>
75 -#endif
76 -
77 -#include <sys/resource.h>
78 -#include <sys/socket.h>
79 -
80 -#ifdef HAVE_SYS_STAT_H
81 -#include <sys/stat.h>
82 -#endif
83 -
84 -#ifdef HAVE_SYS_VFS_H
85 -#include <sys/vfs.h>
86 -#endif
87 -
88 -#ifdef HAVE_SYS_STATFS_H
89 -#include <sys/statfs.h>
90 -#endif
91 -
92 -#ifdef HAVE_SYS_MOUNT_H
93 -#include <sys/mount.h>
94 -#endif
95 -
96 -#ifdef HAVE_SYS_STATVFS_H
97 -#include <sys/statvfs.h>
98 -#endif
99 -
100 -#include <sys/syscall.h>
101 -#include <sys/time.h>
102 -#include <sys/types.h>
103 -#include <sys/wait.h>
104 -#include <sys/un.h>
105 -#include <time.h>
106 -#include <unistd.h>
107 -#include <uuid/uuid.h>
108 -
109 -// #1408
110 -#ifdef MAJOR_IN_MKDEV
111 -#include <sys/mkdev.h>
112 -#endif
113 -#ifdef MAJOR_IN_SYSMACROS
114 -#include <sys/sysmacros.h>
115 -#endif
116 -
117 -/*
118 -#include <mntent.h>
119 -*/
120 -
121 -#ifdef STORAGE_WITH_MATH
122 -#include <math.h>
123 -#include <float.h>
124 -#endif
125 -
126 -#if defined(HAVE_INTTYPES_H)
127 -#include <inttypes.h>
128 -#elif defined(HAVE_STDINT_H)
129 -#include <stdint.h>
130 -#endif
131 -
132 -#ifdef NETDATA_WITH_ZLIB
133 -#include <zlib.h>
134 -#endif
135 -
136 -#ifdef HAVE_CAPABILITY
137 -#include <sys/capability.h>
138 -#endif
139 -
140 -// ----------------------------------------------------------------------------
141 -// netdata chart priorities
142 -
143 -// This is a work in progress - to scope is to collect here all chart priorities.
144 -// These should be based on the CONTEXT of the charts + the chart id when needed
145 -// - for each SECTION +1000 (or +X000 for big sections)
146 -// - for each FAMILY +100
147 -// - for each CHART +10
148 -
149 -#define NETDATA_CHART_PRIO_SYSTEM_IP 501
150 -#define NETDATA_CHART_PRIO_SYSTEM_IPV6 502
151 -
152 -// Memory Section - 1xxx
153 -#define NETDATA_CHART_PRIO_MEM_SYSTEM 1000
154 -#define NETDATA_CHART_PRIO_MEM_SYSTEM_AVAILABLE 1010
155 -#define NETDATA_CHART_PRIO_MEM_SYSTEM_COMMITTED 1020
156 -#define NETDATA_CHART_PRIO_MEM_SYSTEM_PGFAULTS 1030
157 -#define NETDATA_CHART_PRIO_MEM_KERNEL 1100
158 -#define NETDATA_CHART_PRIO_MEM_SLAB 1200
159 -#define NETDATA_CHART_PRIO_MEM_HUGEPAGES 1250
160 -#define NETDATA_CHART_PRIO_MEM_KSM 1300
161 -#define NETDATA_CHART_PRIO_MEM_NUMA 1400
162 -#define NETDATA_CHART_PRIO_MEM_HW 1500
163 -
164 -
165 -// IP
166 -
167 -#define NETDATA_CHART_PRIO_IP 4000
168 -#define NETDATA_CHART_PRIO_IP_ERRORS 4100
169 -#define NETDATA_CHART_PRIO_IP_TCP 4200
170 -#define NETDATA_CHART_PRIO_IP_TCP_MEM 4290
171 -#define NETDATA_CHART_PRIO_IP_BCAST 4500
172 -#define NETDATA_CHART_PRIO_IP_MCAST 4600
173 -#define NETDATA_CHART_PRIO_IP_ECN 4700
174 -
175 -
176 -// IPv4
177 -
178 -#define NETDATA_CHART_PRIO_IPV4 5100
179 -#define NETDATA_CHART_PRIO_IPV4_SOCKETS 5100
180 -#define NETDATA_CHART_PRIO_IPV4_PACKETS 5130
181 -#define NETDATA_CHART_PRIO_IPV4_ERRORS 5150
182 -#define NETDATA_CHART_PRIO_IPV4_ICMP 5170
183 -#define NETDATA_CHART_PRIO_IPV4_TCP 5200
184 -#define NETDATA_CHART_PRIO_IPV4_TCP_MEM 5290
185 -#define NETDATA_CHART_PRIO_IPV4_UDP 5300
186 -#define NETDATA_CHART_PRIO_IPV4_UDP_MEM 5390
187 -#define NETDATA_CHART_PRIO_IPV4_UDPLITE 5400
188 -#define NETDATA_CHART_PRIO_IPV4_RAW 5450
189 -#define NETDATA_CHART_PRIO_IPV4_FRAGMENTS 5460
190 -#define NETDATA_CHART_PRIO_IPV4_FRAGMENTS_MEM 5470
191 -
192 -// IPv6
193 -
194 -#define NETDATA_CHART_PRIO_IPV6 6200
195 -#define NETDATA_CHART_PRIO_IPV6_PACKETS 6200
196 -#define NETDATA_CHART_PRIO_IPV6_ERRORS 6300
197 -#define NETDATA_CHART_PRIO_IPV6_FRAGMENTS 6400
198 -#define NETDATA_CHART_PRIO_IPV6_TCP 6500
199 -#define NETDATA_CHART_PRIO_IPV6_UDP 6600
200 -#define NETDATA_CHART_PRIO_IPV6_UDP_ERRORS 6610
201 -#define NETDATA_CHART_PRIO_IPV6_UDPLITE 6700
202 -#define NETDATA_CHART_PRIO_IPV6_UDPLITE_ERRORS 6710
203 -#define NETDATA_CHART_PRIO_IPV6_RAW 6800
204 -#define NETDATA_CHART_PRIO_IPV6_BCAST 6840
205 -#define NETDATA_CHART_PRIO_IPV6_MCAST 6850
206 -#define NETDATA_CHART_PRIO_IPV6_ICMP 6900
207 -
208 -
209 -// SCTP
210 -
211 -#define NETDATA_CHART_PRIO_SCTP 7000
212 -
213 -
214 -// Netfilter
215 -
216 -#define NETDATA_CHART_PRIO_NETFILTER 8700
217 -#define NETDATA_CHART_PRIO_SYNPROXY 8750
218 -
219 -
220 -// ----------------------------------------------------------------------------
221 -// netdata common definitions
222 -
223 -#if (SIZEOF_VOID_P == 8)
224 -#define ENVIRONMENT64
225 -#elif (SIZEOF_VOID_P == 4)
226 -#define ENVIRONMENT32
227 -#else
228 -#error "Cannot detect if this is a 32 or 64 bit CPU"
229 -#endif
230 -
231 -#ifdef __GNUC__
232 -#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
233 -#endif // __GNUC__
234 -
235 -#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
236 -#define NEVERNULL __attribute__((returns_nonnull))
237 -#else
238 -#define NEVERNULL
239 -#endif
240 -
241 -#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
242 -#define NOINLINE __attribute__((noinline))
243 -#else
244 -#define NOINLINE
245 -#endif
246 -
247 -#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
248 -#define MALLOCLIKE __attribute__((malloc))
249 -#else
250 -#define MALLOCLIKE
251 -#endif
9 +// netdata include files
10
253 -#ifdef HAVE_FUNC_ATTRIBUTE_FORMAT
254 -#define PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
255 -#else
256 -#define PRINTFLIKE(f, a)
257 -#endif
11 +#include "global_statistics.h"
12
259 -#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
260 -#define NORETURN __attribute__ ((noreturn))
261 -#else
262 -#define NORETURN
263 -#endif
13 +// the netdata database
14 +#include "database/rrd.h"
15
265 -#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
266 -#define WARNUNUSED __attribute__ ((warn_unused_result))
267 -#else
268 -#define WARNUNUSED
269 -#endif
16 +// the netdata webserver(s)
17 +#include "webserver/web_server.h"
18
271 -#ifdef abs
272 -#undef abs
273 -#endif
274 -#define abs(x) (((x) < 0)? (-(x)) : (x))
19 +// streaming metrics between netdata servers
20 +#include "streaming/rrdpush.h"
21
276 -#define GUID_LEN 36
22 +// health monitoring and alarm notifications
23 +#include "health/health.h"
24
278 -// ----------------------------------------------------------------------------
25 +// the netdata registry
26 +// the registry is actually an API feature
27 +#include "registry/registry.h"
28
280 -typedef enum rrdcalc_status {
281 - RRDCALC_STATUS_REMOVED = -2,
282 - RRDCALC_STATUS_UNDEFINED = -1,
283 - RRDCALC_STATUS_UNINITIALIZED = 0,
284 - RRDCALC_STATUS_CLEAR = 1,
285 - RRDCALC_STATUS_RAISED = 2,
286 - RRDCALC_STATUS_WARNING = 3,
287 - RRDCALC_STATUS_CRITICAL = 4
288 -} RRDCALC_STATUS;
29 +// backends for archiving the metrics
30 +#include "src/backends/backends.h"
31
290 -// ----------------------------------------------------------------------------
291 -// netdata include files
32 +// the netdata API
33 +#include "api/web_api_v1.h"
34
293 -#include "clocks.h"
294 -#include "log.h"
295 -#include "threads.h"
296 -#include "locks.h"
297 -#include "simple_pattern.h"
298 -#include "avl.h"
299 -#include "global_statistics.h"
300 -#include "storage_number.h"
301 -#include "web_buffer.h"
302 -#include "web_buffer_svg.h"
303 -#include "url.h"
304 -#include "popen.h"
35 +// all data collection plugins
36 +#include "plugins/all.h"
37
306 -#include "procfile.h"
307 -#include "appconfig.h"
308 -#include "dictionary.h"
309 -#include "proc_self_mountinfo.h"
310 -#include "plugin_checks.h"
311 -#include "plugin_idlejitter.h"
312 -#include "plugin_nfacct.h"
313 -
314 -#if defined(__FreeBSD__)
315 -#include <pthread_np.h>
316 -#include "plugin_freebsd.h"
317 -#define NETDATA_OS_TYPE "freebsd"
318 -#elif defined(__APPLE__)
319 -#include "plugin_macos.h"
320 -#define NETDATA_OS_TYPE "macos"
321 -#else
322 -#include "plugin_proc.h"
323 -#include "plugin_proc_diskspace.h"
324 -#define NETDATA_OS_TYPE "linux"
325 -#endif /* __FreeBSD__, __APPLE__*/
326 -
327 -#include "eval.h"
328 -#include "health.h"
38 +// netdata unit tests
39 +#include "unit_test.h"
40
330 -#include "statistical.h"
331 -#include "socket.h"
332 -#include "rrd.h"
333 -#include "plugin_tc.h"
334 -#include "plugins_d.h"
335 -#include "statsd.h"
336 -#include "rrd2json.h"
337 -#include "web_client.h"
338 -#include "web_server.h"
339 -#include "registry.h"
340 -#include "signals.h"
41 +// the netdata deamon
42 #include "daemon.h"
43 #include "main.h"
343 -#include "unit_test.h"
344 -#include "ipc.h"
345 -#include "backends.h"
346 -#include "backend_prometheus.h"
347 -#include "inlined.h"
348 -#include "adaptive_resortable_list.h"
349 -#include "rrdpush.h"
350 -#include "web_api_v1.h"
44 +#include "signals.h"
45
46 +// global netdata daemon variables
47 extern char *netdata_configured_hostname;
48 extern char *netdata_configured_user_config_dir;
49 extern char *netdata_configured_stock_config_dir;
@@ -362,91 +57,4 @@ extern char *netdata_configured_home_dir;
57 extern char *netdata_configured_host_prefix;
58 extern char *netdata_configured_timezone;
59
365 -extern void netdata_fix_chart_id(char *s);
366 -extern void netdata_fix_chart_name(char *s);
367 -
368 -extern void strreverse(char* begin, char* end);
369 -extern char *mystrsep(char **ptr, char *s);
370 -extern char *trim(char *s); // remove leading and trailing spaces; may return NULL
371 -extern char *trim_all(char *buffer); // like trim(), but also remove duplicate spaces inside the string; may return NULL
372 -
373 -extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
374 -extern int snprintfz(char *dst, size_t n, const char *fmt, ...) PRINTFLIKE(3, 4);
375 -
376 -// memory allocation functions that handle failures
377 -#ifdef NETDATA_LOG_ALLOCATIONS
378 -#define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
379 -#define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
380 -#define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
381 -#define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
382 -#define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
383 -
384 -extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
385 -extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
386 -extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
387 -extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
388 -extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
389 -#else
390 -extern char *strdupz(const char *s) MALLOCLIKE NEVERNULL;
391 -extern void *callocz(size_t nmemb, size_t size) MALLOCLIKE NEVERNULL;
392 -extern void *mallocz(size_t size) MALLOCLIKE NEVERNULL;
393 -extern void *reallocz(void *ptr, size_t size) MALLOCLIKE NEVERNULL;
394 -extern void freez(void *ptr);
395 -#endif
396 -
397 -extern void json_escape_string(char *dst, const char *src, size_t size);
398 -extern void json_fix_string(char *s);
399 -
400 -extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
401 -extern int memory_file_save(const char *filename, void *mem, size_t size);
402 -
403 -extern int fd_is_valid(int fd);
404 -
405 -extern struct rlimit rlimit_nofile;
406 -
407 -extern int enable_ksm;
408 -
409 -extern int sleep_usec(usec_t usec);
410 -
411 -extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
412 -
413 -extern int processors;
414 -extern long get_system_cpus(void);
415 -extern int verify_netdata_host_prefix();
416 -
417 -extern pid_t pid_max;
418 -extern pid_t get_system_pid_max(void);
419 -
420 -/* Number of ticks per second */
421 -extern unsigned int system_hz;
422 -extern void get_system_HZ(void);
423 -
424 -extern int recursively_delete_dir(const char *path, const char *reason);
425 -
426 -extern volatile sig_atomic_t netdata_exit;
427 -extern const char *os_type;
428 -
429 -extern const char *program_version;
430 -
431 -extern char *strdupz_path_subpath(const char *path, const char *subpath);
432 -extern int path_is_dir(const char *path, const char *subpath);
433 -extern int path_is_file(const char *path, const char *subpath);
434 -extern void recursive_config_double_dir_load(
435 - const char *user_path
436 - , const char *stock_path
437 - , const char *subpath
438 - , int (*callback)(const char *filename, void *data)
439 - , void *data
440 - , size_t depth
441 - );
442 -
443 -/* fix for alpine linux */
444 -#ifndef RUSAGE_THREAD
445 -#ifdef RUSAGE_CHILDREN
446 -#define RUSAGE_THREAD RUSAGE_CHILDREN
447 -#endif
448 -#endif
449 -
450 -#define BITS_IN_A_KILOBIT 1000
451 -
60 #endif /* NETDATA_COMMON_H */
src/database/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/database/rrd.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 #define NETDATA_RRD_INTERNALS 1
3
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // globals
src/database/rrd.h renamed
+78 -4
@@ -3,6 +3,25 @@
3 #ifndef NETDATA_RRD_H
4 #define NETDATA_RRD_H 1
5
6 +// forward typedefs
7 +typedef struct rrdhost RRDHOST;
8 +typedef struct rrddim RRDDIM;
9 +typedef struct rrdset RRDSET;
10 +typedef struct rrdvar RRDVAR;
11 +typedef struct rrdsetvar RRDSETVAR;
12 +typedef struct rrddimvar RRDDIMVAR;
13 +typedef struct rrdcalc RRDCALC;
14 +typedef struct rrdcalctemplate RRDCALCTEMPLATE;
15 +typedef struct alarm_entry ALARM_ENTRY;
16 +
17 +#include "../common.h"
18 +
19 +#include "rrdvar.h"
20 +#include "rrdsetvar.h"
21 +#include "rrddimvar.h"
22 +#include "rrdcalc.h"
23 +#include "rrdcalctemplate.h"
24 +
25 #define UPDATE_EVERY 1
26 #define UPDATE_EVERY_MAX 3600
27
@@ -21,8 +40,6 @@ extern int gap_when_lost_iterations_above;
40 typedef long long total_number;
41 #define TOTAL_NUMBER_FORMAT "%lld"
42
24 -typedef struct rrdhost RRDHOST;
25 -
43 // ----------------------------------------------------------------------------
44 // chart types
45
@@ -204,7 +221,6 @@ struct rrddim {
221
222 storage_number values[]; // the array of values - THIS HAS TO BE THE LAST MEMBER
223 };
207 -typedef struct rrddim RRDDIM;
224
225 // ----------------------------------------------------------------------------
226 // these loop macros make sure the linked list is accessed with the right lock
@@ -357,7 +373,6 @@ struct rrdset {
373 RRDDIM *dimensions; // the actual data for every dimension
374
375 };
360 -typedef struct rrdset RRDSET;
376
377 #define rrdset_rdlock(st) netdata_rwlock_rdlock(&((st)->rrdset_rwlock))
378 #define rrdset_wrlock(st) netdata_rwlock_wrlock(&((st)->rrdset_rwlock))
@@ -405,6 +420,65 @@ typedef enum rrdhost_flags {
420 #define rrdset_debug(st, fmt, args...) debug_dummy()
421 #endif
422
423 +// ----------------------------------------------------------------------------
424 +// Health data
425 +
426 +struct alarm_entry {
427 + uint32_t unique_id;
428 + uint32_t alarm_id;
429 + uint32_t alarm_event_id;
430 +
431 + time_t when;
432 + time_t duration;
433 + time_t non_clear_duration;
434 +
435 + char *name;
436 + uint32_t hash_name;
437 +
438 + char *chart;
439 + uint32_t hash_chart;
440 +
441 + char *family;
442 +
443 + char *exec;
444 + char *recipient;
445 + time_t exec_run_timestamp;
446 + int exec_code;
447 +
448 + char *source;
449 + char *units;
450 + char *info;
451 +
452 + calculated_number old_value;
453 + calculated_number new_value;
454 +
455 + char *old_value_string;
456 + char *new_value_string;
457 +
458 + RRDCALC_STATUS old_status;
459 + RRDCALC_STATUS new_status;
460 +
461 + uint32_t flags;
462 +
463 + int delay;
464 + time_t delay_up_to_timestamp;
465 +
466 + uint32_t updated_by_id;
467 + uint32_t updates_id;
468 +
469 + struct alarm_entry *next;
470 +};
471 +
472 +
473 +typedef struct alarm_log {
474 + uint32_t next_log_id;
475 + uint32_t next_alarm_id;
476 + unsigned int count;
477 + unsigned int max;
478 + ALARM_ENTRY *alarms;
479 + netdata_rwlock_t alarm_log_rwlock;
480 +} ALARM_LOG;
481 +
482
483 // ----------------------------------------------------------------------------
484 // RRD HOST
src/database/rrdcalc.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDCALC management
src/database/rrdcalc.h new
+136
@@ -0,0 +1,136 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "rrd.h"
4 +
5 +#ifndef NETDATA_RRDCALC_H
6 +#define NETDATA_RRDCALC_H 1
7 +
8 +// calculated variables (defined in health configuration)
9 +// These aggregate time-series data at fixed intervals
10 +// (defined in their update_every member below)
11 +// They increase the overhead of netdata.
12 +//
13 +// These calculations are allocated and linked (->next)
14 +// under RRDHOST.
15 +// Then are also linked to RRDSET (of course only when the
16 +// chart is found, via ->rrdset_next and ->rrdset_prev).
17 +// This double-linked list is maintained sorted at all times
18 +// having as RRDSET.calculations the RRDCALC to be processed
19 +// next.
20 +
21 +#define RRDCALC_FLAG_DB_ERROR 0x00000001
22 +#define RRDCALC_FLAG_DB_NAN 0x00000002
23 +/* #define RRDCALC_FLAG_DB_STALE 0x00000004 */
24 +#define RRDCALC_FLAG_CALC_ERROR 0x00000008
25 +#define RRDCALC_FLAG_WARN_ERROR 0x00000010
26 +#define RRDCALC_FLAG_CRIT_ERROR 0x00000020
27 +#define RRDCALC_FLAG_RUNNABLE 0x00000040
28 +#define RRDCALC_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
29 +
30 +struct rrdcalc {
31 + uint32_t id; // the unique id of this alarm
32 + uint32_t next_event_id; // the next event id that will be used for this alarm
33 +
34 + char *name; // the name of this alarm
35 + uint32_t hash;
36 +
37 + char *exec; // the command to execute when this alarm switches state
38 + char *recipient; // the recipient of the alarm (the first parameter to exec)
39 +
40 + char *chart; // the chart id this should be linked to
41 + uint32_t hash_chart;
42 +
43 + char *source; // the source of this alarm
44 + char *units; // the units of the alarm
45 + char *info; // a short description of the alarm
46 +
47 + int update_every; // update frequency for the alarm
48 +
49 + // the red and green threshold of this alarm (to be set to the chart)
50 + calculated_number green;
51 + calculated_number red;
52 +
53 + // ------------------------------------------------------------------------
54 + // database lookup settings
55 +
56 + char *dimensions; // the chart dimensions
57 + int group; // grouping method: average, max, etc.
58 + int before; // ending point in time-series
59 + int after; // starting point in time-series
60 + uint32_t options; // calculation options
61 +
62 + // ------------------------------------------------------------------------
63 + // expressions related to the alarm
64 +
65 + EVAL_EXPRESSION *calculation; // expression to calculate the value of the alarm
66 + EVAL_EXPRESSION *warning; // expression to check the warning condition
67 + EVAL_EXPRESSION *critical; // expression to check the critical condition
68 +
69 + // ------------------------------------------------------------------------
70 + // notification delay settings
71 +
72 + int delay_up_duration; // duration to delay notifications when alarm raises
73 + int delay_down_duration; // duration to delay notifications when alarm lowers
74 + int delay_max_duration; // the absolute max delay to apply to this alarm
75 + float delay_multiplier; // multiplier for all delays when alarms switch status
76 + // while now < delay_up_to
77 +
78 + // ------------------------------------------------------------------------
79 + // runtime information
80 +
81 + RRDCALC_STATUS status; // the current status of the alarm
82 +
83 + calculated_number value; // the current value of the alarm
84 + calculated_number old_value; // the previous value of the alarm
85 +
86 + uint32_t rrdcalc_flags; // check RRDCALC_FLAG_*
87 +
88 + time_t last_updated; // the last update timestamp of the alarm
89 + time_t next_update; // the next update timestamp of the alarm
90 + time_t last_status_change; // the timestamp of the last time this alarm changed status
91 +
92 + time_t db_after; // the first timestamp evaluated by the db lookup
93 + time_t db_before; // the last timestamp evaluated by the db lookup
94 +
95 + time_t delay_up_to_timestamp; // the timestamp up to which we should delay notifications
96 + int delay_up_current; // the current up notification delay duration
97 + int delay_down_current; // the current down notification delay duration
98 + int delay_last; // the last delay we used
99 +
100 + // ------------------------------------------------------------------------
101 + // variables this alarm exposes to the rest of the alarms
102 +
103 + RRDVAR *local;
104 + RRDVAR *family;
105 + RRDVAR *hostid;
106 + RRDVAR *hostname;
107 +
108 + // ------------------------------------------------------------------------
109 + // the chart this alarm it is linked to
110 +
111 + struct rrdset *rrdset;
112 +
113 + // linking of this alarm on its chart
114 + struct rrdcalc *rrdset_next;
115 + struct rrdcalc *rrdset_prev;
116 +
117 + struct rrdcalc *next;
118 +};
119 +
120 +#define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
121 +
122 +extern void rrdsetcalc_link_matching(RRDSET *st);
123 +extern void rrdsetcalc_unlink(RRDCALC *rc);
124 +extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
125 +
126 +extern const char *rrdcalc_status2string(RRDCALC_STATUS status);
127 +
128 +extern void rrdcalc_free(RRDCALC *rc);
129 +extern void rrdcalc_unlink_and_free(RRDHOST *host, RRDCALC *rc);
130 +
131 +extern int rrdcalc_exists(RRDHOST *host, const char *chart, const char *name, uint32_t hash_chart, uint32_t hash_name);
132 +extern uint32_t rrdcalc_get_unique_id(RRDHOST *host, const char *chart, const char *name, uint32_t *next_event_id);
133 +extern RRDCALC *rrdcalc_create(RRDHOST *host, RRDCALCTEMPLATE *rt, const char *chart);
134 +extern void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc);
135 +
136 +#endif //NETDATA_RRDCALC_H
src/database/rrdcalctemplate.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDCALCTEMPLATE management
src/database/rrdcalctemplate.h new
+68
@@ -0,0 +1,68 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_RRDCALCTEMPLATE_H
4 +#define NETDATA_RRDCALCTEMPLATE_H 1
5 +
6 +#include "rrd.h"
7 +
8 +// RRDCALCTEMPLATE
9 +// these are to be applied to charts found dynamically
10 +// based on their context.
11 +struct rrdcalctemplate {
12 + char *name;
13 + uint32_t hash_name;
14 +
15 + char *exec;
16 + char *recipient;
17 +
18 + char *context;
19 + uint32_t hash_context;
20 +
21 + char *family_match;
22 + SIMPLE_PATTERN *family_pattern;
23 +
24 + char *source; // the source of this alarm
25 + char *units; // the units of the alarm
26 + char *info; // a short description of the alarm
27 +
28 + int update_every; // update frequency for the alarm
29 +
30 + // the red and green threshold of this alarm (to be set to the chart)
31 + calculated_number green;
32 + calculated_number red;
33 +
34 + // ------------------------------------------------------------------------
35 + // database lookup settings
36 +
37 + char *dimensions; // the chart dimensions
38 + int group; // grouping method: average, max, etc.
39 + int before; // ending point in time-series
40 + int after; // starting point in time-series
41 + uint32_t options; // calculation options
42 +
43 + // ------------------------------------------------------------------------
44 + // notification delay settings
45 +
46 + int delay_up_duration; // duration to delay notifications when alarm raises
47 + int delay_down_duration; // duration to delay notifications when alarm lowers
48 + int delay_max_duration; // the absolute max delay to apply to this alarm
49 + float delay_multiplier; // multiplier for all delays when alarms switch status
50 +
51 + // ------------------------------------------------------------------------
52 + // expressions related to the alarm
53 +
54 + EVAL_EXPRESSION *calculation;
55 + EVAL_EXPRESSION *warning;
56 + EVAL_EXPRESSION *critical;
57 +
58 + struct rrdcalctemplate *next;
59 +};
60 +
61 +#define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
62 +
63 +extern void rrdcalctemplate_link_matching(RRDSET *st);
64 +
65 +extern void rrdcalctemplate_free(RRDCALCTEMPLATE *rt);
66 +extern void rrdcalctemplate_unlink_and_free(RRDHOST *host, RRDCALCTEMPLATE *rt);
67 +
68 +#endif //NETDATA_RRDCALCTEMPLATE_H
src/database/rrddim.c renamed
+2 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#define NETDATA_RRD_INTERNALS 1
4 -#include "common.h"
3 +#define NETDATA_RRD_INTERNALS
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDDIM index
src/database/rrddimvar.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDDIMVAR management
src/database/rrddimvar.h new
+56
@@ -0,0 +1,56 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_RRDDIMVAR_H
4 +#define NETDATA_RRDDIMVAR_H 1
5 +
6 +#include "rrd.h"
7 +
8 +// variables linked to individual dimensions
9 +// We link variables to point the values that are already
10 +// calculated / processed by the normal data collection process
11 +// This means, there will be no speed penalty for using
12 +// these variables
13 +struct rrddimvar {
14 + char *prefix;
15 + char *suffix;
16 +
17 + char *key_id; // dimension id
18 + char *key_name; // dimension name
19 + char *key_contextid; // context + dimension id
20 + char *key_contextname; // context + dimension name
21 + char *key_fullidid; // chart type.chart id + dimension id
22 + char *key_fullidname; // chart type.chart id + dimension name
23 + char *key_fullnameid; // chart type.chart name + dimension id
24 + char *key_fullnamename; // chart type.chart name + dimension name
25 +
26 + RRDVAR_TYPE type;
27 + void *value;
28 +
29 + RRDVAR_OPTIONS options;
30 +
31 + RRDVAR *var_local_id;
32 + RRDVAR *var_local_name;
33 +
34 + RRDVAR *var_family_id;
35 + RRDVAR *var_family_name;
36 + RRDVAR *var_family_contextid;
37 + RRDVAR *var_family_contextname;
38 +
39 + RRDVAR *var_host_chartidid;
40 + RRDVAR *var_host_chartidname;
41 + RRDVAR *var_host_chartnameid;
42 + RRDVAR *var_host_chartnamename;
43 +
44 + struct rrddim *rrddim;
45 +
46 + struct rrddimvar *next;
47 +};
48 +
49 +
50 +extern void rrddimvar_rename_all(RRDDIM *rd);
51 +extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options);
52 +extern void rrddimvar_free(RRDDIMVAR *rs);
53 +
54 +
55 +
56 +#endif //NETDATA_RRDDIMVAR_H
src/database/rrdfamily.c renamed
+2 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#define NETDATA_RRD_INTERNALS 1
4 -#include "common.h"
3 +#define NETDATA_RRD_INTERNALS
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDFAMILY index
src/database/rrdhost.c renamed
+2 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#define NETDATA_RRD_INTERNALS 1
4 -#include "common.h"
3 +#define NETDATA_RRD_INTERNALS
4 +#include "rrd.h"
5
6 RRDHOST *localhost = NULL;
7 size_t rrd_hosts_available = 0;
src/database/rrdset.c renamed
+2 -2
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#define NETDATA_RRD_INTERNALS 1
4 -#include "common.h"
3 +#define NETDATA_RRD_INTERNALS
4 +#include "rrd.h"
5
6 void __rrdset_check_rdlock(RRDSET *st, const char *file, const char *function, const unsigned long line) {
7 debug(D_RRD_CALLS, "Checking read lock on chart '%s'", st->id);
src/database/rrdsetvar.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDSETVAR management
src/database/rrdsetvar.h new
+44
@@ -0,0 +1,44 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_RRDSETVAR_H
4 +#define NETDATA_RRDSETVAR_H 1
5 +
6 +#include "rrd.h"
7 +
8 +// variables linked to charts
9 +// We link variables to point to the values that are already
10 +// calculated / processed by the normal data collection process
11 +// This means, there will be no speed penalty for using
12 +// these variables
13 +
14 +struct rrdsetvar {
15 + char *variable; // variable name
16 + uint32_t hash; // variable name hash
17 +
18 + char *key_fullid; // chart type.chart id.variable
19 + char *key_fullname; // chart type.chart name.variable
20 +
21 + RRDVAR_TYPE type;
22 + void *value;
23 +
24 + RRDVAR_OPTIONS options;
25 +
26 + RRDVAR *var_local;
27 + RRDVAR *var_family;
28 + RRDVAR *var_host;
29 + RRDVAR *var_family_name;
30 + RRDVAR *var_host_name;
31 +
32 + struct rrdset *rrdset;
33 +
34 + struct rrdsetvar *next;
35 +};
36 +
37 +extern RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name);
38 +extern void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rv, calculated_number value);
39 +
40 +extern void rrdsetvar_rename_all(RRDSET *st);
41 +extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, RRDVAR_TYPE type, void *value, RRDVAR_OPTIONS options);
42 +extern void rrdsetvar_free(RRDSETVAR *rs);
43 +
44 +#endif //NETDATA_RRDSETVAR_H
src/database/rrdvar.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "rrd.h"
5
6 // ----------------------------------------------------------------------------
7 // RRDVAR management
src/database/rrdvar.h new
+64
@@ -0,0 +1,64 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_RRDVAR_H
4 +#define NETDATA_RRDVAR_H 1
5 +
6 +#include "rrd.h"
7 +
8 +extern int rrdvar_compare(void *a, void *b);
9 +
10 +typedef enum rrdvar_type {
11 + RRDVAR_TYPE_CALCULATED = 1,
12 + RRDVAR_TYPE_TIME_T = 2,
13 + RRDVAR_TYPE_COLLECTED = 3,
14 + RRDVAR_TYPE_TOTAL = 4,
15 + RRDVAR_TYPE_INT = 5
16 +} RRDVAR_TYPE;
17 +
18 +typedef enum rrdvar_options {
19 + RRDVAR_OPTION_DEFAULT = 0,
20 + RRDVAR_OPTION_ALLOCATED = (1 << 0), // the value ptr is allocated (not a reference)
21 + RRDVAR_OPTION_CUSTOM_HOST_VAR = (1 << 1), // this is a custom host variable, not associated with a dimension
22 + RRDVAR_OPTION_CUSTOM_CHART_VAR = (1 << 2), // this is a custom chart variable, not associated with a dimension
23 + RRDVAR_OPTION_RRDCALC_LOCAL_VAR = (1 << 3), // this is a an alarm variable, attached to a chart
24 + RRDVAR_OPTION_RRDCALC_FAMILY_VAR = (1 << 4), // this is a an alarm variable, attached to a family
25 + RRDVAR_OPTION_RRDCALC_HOST_CHARTID_VAR = (1 << 5), // this is a an alarm variable, attached to the host, using the chart id
26 + RRDVAR_OPTION_RRDCALC_HOST_CHARTNAME_VAR = (1 << 6), // this is a an alarm variable, attached to the host, using the chart name
27 +} RRDVAR_OPTIONS;
28 +
29 +// the variables as stored in the variables indexes
30 +// there are 3 indexes:
31 +// 1. at each chart (RRDSET.rrdvar_root_index)
32 +// 2. at each context (RRDFAMILY.rrdvar_root_index)
33 +// 3. at each host (RRDHOST.rrdvar_root_index)
34 +struct rrdvar {
35 + avl avl;
36 +
37 + char *name;
38 + uint32_t hash;
39 +
40 + RRDVAR_TYPE type;
41 + RRDVAR_OPTIONS options;
42 +
43 + void *value;
44 +
45 + time_t last_updated;
46 +};
47 +
48 +extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name);
49 +extern void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, calculated_number value);
50 +extern int foreach_host_variable_callback(RRDHOST *host, int (*callback)(RRDVAR *rv, void *data), void *data);
51 +extern void rrdvar_free_remaining_variables(RRDHOST *host, avl_tree_lock *tree_lock);
52 +
53 +extern int rrdvar_callback_for_all_host_variables(RRDHOST *host, int (*callback)(void *rrdvar, void *data), void *data);
54 +
55 +extern calculated_number rrdvar2number(RRDVAR *rv);
56 +
57 +#define RRDVAR_MAX_LENGTH 1024
58 +
59 +extern int rrdvar_fix_name(char *variable);
60 +
61 +extern RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, RRDVAR_OPTIONS options, void *value);
62 +extern void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv);
63 +
64 +#endif //NETDATA_RRDVAR_H
src/global_statistics.h
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_GLOBAL_STATISTICS_H
4 #define NETDATA_GLOBAL_STATISTICS_H 1
5
6 +#include "common.h"
7 +
8 // ----------------------------------------------------------------------------
9 // global statistics
10
src/health.h deleted
-451
@@ -1,451 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#include "common.h"
4 -
5 -#ifndef NETDATA_HEALTH_H
6 -#define NETDATA_HEALTH_H 1
7 -
8 -extern unsigned int default_health_enabled;
9 -
10 -extern int rrdvar_compare(void *a, void *b);
11 -
12 -typedef enum rrdvar_type {
13 - RRDVAR_TYPE_CALCULATED = 1,
14 - RRDVAR_TYPE_TIME_T = 2,
15 - RRDVAR_TYPE_COLLECTED = 3,
16 - RRDVAR_TYPE_TOTAL = 4,
17 - RRDVAR_TYPE_INT = 5
18 -} RRDVAR_TYPE;
19 -
20 -typedef enum rrdvar_options {
21 - RRDVAR_OPTION_DEFAULT = 0,
22 - RRDVAR_OPTION_ALLOCATED = (1 << 0), // the value ptr is allocated (not a reference)
23 - RRDVAR_OPTION_CUSTOM_HOST_VAR = (1 << 1), // this is a custom host variable, not associated with a dimension
24 - RRDVAR_OPTION_CUSTOM_CHART_VAR = (1 << 2), // this is a custom chart variable, not associated with a dimension
25 - RRDVAR_OPTION_RRDCALC_LOCAL_VAR = (1 << 3), // this is a an alarm variable, attached to a chart
26 - RRDVAR_OPTION_RRDCALC_FAMILY_VAR = (1 << 4), // this is a an alarm variable, attached to a family
27 - RRDVAR_OPTION_RRDCALC_HOST_CHARTID_VAR = (1 << 5), // this is a an alarm variable, attached to the host, using the chart id
28 - RRDVAR_OPTION_RRDCALC_HOST_CHARTNAME_VAR = (1 << 6), // this is a an alarm variable, attached to the host, using the chart name
29 -} RRDVAR_OPTIONS;
30 -
31 -// the variables as stored in the variables indexes
32 -// there are 3 indexes:
33 -// 1. at each chart (RRDSET.rrdvar_root_index)
34 -// 2. at each context (RRDFAMILY.rrdvar_root_index)
35 -// 3. at each host (RRDHOST.rrdvar_root_index)
36 -typedef struct rrdvar {
37 - avl avl;
38 -
39 - char *name;
40 - uint32_t hash;
41 -
42 - RRDVAR_TYPE type;
43 - RRDVAR_OPTIONS options;
44 -
45 - void *value;
46 -
47 - time_t last_updated;
48 -} RRDVAR;
49 -
50 -// variables linked to charts
51 -// We link variables to point to the values that are already
52 -// calculated / processed by the normal data collection process
53 -// This means, there will be no speed penalty for using
54 -// these variables
55 -
56 -typedef struct rrdsetvar {
57 - char *variable; // variable name
58 - uint32_t hash; // variable name hash
59 -
60 - char *key_fullid; // chart type.chart id.variable
61 - char *key_fullname; // chart type.chart name.variable
62 -
63 - RRDVAR_TYPE type;
64 - void *value;
65 -
66 - RRDVAR_OPTIONS options;
67 -
68 - RRDVAR *var_local;
69 - RRDVAR *var_family;
70 - RRDVAR *var_host;
71 - RRDVAR *var_family_name;
72 - RRDVAR *var_host_name;
73 -
74 - struct rrdset *rrdset;
75 -
76 - struct rrdsetvar *next;
77 -} RRDSETVAR;
78 -
79 -
80 -// variables linked to individual dimensions
81 -// We link variables to point the values that are already
82 -// calculated / processed by the normal data collection process
83 -// This means, there will be no speed penalty for using
84 -// these variables
85 -typedef struct rrddimvar {
86 - char *prefix;
87 - char *suffix;
88 -
89 - char *key_id; // dimension id
90 - char *key_name; // dimension name
91 - char *key_contextid; // context + dimension id
92 - char *key_contextname; // context + dimension name
93 - char *key_fullidid; // chart type.chart id + dimension id
94 - char *key_fullidname; // chart type.chart id + dimension name
95 - char *key_fullnameid; // chart type.chart name + dimension id
96 - char *key_fullnamename; // chart type.chart name + dimension name
97 -
98 - RRDVAR_TYPE type;
99 - void *value;
100 -
101 - RRDVAR_OPTIONS options;
102 -
103 - RRDVAR *var_local_id;
104 - RRDVAR *var_local_name;
105 -
106 - RRDVAR *var_family_id;
107 - RRDVAR *var_family_name;
108 - RRDVAR *var_family_contextid;
109 - RRDVAR *var_family_contextname;
110 -
111 - RRDVAR *var_host_chartidid;
112 - RRDVAR *var_host_chartidname;
113 - RRDVAR *var_host_chartnameid;
114 - RRDVAR *var_host_chartnamename;
115 -
116 - struct rrddim *rrddim;
117 -
118 - struct rrddimvar *next;
119 -} RRDDIMVAR;
120 -
121 -// calculated variables (defined in health configuration)
122 -// These aggregate time-series data at fixed intervals
123 -// (defined in their update_every member below)
124 -// They increase the overhead of netdata.
125 -//
126 -// These calculations are allocated and linked (->next)
127 -// under RRDHOST.
128 -// Then are also linked to RRDSET (of course only when the
129 -// chart is found, via ->rrdset_next and ->rrdset_prev).
130 -// This double-linked list is maintained sorted at all times
131 -// having as RRDSET.calculations the RRDCALC to be processed
132 -// next.
133 -
134 -#define RRDCALC_FLAG_DB_ERROR 0x00000001
135 -#define RRDCALC_FLAG_DB_NAN 0x00000002
136 -/* #define RRDCALC_FLAG_DB_STALE 0x00000004 */
137 -#define RRDCALC_FLAG_CALC_ERROR 0x00000008
138 -#define RRDCALC_FLAG_WARN_ERROR 0x00000010
139 -#define RRDCALC_FLAG_CRIT_ERROR 0x00000020
140 -#define RRDCALC_FLAG_RUNNABLE 0x00000040
141 -#define RRDCALC_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
142 -
143 -typedef struct rrdcalc {
144 - uint32_t id; // the unique id of this alarm
145 - uint32_t next_event_id; // the next event id that will be used for this alarm
146 -
147 - char *name; // the name of this alarm
148 - uint32_t hash;
149 -
150 - char *exec; // the command to execute when this alarm switches state
151 - char *recipient; // the recipient of the alarm (the first parameter to exec)
152 -
153 - char *chart; // the chart id this should be linked to
154 - uint32_t hash_chart;
155 -
156 - char *source; // the source of this alarm
157 - char *units; // the units of the alarm
158 - char *info; // a short description of the alarm
159 -
160 - int update_every; // update frequency for the alarm
161 -
162 - // the red and green threshold of this alarm (to be set to the chart)
163 - calculated_number green;
164 - calculated_number red;
165 -
166 - // ------------------------------------------------------------------------
167 - // database lookup settings
168 -
169 - char *dimensions; // the chart dimensions
170 - int group; // grouping method: average, max, etc.
171 - int before; // ending point in time-series
172 - int after; // starting point in time-series
173 - uint32_t options; // calculation options
174 -
175 - // ------------------------------------------------------------------------
176 - // expressions related to the alarm
177 -
178 - EVAL_EXPRESSION *calculation; // expression to calculate the value of the alarm
179 - EVAL_EXPRESSION *warning; // expression to check the warning condition
180 - EVAL_EXPRESSION *critical; // expression to check the critical condition
181 -
182 - // ------------------------------------------------------------------------
183 - // notification delay settings
184 -
185 - int delay_up_duration; // duration to delay notifications when alarm raises
186 - int delay_down_duration; // duration to delay notifications when alarm lowers
187 - int delay_max_duration; // the absolute max delay to apply to this alarm
188 - float delay_multiplier; // multiplier for all delays when alarms switch status
189 - // while now < delay_up_to
190 -
191 - // ------------------------------------------------------------------------
192 - // runtime information
193 -
194 - RRDCALC_STATUS status; // the current status of the alarm
195 -
196 - calculated_number value; // the current value of the alarm
197 - calculated_number old_value; // the previous value of the alarm
198 -
199 - uint32_t rrdcalc_flags; // check RRDCALC_FLAG_*
200 -
201 - time_t last_updated; // the last update timestamp of the alarm
202 - time_t next_update; // the next update timestamp of the alarm
203 - time_t last_status_change; // the timestamp of the last time this alarm changed status
204 -
205 - time_t db_after; // the first timestamp evaluated by the db lookup
206 - time_t db_before; // the last timestamp evaluated by the db lookup
207 -
208 - time_t delay_up_to_timestamp; // the timestamp up to which we should delay notifications
209 - int delay_up_current; // the current up notification delay duration
210 - int delay_down_current; // the current down notification delay duration
211 - int delay_last; // the last delay we used
212 -
213 - // ------------------------------------------------------------------------
214 - // variables this alarm exposes to the rest of the alarms
215 -
216 - RRDVAR *local;
217 - RRDVAR *family;
218 - RRDVAR *hostid;
219 - RRDVAR *hostname;
220 -
221 - // ------------------------------------------------------------------------
222 - // the chart this alarm it is linked to
223 -
224 - struct rrdset *rrdset;
225 -
226 - // linking of this alarm on its chart
227 - struct rrdcalc *rrdset_next;
228 - struct rrdcalc *rrdset_prev;
229 -
230 - struct rrdcalc *next;
231 -} RRDCALC;
232 -
233 -#define RRDCALC_HAS_DB_LOOKUP(rc) ((rc)->after)
234 -
235 -// RRDCALCTEMPLATE
236 -// these are to be applied to charts found dynamically
237 -// based on their context.
238 -typedef struct rrdcalctemplate {
239 - char *name;
240 - uint32_t hash_name;
241 -
242 - char *exec;
243 - char *recipient;
244 -
245 - char *context;
246 - uint32_t hash_context;
247 -
248 - char *family_match;
249 - SIMPLE_PATTERN *family_pattern;
250 -
251 - char *source; // the source of this alarm
252 - char *units; // the units of the alarm
253 - char *info; // a short description of the alarm
254 -
255 - int update_every; // update frequency for the alarm
256 -
257 - // the red and green threshold of this alarm (to be set to the chart)
258 - calculated_number green;
259 - calculated_number red;
260 -
261 - // ------------------------------------------------------------------------
262 - // database lookup settings
263 -
264 - char *dimensions; // the chart dimensions
265 - int group; // grouping method: average, max, etc.
266 - int before; // ending point in time-series
267 - int after; // starting point in time-series
268 - uint32_t options; // calculation options
269 -
270 - // ------------------------------------------------------------------------
271 - // notification delay settings
272 -
273 - int delay_up_duration; // duration to delay notifications when alarm raises
274 - int delay_down_duration; // duration to delay notifications when alarm lowers
275 - int delay_max_duration; // the absolute max delay to apply to this alarm
276 - float delay_multiplier; // multiplier for all delays when alarms switch status
277 -
278 - // ------------------------------------------------------------------------
279 - // expressions related to the alarm
280 -
281 - EVAL_EXPRESSION *calculation;
282 - EVAL_EXPRESSION *warning;
283 - EVAL_EXPRESSION *critical;
284 -
285 - struct rrdcalctemplate *next;
286 -} RRDCALCTEMPLATE;
287 -
288 -#define RRDCALCTEMPLATE_HAS_CALCULATION(rt) ((rt)->after)
289 -
290 -#define HEALTH_ENTRY_FLAG_PROCESSED 0x00000001
291 -#define HEALTH_ENTRY_FLAG_UPDATED 0x00000002
292 -#define HEALTH_ENTRY_FLAG_EXEC_RUN 0x00000004
293 -#define HEALTH_ENTRY_FLAG_EXEC_FAILED 0x00000008
294 -#define HEALTH_ENTRY_FLAG_SAVED 0x10000000
295 -#define HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
296 -
297 -typedef struct alarm_entry {
298 - uint32_t unique_id;
299 - uint32_t alarm_id;
300 - uint32_t alarm_event_id;
301 -
302 - time_t when;
303 - time_t duration;
304 - time_t non_clear_duration;
305 -
306 - char *name;
307 - uint32_t hash_name;
308 -
309 - char *chart;
310 - uint32_t hash_chart;
311 -
312 - char *family;
313 -
314 - char *exec;
315 - char *recipient;
316 - time_t exec_run_timestamp;
317 - int exec_code;
318 -
319 - char *source;
320 - char *units;
321 - char *info;
322 -
323 - calculated_number old_value;
324 - calculated_number new_value;
325 -
326 - char *old_value_string;
327 - char *new_value_string;
328 -
329 - RRDCALC_STATUS old_status;
330 - RRDCALC_STATUS new_status;
331 -
332 - uint32_t flags;
333 -
334 - int delay;
335 - time_t delay_up_to_timestamp;
336 -
337 - uint32_t updated_by_id;
338 - uint32_t updates_id;
339 -
340 - struct alarm_entry *next;
341 -} ALARM_ENTRY;
342 -
343 -typedef struct alarm_log {
344 - uint32_t next_log_id;
345 - uint32_t next_alarm_id;
346 - unsigned int count;
347 - unsigned int max;
348 - ALARM_ENTRY *alarms;
349 - netdata_rwlock_t alarm_log_rwlock;
350 -} ALARM_LOG;
351 -
352 -#include "rrd.h"
353 -
354 -extern calculated_number rrdvar2number(RRDVAR *rv);
355 -
356 -extern void rrdsetvar_rename_all(RRDSET *st);
357 -extern RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, RRDVAR_TYPE type, void *value, RRDVAR_OPTIONS options);
358 -extern void rrdsetvar_free(RRDSETVAR *rs);
359 -
360 -extern void rrddimvar_rename_all(RRDDIM *rd);
361 -extern RRDDIMVAR *rrddimvar_create(RRDDIM *rd, RRDVAR_TYPE type, const char *prefix, const char *suffix, void *value, RRDVAR_OPTIONS options);
362 -extern void rrddimvar_free(RRDDIMVAR *rs);
363 -
364 -extern void rrdsetcalc_link_matching(RRDSET *st);
365 -extern void rrdsetcalc_unlink(RRDCALC *rc);
366 -extern void rrdcalctemplate_link_matching(RRDSET *st);
367 -extern RRDCALC *rrdcalc_find(RRDSET *st, const char *name);
368 -
369 -extern void health_init(void);
370 -extern void *health_main(void *ptr);
371 -
372 -extern void health_reload(void);
373 -
374 -extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
375 -extern void health_alarms2json(RRDHOST *host, BUFFER *wb, int all);
376 -extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after);
377 -
378 -void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf);
379 -
380 -extern RRDVAR *rrdvar_custom_host_variable_create(RRDHOST *host, const char *name);
381 -extern void rrdvar_custom_host_variable_set(RRDHOST *host, RRDVAR *rv, calculated_number value);
382 -extern int foreach_host_variable_callback(RRDHOST *host, int (*callback)(RRDVAR *rv, void *data), void *data);
383 -
384 -extern RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name);
385 -extern void rrdsetvar_custom_chart_variable_set(RRDSETVAR *rv, calculated_number value);
386 -
387 -extern void rrdvar_free_remaining_variables(RRDHOST *host, avl_tree_lock *tree_lock);
388 -
389 -extern const char *rrdcalc_status2string(RRDCALC_STATUS status);
390 -
391 -
392 -extern int health_alarm_log_open(RRDHOST *host);
393 -extern void health_alarm_log_close(RRDHOST *host);
394 -extern void health_log_rotate(RRDHOST *host);
395 -extern void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
396 -extern ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filename);
397 -extern void health_alarm_log_load(RRDHOST *host);
398 -extern void health_alarm_log(
399 - RRDHOST *host,
400 - uint32_t alarm_id,
401 - uint32_t alarm_event_id,
402 - time_t when,
403 - const char *name,
404 - const char *chart,
405 - const char *family,
406 - const char *exec,
407 - const char *recipient,
408 - time_t duration,
409 - calculated_number old_value,
410 - calculated_number new_value,
411 - RRDCALC_STATUS old_status,
412 - RRDCALC_STATUS new_status,
413 - const char *source,
414 - const char *units,
415 - const char *info,
416 - int delay,
417 - uint32_t flags
418 -);
419 -
420 -extern void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath);
421 -extern char *health_user_config_dir(void);
422 -extern char *health_stock_config_dir(void);
423 -extern void health_reload_host(RRDHOST *host);
424 -extern void health_alarm_log_free(RRDHOST *host);
425 -
426 -extern void rrdcalc_free(RRDCALC *rc);
427 -extern void rrdcalc_unlink_and_free(RRDHOST *host, RRDCALC *rc);
428 -
429 -extern void rrdcalctemplate_free(RRDCALCTEMPLATE *rt);
430 -extern void rrdcalctemplate_unlink_and_free(RRDHOST *host, RRDCALCTEMPLATE *rt);
431 -
432 -extern int rrdvar_callback_for_all_host_variables(RRDHOST *host, int (*callback)(void *rrdvar, void *data), void *data);
433 -
434 -#ifdef NETDATA_HEALTH_INTERNALS
435 -#define RRDVAR_MAX_LENGTH 1024
436 -
437 -extern int rrdcalc_exists(RRDHOST *host, const char *chart, const char *name, uint32_t hash_chart, uint32_t hash_name);
438 -extern uint32_t rrdcalc_get_unique_id(RRDHOST *host, const char *chart, const char *name, uint32_t *next_event_id);
439 -extern int rrdvar_fix_name(char *variable);
440 -
441 -extern RRDCALC *rrdcalc_create(RRDHOST *host, RRDCALCTEMPLATE *rt, const char *chart);
442 -extern void rrdcalc_create_part2(RRDHOST *host, RRDCALC *rc);
443 -
444 -extern RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *tree, const char *name, RRDVAR_TYPE type, RRDVAR_OPTIONS options, void *value);
445 -extern void rrdvar_free(RRDHOST *host, avl_tree_lock *tree, RRDVAR *rv);
446 -
447 -extern void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae);
448 -
449 -#endif // NETDATA_HEALTH_INTERNALS
450 -
451 -#endif //NETDATA_HEALTH_H
src/health/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/health/health.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "health.h"
5
6 unsigned int default_health_enabled = 1;
7
src/health/health.h new
+76
@@ -0,0 +1,76 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_HEALTH_H
4 +#define NETDATA_HEALTH_H 1
5 +
6 +#include "src/common.h"
7 +
8 +#define NETDATA_PLUGIN_HOOK_HEALTH \
9 + { \
10 + .name = "HEALTH", \
11 + .config_section = NULL, \
12 + .config_name = NULL, \
13 + .enabled = 1, \
14 + .thread = NULL, \
15 + .init_routine = NULL, \
16 + .start_routine = health_main \
17 + },
18 +
19 +extern unsigned int default_health_enabled;
20 +
21 +#define HEALTH_ENTRY_FLAG_PROCESSED 0x00000001
22 +#define HEALTH_ENTRY_FLAG_UPDATED 0x00000002
23 +#define HEALTH_ENTRY_FLAG_EXEC_RUN 0x00000004
24 +#define HEALTH_ENTRY_FLAG_EXEC_FAILED 0x00000008
25 +#define HEALTH_ENTRY_FLAG_SAVED 0x10000000
26 +#define HEALTH_ENTRY_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
27 +
28 +extern void health_init(void);
29 +extern void *health_main(void *ptr);
30 +
31 +extern void health_reload(void);
32 +
33 +extern int health_variable_lookup(const char *variable, uint32_t hash, RRDCALC *rc, calculated_number *result);
34 +extern void health_alarms2json(RRDHOST *host, BUFFER *wb, int all);
35 +extern void health_alarm_log2json(RRDHOST *host, BUFFER *wb, uint32_t after);
36 +
37 +void health_api_v1_chart_variables2json(RRDSET *st, BUFFER *buf);
38 +
39 +extern int health_alarm_log_open(RRDHOST *host);
40 +extern void health_alarm_log_close(RRDHOST *host);
41 +extern void health_log_rotate(RRDHOST *host);
42 +extern void health_alarm_log_save(RRDHOST *host, ALARM_ENTRY *ae);
43 +extern ssize_t health_alarm_log_read(RRDHOST *host, FILE *fp, const char *filename);
44 +extern void health_alarm_log_load(RRDHOST *host);
45 +
46 +extern void health_alarm_log(
47 + RRDHOST *host,
48 + uint32_t alarm_id,
49 + uint32_t alarm_event_id,
50 + time_t when,
51 + const char *name,
52 + const char *chart,
53 + const char *family,
54 + const char *exec,
55 + const char *recipient,
56 + time_t duration,
57 + calculated_number old_value,
58 + calculated_number new_value,
59 + RRDCALC_STATUS old_status,
60 + RRDCALC_STATUS new_status,
61 + const char *source,
62 + const char *units,
63 + const char *info,
64 + int delay,
65 + uint32_t flags
66 +);
67 +
68 +extern void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath);
69 +extern char *health_user_config_dir(void);
70 +extern char *health_stock_config_dir(void);
71 +extern void health_reload_host(RRDHOST *host);
72 +extern void health_alarm_log_free(RRDHOST *host);
73 +
74 +extern void health_alarm_log_free_one_nochecks_nounlink(ALARM_ENTRY *ae);
75 +
76 +#endif //NETDATA_HEALTH_H
src/health/health_config.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "health.h"
5
6 #define HEALTH_CONF_MAX_LINE 4096
7
src/health/health_json.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "health.h"
5
6 static inline void health_string2json(BUFFER *wb, const char *prefix, const char *label, const char *value, const char *suffix) {
7 if(value && *value) {
src/health/health_log.c renamed
+1 -1
@@ -1,7 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #define NETDATA_HEALTH_INTERNALS
4 -#include "common.h"
4 +#include "health.h"
5
6 // ----------------------------------------------------------------------------
7 // health alarm log load/save
src/ipc.h deleted
-9
@@ -1,9 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_IPC_H
4 -#define NETDATA_PLUGIN_IPC_H 1
5 -
6 -extern int do_ipc(int update_every, usec_t dt);
7 -
8 -#endif /* NETDATA_PLUGIN_IPC_H */
9 -
src/libnetdata/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +MAINTAINERCLEANFILES = Makefile.in
4 +
5 +
src/libnetdata/adaptive_resortable_list.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // the default processor() of the ARL
6 // can be overwritten at arl_create()
src/libnetdata/adaptive_resortable_list.h renamed
+2
@@ -1,5 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +#include "libnetdata.h"
4 +
5 #ifndef NETDATA_ADAPTIVE_RESORTABLE_LIST_H
6 #define NETDATA_ADAPTIVE_RESORTABLE_LIST_H 1
7
src/libnetdata/appconfig.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 #define CONFIG_FILE_LINE_MAX ((CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 1024) * 2)
6
src/libnetdata/appconfig.h renamed
+2 -2
@@ -75,11 +75,11 @@
75 * a method to allocate only the dynamic option names.
76 */
77
78 -#include "common.h"
79 -
78 #ifndef NETDATA_CONFIG_H
79 #define NETDATA_CONFIG_H 1
80
81 +#include "libnetdata.h"
82 +
83 #define CONFIG_FILENAME "netdata.conf"
84
85 #define CONFIG_SECTION_GLOBAL "global"
src/libnetdata/avl.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 /* ------------------------------------------------------------------------- */
6 /*
src/libnetdata/avl.h renamed
+3
@@ -3,6 +3,9 @@
3 #ifndef _AVL_H
4 #define _AVL_H 1
5
6 +#include "libnetdata.h"
7 +
8 +
9 /* Maximum AVL tree height. */
10 #ifndef AVL_MAX_HEIGHT
11 #define AVL_MAX_HEIGHT 92
src/libnetdata/clocks.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 #ifndef HAVE_CLOCK_GETTIME
6 inline int clock_gettime(clockid_t clk_id, struct timespec *ts) {
src/libnetdata/clocks.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_CLOCKS_H
4 #define NETDATA_CLOCKS_H 1
5
6 +#include "libnetdata.h"
7 +
8 #ifndef HAVE_STRUCT_TIMESPEC
9 struct timespec {
10 time_t tv_sec; /* seconds */
src/libnetdata/common.c new
+1503
@@ -0,0 +1,1503 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "libnetdata.h"
4 +
5 +#ifdef __APPLE__
6 +#define INHERIT_NONE 0
7 +#endif /* __APPLE__ */
8 +#if defined(__FreeBSD__) || defined(__APPLE__)
9 +# define O_NOATIME 0
10 +# define MADV_DONTFORK INHERIT_NONE
11 +#endif /* __FreeBSD__ || __APPLE__*/
12 +
13 +struct rlimit rlimit_nofile = { .rlim_cur = 1024, .rlim_max = 1024 };
14 +int enable_ksm = 1;
15 +
16 +volatile sig_atomic_t netdata_exit = 0;
17 +const char *os_type = NETDATA_OS_TYPE;
18 +const char *program_version = VERSION;
19 +
20 +// ----------------------------------------------------------------------------
21 +// memory allocation functions that handle failures
22 +
23 +// although netdata does not use memory allocations too often (netdata tries to
24 +// maintain its memory footprint stable during runtime, i.e. all buffers are
25 +// allocated during initialization and are adapted to current use throughout
26 +// its lifetime), these can be used to override the default system allocation
27 +// routines.
28 +
29 +#ifdef NETDATA_LOG_ALLOCATIONS
30 +static struct memory_statistics {
31 + volatile size_t malloc_calls_made;
32 + volatile size_t calloc_calls_made;
33 + volatile size_t realloc_calls_made;
34 + volatile size_t strdup_calls_made;
35 + volatile size_t free_calls_made;
36 + volatile size_t memory_calls_made;
37 + volatile size_t allocated_memory;
38 + volatile size_t mmapped_memory;
39 +} memory_statistics;
40 +
41 +static inline void print_allocations(const char *file, const char *function, const unsigned long line) {
42 + static struct memory_statistics old = { 0, 0, 0, 0, 0, 0, 0, 0 };
43 +
44 + //if(unlikely(!(memory_statistics.memory_calls_made % 5))) {
45 + fprintf(stderr, "(%04lu@%-10.10s:%-15.15s): Allocated %zu KB (+%zu B), mmapped %zu KB (+%zu B): malloc %zu (+%zu), calloc %zu (+%zu), realloc %zu (+%zu), strdup %zu (+%zu), free %zu (+%zu)\n",
46 + line, file, function,
47 + (memory_statistics.allocated_memory + 512) / 1024, memory_statistics.allocated_memory - old.allocated_memory,
48 + (memory_statistics.mmapped_memory + 512) / 1024, memory_statistics.mmapped_memory - old.mmapped_memory,
49 + memory_statistics.malloc_calls_made, memory_statistics.malloc_calls_made - old.malloc_calls_made,
50 + memory_statistics.calloc_calls_made, memory_statistics.calloc_calls_made - old.calloc_calls_made,
51 + memory_statistics.realloc_calls_made, memory_statistics.realloc_calls_made - old.realloc_calls_made,
52 + memory_statistics.strdup_calls_made, memory_statistics.strdup_calls_made - old.strdup_calls_made,
53 + memory_statistics.free_calls_made, memory_statistics.free_calls_made - old.free_calls_made
54 + );
55 +
56 + memcpy(&old, &memory_statistics, sizeof(struct memory_statistics));
57 + //}
58 +}
59 +
60 +static inline void malloc_accounting(const char *file, const char *function, const unsigned long line, size_t size) {
61 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
62 + __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
63 + __atomic_fetch_add(&memory_statistics.malloc_calls_made, 1, __ATOMIC_SEQ_CST);
64 + __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
65 +#else
66 + // this is for debugging - we don't care locking it
67 + memory_statistics.memory_calls_made++;
68 + memory_statistics.malloc_calls_made++;
69 + memory_statistics.allocated_memory += size;
70 +#endif
71 + print_allocations(file, function, line);
72 +}
73 +
74 +static inline void mmap_accounting(size_t size) {
75 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
76 + __atomic_fetch_add(&memory_statistics.malloc_calls_made, 1, __ATOMIC_SEQ_CST);
77 + __atomic_fetch_add(&memory_statistics.mmapped_memory, size, __ATOMIC_SEQ_CST);
78 +#else
79 + // this is for debugging - we don't care locking it
80 + memory_statistics.memory_calls_made++;
81 + memory_statistics.mmapped_memory += size;
82 +#endif
83 +}
84 +
85 +static inline void calloc_accounting(const char *file, const char *function, const unsigned long line, size_t size) {
86 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
87 + __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
88 + __atomic_fetch_add(&memory_statistics.calloc_calls_made, 1, __ATOMIC_SEQ_CST);
89 + __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
90 +#else
91 + // this is for debugging - we don't care locking it
92 + memory_statistics.memory_calls_made++;
93 + memory_statistics.calloc_calls_made++;
94 + memory_statistics.allocated_memory += size;
95 +#endif
96 + print_allocations(file, function, line);
97 +}
98 +
99 +static inline void realloc_accounting(const char *file, const char *function, const unsigned long line, void *ptr, size_t size) {
100 + (void)ptr;
101 +
102 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
103 + __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
104 + __atomic_fetch_add(&memory_statistics.realloc_calls_made, 1, __ATOMIC_SEQ_CST);
105 + __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
106 +#else
107 + // this is for debugging - we don't care locking it
108 + memory_statistics.memory_calls_made++;
109 + memory_statistics.realloc_calls_made++;
110 + memory_statistics.allocated_memory += size;
111 +#endif
112 + print_allocations(file, function, line);
113 +}
114 +
115 +static inline void strdup_accounting(const char *file, const char *function, const unsigned long line, const char *s) {
116 + size_t size = strlen(s) + 1;
117 +
118 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
119 + __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
120 + __atomic_fetch_add(&memory_statistics.strdup_calls_made, 1, __ATOMIC_SEQ_CST);
121 + __atomic_fetch_add(&memory_statistics.allocated_memory, size, __ATOMIC_SEQ_CST);
122 +#else
123 + // this is for debugging - we don't care locking it
124 + memory_statistics.memory_calls_made++;
125 + memory_statistics.strdup_calls_made++;
126 + memory_statistics.allocated_memory += size;
127 +#endif
128 + print_allocations(file, function, line);
129 +}
130 +
131 +static inline void free_accounting(const char *file, const char *function, const unsigned long line, void *ptr) {
132 + (void)file;
133 + (void)function;
134 + (void)line;
135 +
136 + if(likely(ptr)) {
137 +#if defined(HAVE_C___ATOMIC) && !defined(NETDATA_NO_ATOMIC_INSTRUCTIONS)
138 + __atomic_fetch_add(&memory_statistics.memory_calls_made, 1, __ATOMIC_SEQ_CST);
139 + __atomic_fetch_add(&memory_statistics.free_calls_made, 1, __ATOMIC_SEQ_CST);
140 +#else
141 + // this is for debugging - we don't care locking it
142 + memory_statistics.memory_calls_made++;
143 + memory_statistics.free_calls_made++;
144 +#endif
145 + }
146 +}
147 +#endif
148 +
149 +#ifdef NETDATA_LOG_ALLOCATIONS
150 +char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s) {
151 + strdup_accounting(file, function, line, s);
152 +#else
153 +char *strdupz(const char *s) {
154 +#endif
155 +
156 + char *t = strdup(s);
157 + if (unlikely(!t)) fatal("Cannot strdup() string '%s'", s);
158 + return t;
159 +}
160 +
161 +#ifdef NETDATA_LOG_ALLOCATIONS
162 +void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size) {
163 + malloc_accounting(file, function, line, size);
164 +#else
165 +void *mallocz(size_t size) {
166 +#endif
167 +
168 + void *p = malloc(size);
169 + if (unlikely(!p)) fatal("Cannot allocate %zu bytes of memory.", size);
170 + return p;
171 +}
172 +
173 +#ifdef NETDATA_LOG_ALLOCATIONS
174 +void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size) {
175 + calloc_accounting(file, function, line, nmemb * size);
176 +#else
177 +void *callocz(size_t nmemb, size_t size) {
178 +#endif
179 +
180 + void *p = calloc(nmemb, size);
181 + if (unlikely(!p)) fatal("Cannot allocate %zu bytes of memory.", nmemb * size);
182 + return p;
183 +}
184 +
185 +#ifdef NETDATA_LOG_ALLOCATIONS
186 +void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size) {
187 + realloc_accounting(file, function, line, ptr, size);
188 +#else
189 +void *reallocz(void *ptr, size_t size) {
190 +#endif
191 +
192 + void *p = realloc(ptr, size);
193 + if (unlikely(!p)) fatal("Cannot re-allocate memory to %zu bytes.", size);
194 + return p;
195 +}
196 +
197 +#ifdef NETDATA_LOG_ALLOCATIONS
198 +void freez_int(const char *file, const char *function, const unsigned long line, void *ptr) {
199 + free_accounting(file, function, line, ptr);
200 +#else
201 +void freez(void *ptr) {
202 +#endif
203 +
204 + free(ptr);
205 +}
206 +
207 +void json_escape_string(char *dst, const char *src, size_t size) {
208 + const char *t;
209 + char *d = dst, *e = &dst[size - 1];
210 +
211 + for(t = src; *t && d < e ;t++) {
212 + if(unlikely(*t == '\\' || *t == '"')) {
213 + if(unlikely(d + 1 >= e)) break;
214 + *d++ = '\\';
215 + }
216 + *d++ = *t;
217 + }
218 +
219 + *d = '\0';
220 +}
221 +
222 +void json_fix_string(char *s) {
223 + unsigned char c;
224 + while((c = (unsigned char)*s)) {
225 + if(unlikely(c == '\\'))
226 + *s++ = '/';
227 + else if(unlikely(c == '"'))
228 + *s++ = '\'';
229 + else if(unlikely(isspace(c) || iscntrl(c)))
230 + *s++ = ' ';
231 + else if(unlikely(!isprint(c) || c > 127))
232 + *s++ = '_';
233 + else
234 + s++;
235 + }
236 +}
237 +
238 +int sleep_usec(usec_t usec) {
239 +
240 +#ifndef NETDATA_WITH_USLEEP
241 + // we expect microseconds (1.000.000 per second)
242 + // but timespec is nanoseconds (1.000.000.000 per second)
243 + struct timespec rem, req = {
244 + .tv_sec = (time_t) (usec / 1000000),
245 + .tv_nsec = (suseconds_t) ((usec % 1000000) * 1000)
246 + };
247 +
248 + while (nanosleep(&req, &rem) == -1) {
249 + if (likely(errno == EINTR)) {
250 + debug(D_SYSTEM, "nanosleep() interrupted (while sleeping for %llu microseconds).", usec);
251 + req.tv_sec = rem.tv_sec;
252 + req.tv_nsec = rem.tv_nsec;
253 + } else {
254 + error("Cannot nanosleep() for %llu microseconds.", usec);
255 + break;
256 + }
257 + }
258 +
259 + return 0;
260 +#else
261 + int ret = usleep(usec);
262 + if(unlikely(ret == -1 && errno == EINVAL)) {
263 + // on certain systems, usec has to be up to 999999
264 + if(usec > 999999) {
265 + int counter = usec / 999999;
266 + while(counter--)
267 + usleep(999999);
268 +
269 + usleep(usec % 999999);
270 + }
271 + else {
272 + error("Cannot usleep() for %llu microseconds.", usec);
273 + return ret;
274 + }
275 + }
276 +
277 + if(ret != 0)
278 + error("usleep() failed for %llu microseconds.", usec);
279 +
280 + return ret;
281 +#endif
282 +}
283 +
284 +unsigned char netdata_map_chart_names[256] = {
285 + [0] = '\0', //
286 + [1] = '_', //
287 + [2] = '_', //
288 + [3] = '_', //
289 + [4] = '_', //
290 + [5] = '_', //
291 + [6] = '_', //
292 + [7] = '_', //
293 + [8] = '_', //
294 + [9] = '_', //
295 + [10] = '_', //
296 + [11] = '_', //
297 + [12] = '_', //
298 + [13] = '_', //
299 + [14] = '_', //
300 + [15] = '_', //
301 + [16] = '_', //
302 + [17] = '_', //
303 + [18] = '_', //
304 + [19] = '_', //
305 + [20] = '_', //
306 + [21] = '_', //
307 + [22] = '_', //
308 + [23] = '_', //
309 + [24] = '_', //
310 + [25] = '_', //
311 + [26] = '_', //
312 + [27] = '_', //
313 + [28] = '_', //
314 + [29] = '_', //
315 + [30] = '_', //
316 + [31] = '_', //
317 + [32] = '_', //
318 + [33] = '_', // !
319 + [34] = '_', // "
320 + [35] = '_', // #
321 + [36] = '_', // $
322 + [37] = '_', // %
323 + [38] = '_', // &
324 + [39] = '_', // '
325 + [40] = '_', // (
326 + [41] = '_', // )
327 + [42] = '_', // *
328 + [43] = '_', // +
329 + [44] = '.', // ,
330 + [45] = '-', // -
331 + [46] = '.', // .
332 + [47] = '/', // /
333 + [48] = '0', // 0
334 + [49] = '1', // 1
335 + [50] = '2', // 2
336 + [51] = '3', // 3
337 + [52] = '4', // 4
338 + [53] = '5', // 5
339 + [54] = '6', // 6
340 + [55] = '7', // 7
341 + [56] = '8', // 8
342 + [57] = '9', // 9
343 + [58] = '_', // :
344 + [59] = '_', // ;
345 + [60] = '_', // <
346 + [61] = '_', // =
347 + [62] = '_', // >
348 + [63] = '_', // ?
349 + [64] = '_', // @
350 + [65] = 'a', // A
351 + [66] = 'b', // B
352 + [67] = 'c', // C
353 + [68] = 'd', // D
354 + [69] = 'e', // E
355 + [70] = 'f', // F
356 + [71] = 'g', // G
357 + [72] = 'h', // H
358 + [73] = 'i', // I
359 + [74] = 'j', // J
360 + [75] = 'k', // K
361 + [76] = 'l', // L
362 + [77] = 'm', // M
363 + [78] = 'n', // N
364 + [79] = 'o', // O
365 + [80] = 'p', // P
366 + [81] = 'q', // Q
367 + [82] = 'r', // R
368 + [83] = 's', // S
369 + [84] = 't', // T
370 + [85] = 'u', // U
371 + [86] = 'v', // V
372 + [87] = 'w', // W
373 + [88] = 'x', // X
374 + [89] = 'y', // Y
375 + [90] = 'z', // Z
376 + [91] = '_', // [
377 + [92] = '/', // backslash
378 + [93] = '_', // ]
379 + [94] = '_', // ^
380 + [95] = '_', // _
381 + [96] = '_', // `
382 + [97] = 'a', // a
383 + [98] = 'b', // b
384 + [99] = 'c', // c
385 + [100] = 'd', // d
386 + [101] = 'e', // e
387 + [102] = 'f', // f
388 + [103] = 'g', // g
389 + [104] = 'h', // h
390 + [105] = 'i', // i
391 + [106] = 'j', // j
392 + [107] = 'k', // k
393 + [108] = 'l', // l
394 + [109] = 'm', // m
395 + [110] = 'n', // n
396 + [111] = 'o', // o
397 + [112] = 'p', // p
398 + [113] = 'q', // q
399 + [114] = 'r', // r
400 + [115] = 's', // s
401 + [116] = 't', // t
402 + [117] = 'u', // u
403 + [118] = 'v', // v
404 + [119] = 'w', // w
405 + [120] = 'x', // x
406 + [121] = 'y', // y
407 + [122] = 'z', // z
408 + [123] = '_', // {
409 + [124] = '_', // |
410 + [125] = '_', // }
411 + [126] = '_', // ~
412 + [127] = '_', //
413 + [128] = '_', //
414 + [129] = '_', //
415 + [130] = '_', //
416 + [131] = '_', //
417 + [132] = '_', //
418 + [133] = '_', //
419 + [134] = '_', //
420 + [135] = '_', //
421 + [136] = '_', //
422 + [137] = '_', //
423 + [138] = '_', //
424 + [139] = '_', //
425 + [140] = '_', //
426 + [141] = '_', //
427 + [142] = '_', //
428 + [143] = '_', //
429 + [144] = '_', //
430 + [145] = '_', //
431 + [146] = '_', //
432 + [147] = '_', //
433 + [148] = '_', //
434 + [149] = '_', //
435 + [150] = '_', //
436 + [151] = '_', //
437 + [152] = '_', //
438 + [153] = '_', //
439 + [154] = '_', //
440 + [155] = '_', //
441 + [156] = '_', //
442 + [157] = '_', //
443 + [158] = '_', //
444 + [159] = '_', //
445 + [160] = '_', //
446 + [161] = '_', //
447 + [162] = '_', //
448 + [163] = '_', //
449 + [164] = '_', //
450 + [165] = '_', //
451 + [166] = '_', //
452 + [167] = '_', //
453 + [168] = '_', //
454 + [169] = '_', //
455 + [170] = '_', //
456 + [171] = '_', //
457 + [172] = '_', //
458 + [173] = '_', //
459 + [174] = '_', //
460 + [175] = '_', //
461 + [176] = '_', //
462 + [177] = '_', //
463 + [178] = '_', //
464 + [179] = '_', //
465 + [180] = '_', //
466 + [181] = '_', //
467 + [182] = '_', //
468 + [183] = '_', //
469 + [184] = '_', //
470 + [185] = '_', //
471 + [186] = '_', //
472 + [187] = '_', //
473 + [188] = '_', //
474 + [189] = '_', //
475 + [190] = '_', //
476 + [191] = '_', //
477 + [192] = '_', //
478 + [193] = '_', //
479 + [194] = '_', //
480 + [195] = '_', //
481 + [196] = '_', //
482 + [197] = '_', //
483 + [198] = '_', //
484 + [199] = '_', //
485 + [200] = '_', //
486 + [201] = '_', //
487 + [202] = '_', //
488 + [203] = '_', //
489 + [204] = '_', //
490 + [205] = '_', //
491 + [206] = '_', //
492 + [207] = '_', //
493 + [208] = '_', //
494 + [209] = '_', //
495 + [210] = '_', //
496 + [211] = '_', //
497 + [212] = '_', //
498 + [213] = '_', //
499 + [214] = '_', //
500 + [215] = '_', //
501 + [216] = '_', //
502 + [217] = '_', //
503 + [218] = '_', //
504 + [219] = '_', //
505 + [220] = '_', //
506 + [221] = '_', //
507 + [222] = '_', //
508 + [223] = '_', //
509 + [224] = '_', //
510 + [225] = '_', //
511 + [226] = '_', //
512 + [227] = '_', //
513 + [228] = '_', //
514 + [229] = '_', //
515 + [230] = '_', //
516 + [231] = '_', //
517 + [232] = '_', //
518 + [233] = '_', //
519 + [234] = '_', //
520 + [235] = '_', //
521 + [236] = '_', //
522 + [237] = '_', //
523 + [238] = '_', //
524 + [239] = '_', //
525 + [240] = '_', //
526 + [241] = '_', //
527 + [242] = '_', //
528 + [243] = '_', //
529 + [244] = '_', //
530 + [245] = '_', //
531 + [246] = '_', //
532 + [247] = '_', //
533 + [248] = '_', //
534 + [249] = '_', //
535 + [250] = '_', //
536 + [251] = '_', //
537 + [252] = '_', //
538 + [253] = '_', //
539 + [254] = '_', //
540 + [255] = '_' //
541 +};
542 +
543 +// make sure the supplied string
544 +// is good for a netdata chart/dimension ID/NAME
545 +void netdata_fix_chart_name(char *s) {
546 + while ((*s = netdata_map_chart_names[(unsigned char) *s])) s++;
547 +}
548 +
549 +unsigned char netdata_map_chart_ids[256] = {
550 + [0] = '\0', //
551 + [1] = '_', //
552 + [2] = '_', //
553 + [3] = '_', //
554 + [4] = '_', //
555 + [5] = '_', //
556 + [6] = '_', //
557 + [7] = '_', //
558 + [8] = '_', //
559 + [9] = '_', //
560 + [10] = '_', //
561 + [11] = '_', //
562 + [12] = '_', //
563 + [13] = '_', //
564 + [14] = '_', //
565 + [15] = '_', //
566 + [16] = '_', //
567 + [17] = '_', //
568 + [18] = '_', //
569 + [19] = '_', //
570 + [20] = '_', //
571 + [21] = '_', //
572 + [22] = '_', //
573 + [23] = '_', //
574 + [24] = '_', //
575 + [25] = '_', //
576 + [26] = '_', //
577 + [27] = '_', //
578 + [28] = '_', //
579 + [29] = '_', //
580 + [30] = '_', //
581 + [31] = '_', //
582 + [32] = '_', //
583 + [33] = '_', // !
584 + [34] = '_', // "
585 + [35] = '_', // #
586 + [36] = '_', // $
587 + [37] = '_', // %
588 + [38] = '_', // &
589 + [39] = '_', // '
590 + [40] = '_', // (
591 + [41] = '_', // )
592 + [42] = '_', // *
593 + [43] = '_', // +
594 + [44] = '.', // ,
595 + [45] = '-', // -
596 + [46] = '.', // .
597 + [47] = '_', // /
598 + [48] = '0', // 0
599 + [49] = '1', // 1
600 + [50] = '2', // 2
601 + [51] = '3', // 3
602 + [52] = '4', // 4
603 + [53] = '5', // 5
604 + [54] = '6', // 6
605 + [55] = '7', // 7
606 + [56] = '8', // 8
607 + [57] = '9', // 9
608 + [58] = '_', // :
609 + [59] = '_', // ;
610 + [60] = '_', // <
611 + [61] = '_', // =
612 + [62] = '_', // >
613 + [63] = '_', // ?
614 + [64] = '_', // @
615 + [65] = 'a', // A
616 + [66] = 'b', // B
617 + [67] = 'c', // C
618 + [68] = 'd', // D
619 + [69] = 'e', // E
620 + [70] = 'f', // F
621 + [71] = 'g', // G
622 + [72] = 'h', // H
623 + [73] = 'i', // I
624 + [74] = 'j', // J
625 + [75] = 'k', // K
626 + [76] = 'l', // L
627 + [77] = 'm', // M
628 + [78] = 'n', // N
629 + [79] = 'o', // O
630 + [80] = 'p', // P
631 + [81] = 'q', // Q
632 + [82] = 'r', // R
633 + [83] = 's', // S
634 + [84] = 't', // T
635 + [85] = 'u', // U
636 + [86] = 'v', // V
637 + [87] = 'w', // W
638 + [88] = 'x', // X
639 + [89] = 'y', // Y
640 + [90] = 'z', // Z
641 + [91] = '_', // [
642 + [92] = '/', // backslash
643 + [93] = '_', // ]
644 + [94] = '_', // ^
645 + [95] = '_', // _
646 + [96] = '_', // `
647 + [97] = 'a', // a
648 + [98] = 'b', // b
649 + [99] = 'c', // c
650 + [100] = 'd', // d
651 + [101] = 'e', // e
652 + [102] = 'f', // f
653 + [103] = 'g', // g
654 + [104] = 'h', // h
655 + [105] = 'i', // i
656 + [106] = 'j', // j
657 + [107] = 'k', // k
658 + [108] = 'l', // l
659 + [109] = 'm', // m
660 + [110] = 'n', // n
661 + [111] = 'o', // o
662 + [112] = 'p', // p
663 + [113] = 'q', // q
664 + [114] = 'r', // r
665 + [115] = 's', // s
666 + [116] = 't', // t
667 + [117] = 'u', // u
668 + [118] = 'v', // v
669 + [119] = 'w', // w
670 + [120] = 'x', // x
671 + [121] = 'y', // y
672 + [122] = 'z', // z
673 + [123] = '_', // {
674 + [124] = '_', // |
675 + [125] = '_', // }
676 + [126] = '_', // ~
677 + [127] = '_', //
678 + [128] = '_', //
679 + [129] = '_', //
680 + [130] = '_', //
681 + [131] = '_', //
682 + [132] = '_', //
683 + [133] = '_', //
684 + [134] = '_', //
685 + [135] = '_', //
686 + [136] = '_', //
687 + [137] = '_', //
688 + [138] = '_', //
689 + [139] = '_', //
690 + [140] = '_', //
691 + [141] = '_', //
692 + [142] = '_', //
693 + [143] = '_', //
694 + [144] = '_', //
695 + [145] = '_', //
696 + [146] = '_', //
697 + [147] = '_', //
698 + [148] = '_', //
699 + [149] = '_', //
700 + [150] = '_', //
701 + [151] = '_', //
702 + [152] = '_', //
703 + [153] = '_', //
704 + [154] = '_', //
705 + [155] = '_', //
706 + [156] = '_', //
707 + [157] = '_', //
708 + [158] = '_', //
709 + [159] = '_', //
710 + [160] = '_', //
711 + [161] = '_', //
712 + [162] = '_', //
713 + [163] = '_', //
714 + [164] = '_', //
715 + [165] = '_', //
716 + [166] = '_', //
717 + [167] = '_', //
718 + [168] = '_', //
719 + [169] = '_', //
720 + [170] = '_', //
721 + [171] = '_', //
722 + [172] = '_', //
723 + [173] = '_', //
724 + [174] = '_', //
725 + [175] = '_', //
726 + [176] = '_', //
727 + [177] = '_', //
728 + [178] = '_', //
729 + [179] = '_', //
730 + [180] = '_', //
731 + [181] = '_', //
732 + [182] = '_', //
733 + [183] = '_', //
734 + [184] = '_', //
735 + [185] = '_', //
736 + [186] = '_', //
737 + [187] = '_', //
738 + [188] = '_', //
739 + [189] = '_', //
740 + [190] = '_', //
741 + [191] = '_', //
742 + [192] = '_', //
743 + [193] = '_', //
744 + [194] = '_', //
745 + [195] = '_', //
746 + [196] = '_', //
747 + [197] = '_', //
748 + [198] = '_', //
749 + [199] = '_', //
750 + [200] = '_', //
751 + [201] = '_', //
752 + [202] = '_', //
753 + [203] = '_', //
754 + [204] = '_', //
755 + [205] = '_', //
756 + [206] = '_', //
757 + [207] = '_', //
758 + [208] = '_', //
759 + [209] = '_', //
760 + [210] = '_', //
761 + [211] = '_', //
762 + [212] = '_', //
763 + [213] = '_', //
764 + [214] = '_', //
765 + [215] = '_', //
766 + [216] = '_', //
767 + [217] = '_', //
768 + [218] = '_', //
769 + [219] = '_', //
770 + [220] = '_', //
771 + [221] = '_', //
772 + [222] = '_', //
773 + [223] = '_', //
774 + [224] = '_', //
775 + [225] = '_', //
776 + [226] = '_', //
777 + [227] = '_', //
778 + [228] = '_', //
779 + [229] = '_', //
780 + [230] = '_', //
781 + [231] = '_', //
782 + [232] = '_', //
783 + [233] = '_', //
784 + [234] = '_', //
785 + [235] = '_', //
786 + [236] = '_', //
787 + [237] = '_', //
788 + [238] = '_', //
789 + [239] = '_', //
790 + [240] = '_', //
791 + [241] = '_', //
792 + [242] = '_', //
793 + [243] = '_', //
794 + [244] = '_', //
795 + [245] = '_', //
796 + [246] = '_', //
797 + [247] = '_', //
798 + [248] = '_', //
799 + [249] = '_', //
800 + [250] = '_', //
801 + [251] = '_', //
802 + [252] = '_', //
803 + [253] = '_', //
804 + [254] = '_', //
805 + [255] = '_' //
806 +};
807 +
808 +// make sure the supplied string
809 +// is good for a netdata chart/dimension ID/NAME
810 +void netdata_fix_chart_id(char *s) {
811 + while ((*s = netdata_map_chart_ids[(unsigned char) *s])) s++;
812 +}
813 +
814 +/*
815 +// http://stackoverflow.com/questions/7666509/hash-function-for-string
816 +uint32_t simple_hash(const char *name)
817 +{
818 + const char *s = name;
819 + uint32_t hash = 5381;
820 + int i;
821 +
822 + while((i = *s++)) hash = ((hash << 5) + hash) + i;
823 +
824 + // fprintf(stderr, "HASH: %lu %s\n", hash, name);
825 +
826 + return hash;
827 +}
828 +*/
829 +
830 +/*
831 +// http://isthe.com/chongo/tech/comp/fnv/#FNV-1a
832 +uint32_t simple_hash(const char *name) {
833 + unsigned char *s = (unsigned char *) name;
834 + uint32_t hval = 0x811c9dc5;
835 +
836 + // FNV-1a algorithm
837 + while (*s) {
838 + // multiply by the 32 bit FNV magic prime mod 2^32
839 + // NOTE: No need to optimize with left shifts.
840 + // GCC will use imul instruction anyway.
841 + // Tested with 'gcc -O3 -S'
842 + //hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
843 + hval *= 16777619;
844 +
845 + // xor the bottom with the current octet
846 + hval ^= (uint32_t) *s++;
847 + }
848 +
849 + // fprintf(stderr, "HASH: %u = %s\n", hval, name);
850 + return hval;
851 +}
852 +
853 +uint32_t simple_uhash(const char *name) {
854 + unsigned char *s = (unsigned char *) name;
855 + uint32_t hval = 0x811c9dc5, c;
856 +
857 + // FNV-1a algorithm
858 + while ((c = *s++)) {
859 + if (unlikely(c >= 'A' && c <= 'Z')) c += 'a' - 'A';
860 + hval *= 16777619;
861 + hval ^= c;
862 + }
863 + return hval;
864 +}
865 +*/
866 +
867 +/*
868 +// http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx
869 +// one at a time hash
870 +uint32_t simple_hash(const char *name) {
871 + unsigned char *s = (unsigned char *)name;
872 + uint32_t h = 0;
873 +
874 + while(*s) {
875 + h += *s++;
876 + h += (h << 10);
877 + h ^= (h >> 6);
878 + }
879 +
880 + h += (h << 3);
881 + h ^= (h >> 11);
882 + h += (h << 15);
883 +
884 + // fprintf(stderr, "HASH: %u = %s\n", h, name);
885 +
886 + return h;
887 +}
888 +*/
889 +
890 +void strreverse(char *begin, char *end) {
891 + while (end > begin) {
892 + // clearer code.
893 + char aux = *end;
894 + *end-- = *begin;
895 + *begin++ = aux;
896 + }
897 +}
898 +
899 +char *strsep_on_1char(char **ptr, char c) {
900 + if(unlikely(!ptr || !*ptr))
901 + return NULL;
902 +
903 + // remember the position we started
904 + char *s = *ptr;
905 +
906 + // skip separators in front
907 + while(*s == c) s++;
908 + char *ret = s;
909 +
910 + // find the next separator
911 + while(*s++) {
912 + if(unlikely(*s == c)) {
913 + *s++ = '\0';
914 + *ptr = s;
915 + return ret;
916 + }
917 + }
918 +
919 + *ptr = NULL;
920 + return ret;
921 +}
922 +
923 +char *mystrsep(char **ptr, char *s) {
924 + char *p = "";
925 + while (p && !p[0] && *ptr) p = strsep(ptr, s);
926 + return (p);
927 +}
928 +
929 +char *trim(char *s) {
930 + // skip leading spaces
931 + while (*s && isspace(*s)) s++;
932 + if (!*s) return NULL;
933 +
934 + // skip tailing spaces
935 + // this way is way faster. Writes only one NUL char.
936 + ssize_t l = strlen(s);
937 + if (--l >= 0) {
938 + char *p = s + l;
939 + while (p > s && isspace(*p)) p--;
940 + *++p = '\0';
941 + }
942 +
943 + if (!*s) return NULL;
944 +
945 + return s;
946 +}
947 +
948 +inline char *trim_all(char *buffer) {
949 + char *d = buffer, *s = buffer;
950 +
951 + // skip spaces
952 + while(isspace(*s)) s++;
953 +
954 + while(*s) {
955 + // copy the non-space part
956 + while(*s && !isspace(*s)) *d++ = *s++;
957 +
958 + // add a space if we have to
959 + if(*s && isspace(*s)) {
960 + *d++ = ' ';
961 + s++;
962 + }
963 +
964 + // skip spaces
965 + while(isspace(*s)) s++;
966 + }
967 +
968 + *d = '\0';
969 +
970 + if(d > buffer) {
971 + d--;
972 + if(isspace(*d)) *d = '\0';
973 + }
974 +
975 + if(!buffer[0]) return NULL;
976 + return buffer;
977 +}
978 +
979 +static int memory_file_open(const char *filename, size_t size) {
980 + // info("memory_file_open('%s', %zu", filename, size);
981 +
982 + int fd = open(filename, O_RDWR | O_CREAT | O_NOATIME, 0664);
983 + if (fd != -1) {
984 + if (lseek(fd, size, SEEK_SET) == (off_t) size) {
985 + if (write(fd, "", 1) == 1) {
986 + if (ftruncate(fd, size))
987 + error("Cannot truncate file '%s' to size %zu. Will use the larger file.", filename, size);
988 + }
989 + else error("Cannot write to file '%s' at position %zu.", filename, size);
990 + }
991 + else error("Cannot seek file '%s' to size %zu.", filename, size);
992 + }
993 + else error("Cannot create/open file '%s'.", filename);
994 +
995 + return fd;
996 +}
997 +
998 +// mmap_shared is used for memory mode = map
999 +static void *memory_file_mmap(const char *filename, size_t size, int flags) {
1000 + // info("memory_file_mmap('%s', %zu", filename, size);
1001 + static int log_madvise = 1;
1002 +
1003 + int fd = -1;
1004 + if(filename) {
1005 + fd = memory_file_open(filename, size);
1006 + if(fd == -1) return MAP_FAILED;
1007 + }
1008 +
1009 + void *mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, fd, 0);
1010 + if (mem != MAP_FAILED) {
1011 +#ifdef NETDATA_LOG_ALLOCATIONS
1012 + mmap_accounting(size);
1013 +#endif
1014 + int advise = MADV_SEQUENTIAL | MADV_DONTFORK;
1015 + if (flags & MAP_SHARED) advise |= MADV_WILLNEED;
1016 +
1017 + if (madvise(mem, size, advise) != 0 && log_madvise) {
1018 + error("Cannot advise the kernel about shared memory usage.");
1019 + log_madvise--;
1020 + }
1021 + }
1022 +
1023 + if(fd != -1)
1024 + close(fd);
1025 +
1026 + return mem;
1027 +}
1028 +
1029 +#ifdef MADV_MERGEABLE
1030 +static void *memory_file_mmap_ksm(const char *filename, size_t size, int flags) {
1031 + // info("memory_file_mmap_ksm('%s', %zu", filename, size);
1032 + static int log_madvise_2 = 1, log_madvise_3 = 1;
1033 +
1034 + int fd = -1;
1035 + if(filename) {
1036 + fd = memory_file_open(filename, size);
1037 + if(fd == -1) return MAP_FAILED;
1038 + }
1039 +
1040 + void *mem = mmap(NULL, size, PROT_READ | PROT_WRITE, flags | MAP_ANONYMOUS, -1, 0);
1041 + if (mem != MAP_FAILED) {
1042 +#ifdef NETDATA_LOG_ALLOCATIONS
1043 + mmap_accounting(size);
1044 +#endif
1045 + if(fd != -1) {
1046 + if (lseek(fd, 0, SEEK_SET) == 0) {
1047 + if (read(fd, mem, size) != (ssize_t) size)
1048 + error("Cannot read from file '%s'", filename);
1049 + }
1050 + else error("Cannot seek to beginning of file '%s'.", filename);
1051 + }
1052 +
1053 + // don't use MADV_SEQUENTIAL|MADV_DONTFORK, they disable MADV_MERGEABLE
1054 + if (madvise(mem, size, MADV_SEQUENTIAL | MADV_DONTFORK) != 0 && log_madvise_2) {
1055 + error("Cannot advise the kernel about the memory usage (MADV_SEQUENTIAL|MADV_DONTFORK) of file '%s'.", filename);
1056 + log_madvise_2--;
1057 + }
1058 +
1059 + if (madvise(mem, size, MADV_MERGEABLE) != 0 && log_madvise_3) {
1060 + error("Cannot advise the kernel about the memory usage (MADV_MERGEABLE) of file '%s'.", filename);
1061 + log_madvise_3--;
1062 + }
1063 + }
1064 +
1065 + if(fd != -1)
1066 + close(fd);
1067 +
1068 + return mem;
1069 +}
1070 +#else
1071 +static void *memory_file_mmap_ksm(const char *filename, size_t size, int flags) {
1072 + // info("memory_file_mmap_ksm FALLBACK ('%s', %zu", filename, size);
1073 +
1074 + if(filename)
1075 + return memory_file_mmap(filename, size, flags);
1076 +
1077 + // when KSM is not available and no filename is given (memory mode = ram),
1078 + // we just report failure
1079 + return MAP_FAILED;
1080 +}
1081 +#endif
1082 +
1083 +void *mymmap(const char *filename, size_t size, int flags, int ksm) {
1084 + void *mem = NULL;
1085 +
1086 + if (filename && (flags & MAP_SHARED || !enable_ksm || !ksm))
1087 + // memory mode = map | save
1088 + // when KSM is not enabled
1089 + // MAP_SHARED is used for memory mode = map (no KSM possible)
1090 + mem = memory_file_mmap(filename, size, flags);
1091 +
1092 + else
1093 + // memory mode = save | ram
1094 + // when KSM is enabled
1095 + // for memory mode = ram, the filename is NULL
1096 + mem = memory_file_mmap_ksm(filename, size, flags);
1097 +
1098 + if(mem == MAP_FAILED) return NULL;
1099 +
1100 + errno = 0;
1101 + return mem;
1102 +}
1103 +
1104 +int memory_file_save(const char *filename, void *mem, size_t size) {
1105 + char tmpfilename[FILENAME_MAX + 1];
1106 +
1107 + snprintfz(tmpfilename, FILENAME_MAX, "%s.%ld.tmp", filename, (long) getpid());
1108 +
1109 + int fd = open(tmpfilename, O_RDWR | O_CREAT | O_NOATIME, 0664);
1110 + if (fd < 0) {
1111 + error("Cannot create/open file '%s'.", filename);
1112 + return -1;
1113 + }
1114 +
1115 + if (write(fd, mem, size) != (ssize_t) size) {
1116 + error("Cannot write to file '%s' %ld bytes.", filename, (long) size);
1117 + close(fd);
1118 + return -1;
1119 + }
1120 +
1121 + close(fd);
1122 +
1123 + if (rename(tmpfilename, filename)) {
1124 + error("Cannot rename '%s' to '%s'", tmpfilename, filename);
1125 + return -1;
1126 + }
1127 +
1128 + return 0;
1129 +}
1130 +
1131 +int fd_is_valid(int fd) {
1132 + return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
1133 +}
1134 +
1135 +char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
1136 + char *s = fgets(buf, (int)buf_size, fp);
1137 + if (!s) return NULL;
1138 +
1139 + char *t = s;
1140 + if (*t != '\0') {
1141 + // find the string end
1142 + while (*++t != '\0');
1143 +
1144 + // trim trailing spaces/newlines/tabs
1145 + while (--t > s && *t == '\n')
1146 + *t = '\0';
1147 + }
1148 +
1149 + if (len)
1150 + *len = t - s + 1;
1151 +
1152 + return s;
1153 +}
1154 +
1155 +int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args) {
1156 + int size = vsnprintf(dst, n, fmt, args);
1157 +
1158 + if (unlikely((size_t) size > n)) {
1159 + // truncated
1160 + size = (int)n;
1161 + }
1162 +
1163 + dst[size] = '\0';
1164 + return size;
1165 +}
1166 +
1167 +int snprintfz(char *dst, size_t n, const char *fmt, ...) {
1168 + va_list args;
1169 +
1170 + va_start(args, fmt);
1171 + int ret = vsnprintfz(dst, n, fmt, args);
1172 + va_end(args);
1173 +
1174 + return ret;
1175 +}
1176 +
1177 +/*
1178 +// poor man cycle counting
1179 +static unsigned long tsc;
1180 +void begin_tsc(void) {
1181 + unsigned long a, d;
1182 + asm volatile ("cpuid\nrdtsc" : "=a" (a), "=d" (d) : "0" (0) : "ebx", "ecx");
1183 + tsc = ((unsigned long)d << 32) | (unsigned long)a;
1184 +}
1185 +unsigned long end_tsc(void) {
1186 + unsigned long a, d;
1187 + asm volatile ("rdtscp" : "=a" (a), "=d" (d) : : "ecx");
1188 + return (((unsigned long)d << 32) | (unsigned long)a) - tsc;
1189 +}
1190 +*/
1191 +
1192 +int recursively_delete_dir(const char *path, const char *reason) {
1193 + DIR *dir = opendir(path);
1194 + if(!dir) {
1195 + error("Cannot read %s directory to be deleted '%s'", reason?reason:"", path);
1196 + return -1;
1197 + }
1198 +
1199 + int ret = 0;
1200 + struct dirent *de = NULL;
1201 + while((de = readdir(dir))) {
1202 + if(de->d_type == DT_DIR
1203 + && (
1204 + (de->d_name[0] == '.' && de->d_name[1] == '\0')
1205 + || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1206 + ))
1207 + continue;
1208 +
1209 + char fullpath[FILENAME_MAX + 1];
1210 + snprintfz(fullpath, FILENAME_MAX, "%s/%s", path, de->d_name);
1211 +
1212 + if(de->d_type == DT_DIR) {
1213 + int r = recursively_delete_dir(fullpath, reason);
1214 + if(r > 0) ret += r;
1215 + continue;
1216 + }
1217 +
1218 + info("Deleting %s file '%s'", reason?reason:"", fullpath);
1219 + if(unlikely(unlink(fullpath) == -1))
1220 + error("Cannot delete %s file '%s'", reason?reason:"", fullpath);
1221 + else
1222 + ret++;
1223 + }
1224 +
1225 + info("Deleting empty directory '%s'", path);
1226 + if(unlikely(rmdir(path) == -1))
1227 + error("Cannot delete empty directory '%s'", path);
1228 + else
1229 + ret++;
1230 +
1231 + closedir(dir);
1232 +
1233 + return ret;
1234 +}
1235 +
1236 +static int is_virtual_filesystem(const char *path, char **reason) {
1237 +
1238 +#if defined(__APPLE__) || defined(__FreeBSD__)
1239 + (void)path;
1240 + (void)reason;
1241 +#else
1242 + struct statfs stat;
1243 + // stat.f_fsid.__val[0] is a file system id
1244 + // stat.f_fsid.__val[1] is the inode
1245 + // so their combination uniquely identifies the file/dir
1246 +
1247 + if (statfs(path, &stat) == -1) {
1248 + if(reason) *reason = "failed to statfs()";
1249 + return -1;
1250 + }
1251 +
1252 + if(stat.f_fsid.__val[0] != 0 || stat.f_fsid.__val[1] != 0) {
1253 + errno = EINVAL;
1254 + if(reason) *reason = "is not a virtual file system";
1255 + return -1;
1256 + }
1257 +#endif
1258 +
1259 + return 0;
1260 +}
1261 +
1262 +int verify_netdata_host_prefix() {
1263 + if(!netdata_configured_host_prefix)
1264 + netdata_configured_host_prefix = "";
1265 +
1266 + if(!*netdata_configured_host_prefix)
1267 + return 0;
1268 +
1269 + char buffer[FILENAME_MAX + 1];
1270 + char *path = netdata_configured_host_prefix;
1271 + char *reason = "unknown reason";
1272 + errno = 0;
1273 +
1274 + struct stat sb;
1275 + if (stat(path, &sb) == -1) {
1276 + reason = "failed to stat()";
1277 + goto failed;
1278 + }
1279 +
1280 + if((sb.st_mode & S_IFMT) != S_IFDIR) {
1281 + errno = EINVAL;
1282 + reason = "is not a directory";
1283 + goto failed;
1284 + }
1285 +
1286 + path = buffer;
1287 + snprintfz(path, FILENAME_MAX, "%s/proc", netdata_configured_host_prefix);
1288 + if(is_virtual_filesystem(path, &reason) == -1)
1289 + goto failed;
1290 +
1291 + snprintfz(path, FILENAME_MAX, "%s/sys", netdata_configured_host_prefix);
1292 + if(is_virtual_filesystem(path, &reason) == -1)
1293 + goto failed;
1294 +
1295 + if(netdata_configured_host_prefix && *netdata_configured_host_prefix)
1296 + info("Using host prefix directory '%s'", netdata_configured_host_prefix);
1297 +
1298 + return 0;
1299 +
1300 +failed:
1301 + error("Ignoring host prefix '%s': path '%s' %s", netdata_configured_host_prefix, path, reason);
1302 + netdata_configured_host_prefix = "";
1303 + return -1;
1304 +}
1305 +
1306 +char *strdupz_path_subpath(const char *path, const char *subpath) {
1307 + if(unlikely(!path || !*path)) path = ".";
1308 + if(unlikely(!subpath)) subpath = "";
1309 +
1310 + // skip trailing slashes in path
1311 + size_t len = strlen(path);
1312 + while(len > 0 && path[len - 1] == '/') len--;
1313 +
1314 + // skip leading slashes in subpath
1315 + while(subpath[0] == '/') subpath++;
1316 +
1317 + // if the last character in path is / and (there is a subpath or path is now empty)
1318 + // keep the trailing slash in path and remove the additional slash
1319 + char *slash = "/";
1320 + if(path[len] == '/' && (*subpath || len == 0)) {
1321 + slash = "";
1322 + len++;
1323 + }
1324 + else if(!*subpath) {
1325 + // there is no subpath
1326 + // no need for trailing slash
1327 + slash = "";
1328 + }
1329 +
1330 + char buffer[FILENAME_MAX + 1];
1331 + snprintfz(buffer, FILENAME_MAX, "%.*s%s%s", (int)len, path, slash, subpath);
1332 + return strdupz(buffer);
1333 +}
1334 +
1335 +int path_is_dir(const char *path, const char *subpath) {
1336 + char *s = strdupz_path_subpath(path, subpath);
1337 +
1338 + size_t max_links = 100;
1339 +
1340 + int is_dir = 0;
1341 + struct stat statbuf;
1342 + while(max_links-- && stat(s, &statbuf) == 0) {
1343 + if((statbuf.st_mode & S_IFMT) == S_IFDIR) {
1344 + is_dir = 1;
1345 + break;
1346 + }
1347 + else if((statbuf.st_mode & S_IFMT) == S_IFLNK) {
1348 + char buffer[FILENAME_MAX + 1];
1349 + ssize_t l = readlink(s, buffer, FILENAME_MAX);
1350 + if(l > 0) {
1351 + buffer[l] = '\0';
1352 + freez(s);
1353 + s = strdupz(buffer);
1354 + continue;
1355 + }
1356 + else {
1357 + is_dir = 0;
1358 + break;
1359 + }
1360 + }
1361 + else {
1362 + is_dir = 0;
1363 + break;
1364 + }
1365 + }
1366 +
1367 + freez(s);
1368 + return is_dir;
1369 +}
1370 +
1371 +int path_is_file(const char *path, const char *subpath) {
1372 + char *s = strdupz_path_subpath(path, subpath);
1373 +
1374 + size_t max_links = 100;
1375 +
1376 + int is_file = 0;
1377 + struct stat statbuf;
1378 + while(max_links-- && stat(s, &statbuf) == 0) {
1379 + if((statbuf.st_mode & S_IFMT) == S_IFREG) {
1380 + is_file = 1;
1381 + break;
1382 + }
1383 + else if((statbuf.st_mode & S_IFMT) == S_IFLNK) {
1384 + char buffer[FILENAME_MAX + 1];
1385 + ssize_t l = readlink(s, buffer, FILENAME_MAX);
1386 + if(l > 0) {
1387 + buffer[l] = '\0';
1388 + freez(s);
1389 + s = strdupz(buffer);
1390 + continue;
1391 + }
1392 + else {
1393 + is_file = 0;
1394 + break;
1395 + }
1396 + }
1397 + else {
1398 + is_file = 0;
1399 + break;
1400 + }
1401 + }
1402 +
1403 + freez(s);
1404 + return is_file;
1405 +}
1406 +
1407 +void recursive_config_double_dir_load(const char *user_path, const char *stock_path, const char *subpath, int (*callback)(const char *filename, void *data), void *data, size_t depth) {
1408 + if(depth > 3) {
1409 + error("CONFIG: Max directory depth reached while reading user path '%s', stock path '%s', subpath '%s'", user_path, stock_path, subpath);
1410 + return;
1411 + }
1412 +
1413 + char *udir = strdupz_path_subpath(user_path, subpath);
1414 + char *sdir = strdupz_path_subpath(stock_path, subpath);
1415 +
1416 + debug(D_HEALTH, "CONFIG traversing user-config directory '%s', stock config directory '%s'", udir, sdir);
1417 +
1418 + DIR *dir = opendir(udir);
1419 + if (!dir) {
1420 + error("CONFIG cannot open user-config directory '%s'.", udir);
1421 + }
1422 + else {
1423 + struct dirent *de = NULL;
1424 + while((de = readdir(dir))) {
1425 + if(de->d_type == DT_DIR || de->d_type == DT_LNK) {
1426 + if( !de->d_name[0] ||
1427 + (de->d_name[0] == '.' && de->d_name[1] == '\0') ||
1428 + (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1429 + ) {
1430 + debug(D_HEALTH, "CONFIG ignoring user-config directory '%s/%s'", udir, de->d_name);
1431 + continue;
1432 + }
1433 +
1434 + if(path_is_dir(udir, de->d_name)) {
1435 + recursive_config_double_dir_load(udir, sdir, de->d_name, callback, data, depth + 1);
1436 + continue;
1437 + }
1438 + }
1439 +
1440 + if(de->d_type == DT_REG || de->d_type == DT_LNK) {
1441 + size_t len = strlen(de->d_name);
1442 + if(path_is_file(udir, de->d_name) &&
1443 + len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
1444 + char *filename = strdupz_path_subpath(udir, de->d_name);
1445 + callback(filename, data);
1446 + freez(filename);
1447 + }
1448 + else
1449 + debug(D_HEALTH, "CONFIG ignoring user-config file '%s/%s'", udir, de->d_name);
1450 + }
1451 + }
1452 +
1453 + closedir(dir);
1454 + }
1455 +
1456 + debug(D_HEALTH, "CONFIG traversing stock config directory '%s', user config directory '%s'", sdir, udir);
1457 +
1458 + dir = opendir(sdir);
1459 + if (!dir) {
1460 + error("CONFIG cannot open stock config directory '%s'.", sdir);
1461 + }
1462 + else {
1463 + struct dirent *de = NULL;
1464 + while((de = readdir(dir))) {
1465 + if(de->d_type == DT_DIR || de->d_type == DT_LNK) {
1466 + if( !de->d_name[0] ||
1467 + (de->d_name[0] == '.' && de->d_name[1] == '\0') ||
1468 + (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
1469 + ) {
1470 + debug(D_HEALTH, "CONFIG ignoring stock config directory '%s/%s'", sdir, de->d_name);
1471 + continue;
1472 + }
1473 +
1474 + if(path_is_dir(sdir, de->d_name)) {
1475 + // we recurse in stock subdirectory, only when there is no corresponding
1476 + // user subdirectory - to avoid reading the files twice
1477 +
1478 + if(!path_is_dir(udir, de->d_name))
1479 + recursive_config_double_dir_load(udir, sdir, de->d_name, callback, data, depth + 1);
1480 +
1481 + continue;
1482 + }
1483 + }
1484 +
1485 + if(de->d_type == DT_REG || de->d_type == DT_LNK) {
1486 + size_t len = strlen(de->d_name);
1487 + if(path_is_file(sdir, de->d_name) && !path_is_file(udir, de->d_name) &&
1488 + len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
1489 + char *filename = strdupz_path_subpath(sdir, de->d_name);
1490 + callback(filename, data);
1491 + freez(filename);
1492 + }
1493 + else
1494 + debug(D_HEALTH, "CONFIG ignoring stock config file '%s/%s'", sdir, de->d_name);
1495 + }
1496 + }
1497 +
1498 + closedir(dir);
1499 + }
1500 +
1501 + freez(udir);
1502 + freez(sdir);
1503 +}
src/libnetdata/dictionary.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // ----------------------------------------------------------------------------
6 // dictionary statistics
src/libnetdata/dictionary.h renamed
+2 -2
@@ -1,10 +1,10 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
4 -
3 #ifndef NETDATA_DICTIONARY_H
4 #define NETDATA_DICTIONARY_H 1
5
6 +#include "libnetdata.h"
7 +
8 struct dictionary_stats {
9 unsigned long long inserts;
10 unsigned long long deletes;
src/libnetdata/eval.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // ----------------------------------------------------------------------------
6 // data structures for storing the parsed expression in memory
src/libnetdata/eval.h renamed
+14
@@ -3,8 +3,20 @@
3 #ifndef NETDATA_EVAL_H
4 #define NETDATA_EVAL_H 1
5
6 +#include "libnetdata.h"
7 +
8 #define EVAL_MAX_VARIABLE_NAME_LENGTH 300
9
10 +typedef enum rrdcalc_status {
11 + RRDCALC_STATUS_REMOVED = -2,
12 + RRDCALC_STATUS_UNDEFINED = -1,
13 + RRDCALC_STATUS_UNINITIALIZED = 0,
14 + RRDCALC_STATUS_CLEAR = 1,
15 + RRDCALC_STATUS_RAISED = 2,
16 + RRDCALC_STATUS_WARNING = 3,
17 + RRDCALC_STATUS_CRITICAL = 4
18 +} RRDCALC_STATUS;
19 +
20 typedef struct eval_variable {
21 char *name;
22 uint32_t hash;
@@ -71,4 +83,6 @@ extern const char *expression_strerror(int error);
83 // 2 = FAILED, the error message is in: buffer_tostring(expression->error_msg)
84 extern int expression_evaluate(EVAL_EXPRESSION *expression);
85
86 +extern int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result);
87 +
88 #endif //NETDATA_EVAL_H
src/libnetdata/inlined.h renamed
+2 -2
@@ -1,10 +1,10 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
4 -
3 #ifndef NETDATA_INLINED_H
4 #define NETDATA_INLINED_H 1
5
6 +#include "libnetdata.h"
7 +
8 #ifdef KERNEL_32BIT
9 typedef uint32_t kernel_uint_t;
10 #define str2kernel_uint_t(string) str2uint32_t(string)
src/libnetdata/libnetdata.h new
+309
@@ -0,0 +1,309 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_LIB_H
4 +#define NETDATA_LIB_H 1
5 +
6 +#ifdef HAVE_CONFIG_H
7 +#include <config.h>
8 +#endif
9 +
10 +#define OS_LINUX 1
11 +#define OS_FREEBSD 2
12 +#define OS_MACOS 3
13 +
14 +
15 +// ----------------------------------------------------------------------------
16 +// system include files for all netdata C programs
17 +
18 +/* select the memory allocator, based on autoconf findings */
19 +#if defined(ENABLE_JEMALLOC)
20 +
21 +#if defined(HAVE_JEMALLOC_JEMALLOC_H)
22 +#include <jemalloc/jemalloc.h>
23 +#else // !defined(HAVE_JEMALLOC_JEMALLOC_H)
24 +#include <malloc.h>
25 +#endif // !defined(HAVE_JEMALLOC_JEMALLOC_H)
26 +
27 +#elif defined(ENABLE_TCMALLOC)
28 +
29 +#include <google/tcmalloc.h>
30 +
31 +#else /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
32 +
33 +#if !(defined(__FreeBSD__) || defined(__APPLE__))
34 +#include <malloc.h>
35 +#endif /* __FreeBSD__ || __APPLE__ */
36 +
37 +#endif /* !defined(ENABLE_JEMALLOC) && !defined(ENABLE_TCMALLOC) */
38 +
39 +// ----------------------------------------------------------------------------
40 +
41 +#if defined(__FreeBSD__)
42 +#include <pthread_np.h>
43 +#define NETDATA_OS_TYPE "freebsd"
44 +#elif defined(__APPLE__)
45 +#define NETDATA_OS_TYPE "macos"
46 +#else
47 +#define NETDATA_OS_TYPE "linux"
48 +#endif /* __FreeBSD__, __APPLE__*/
49 +
50 +#include <pthread.h>
51 +#include <errno.h>
52 +#include <stdio.h>
53 +#include <stdlib.h>
54 +#include <stdarg.h>
55 +#include <stddef.h>
56 +#include <ctype.h>
57 +#include <string.h>
58 +#include <strings.h>
59 +#include <arpa/inet.h>
60 +#include <netinet/tcp.h>
61 +#include <sys/ioctl.h>
62 +#include <libgen.h>
63 +#include <dirent.h>
64 +#include <fcntl.h>
65 +#include <getopt.h>
66 +#include <grp.h>
67 +#include <pwd.h>
68 +#include <locale.h>
69 +#include <net/if.h>
70 +#include <poll.h>
71 +#include <signal.h>
72 +#include <syslog.h>
73 +#include <sys/mman.h>
74 +#include <sys/resource.h>
75 +#include <sys/socket.h>
76 +#include <sys/syscall.h>
77 +#include <sys/time.h>
78 +#include <sys/types.h>
79 +#include <sys/wait.h>
80 +#include <sys/un.h>
81 +#include <time.h>
82 +#include <unistd.h>
83 +#include <uuid/uuid.h>
84 +
85 +#ifdef HAVE_NETINET_IN_H
86 +#include <netinet/in.h>
87 +#endif
88 +
89 +#ifdef HAVE_RESOLV_H
90 +#include <resolv.h>
91 +#endif
92 +
93 +#ifdef HAVE_NETDB_H
94 +#include <netdb.h>
95 +#endif
96 +
97 +#ifdef HAVE_SYS_PRCTL_H
98 +#include <sys/prctl.h>
99 +#endif
100 +
101 +#ifdef HAVE_SYS_STAT_H
102 +#include <sys/stat.h>
103 +#endif
104 +
105 +#ifdef HAVE_SYS_VFS_H
106 +#include <sys/vfs.h>
107 +#endif
108 +
109 +#ifdef HAVE_SYS_STATFS_H
110 +#include <sys/statfs.h>
111 +#endif
112 +
113 +#ifdef HAVE_SYS_MOUNT_H
114 +#include <sys/mount.h>
115 +#endif
116 +
117 +#ifdef HAVE_SYS_STATVFS_H
118 +#include <sys/statvfs.h>
119 +#endif
120 +
121 +// #1408
122 +#ifdef MAJOR_IN_MKDEV
123 +#include <sys/mkdev.h>
124 +#endif
125 +#ifdef MAJOR_IN_SYSMACROS
126 +#include <sys/sysmacros.h>
127 +#endif
128 +
129 +#ifdef STORAGE_WITH_MATH
130 +#include <math.h>
131 +#include <float.h>
132 +#endif
133 +
134 +#if defined(HAVE_INTTYPES_H)
135 +#include <inttypes.h>
136 +#elif defined(HAVE_STDINT_H)
137 +#include <stdint.h>
138 +#endif
139 +
140 +#ifdef NETDATA_WITH_ZLIB
141 +#include <zlib.h>
142 +#endif
143 +
144 +#ifdef HAVE_CAPABILITY
145 +#include <sys/capability.h>
146 +#endif
147 +
148 +
149 +// ----------------------------------------------------------------------------
150 +// netdata common definitions
151 +
152 +#if (SIZEOF_VOID_P == 8)
153 +#define ENVIRONMENT64
154 +#elif (SIZEOF_VOID_P == 4)
155 +#define ENVIRONMENT32
156 +#else
157 +#error "Cannot detect if this is a 32 or 64 bit CPU"
158 +#endif
159 +
160 +#ifdef __GNUC__
161 +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
162 +#endif // __GNUC__
163 +
164 +#ifdef HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
165 +#define NEVERNULL __attribute__((returns_nonnull))
166 +#else
167 +#define NEVERNULL
168 +#endif
169 +
170 +#ifdef HAVE_FUNC_ATTRIBUTE_NOINLINE
171 +#define NOINLINE __attribute__((noinline))
172 +#else
173 +#define NOINLINE
174 +#endif
175 +
176 +#ifdef HAVE_FUNC_ATTRIBUTE_MALLOC
177 +#define MALLOCLIKE __attribute__((malloc))
178 +#else
179 +#define MALLOCLIKE
180 +#endif
181 +
182 +#ifdef HAVE_FUNC_ATTRIBUTE_FORMAT
183 +#define PRINTFLIKE(f, a) __attribute__ ((format(__printf__, f, a)))
184 +#else
185 +#define PRINTFLIKE(f, a)
186 +#endif
187 +
188 +#ifdef HAVE_FUNC_ATTRIBUTE_NORETURN
189 +#define NORETURN __attribute__ ((noreturn))
190 +#else
191 +#define NORETURN
192 +#endif
193 +
194 +#ifdef HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
195 +#define WARNUNUSED __attribute__ ((warn_unused_result))
196 +#else
197 +#define WARNUNUSED
198 +#endif
199 +
200 +#ifdef abs
201 +#undef abs
202 +#endif
203 +#define abs(x) (((x) < 0)? (-(x)) : (x))
204 +
205 +#define GUID_LEN 36
206 +
207 +#include "os.h"
208 +#include "storage_number.h"
209 +#include "web_buffer.h"
210 +#include "locks.h"
211 +#include "avl.h"
212 +#include "inlined.h"
213 +#include "clocks.h"
214 +#include "threads.h"
215 +#include "popen.h"
216 +#include "simple_pattern.h"
217 +#include "socket.h"
218 +#include "appconfig.h"
219 +#include "log.h"
220 +#include "procfile.h"
221 +#include "dictionary.h"
222 +#include "eval.h"
223 +#include "statistical.h"
224 +#include "adaptive_resortable_list.h"
225 +#include "url.h"
226 +
227 +extern void netdata_fix_chart_id(char *s);
228 +extern void netdata_fix_chart_name(char *s);
229 +
230 +extern void strreverse(char* begin, char* end);
231 +extern char *mystrsep(char **ptr, char *s);
232 +extern char *trim(char *s); // remove leading and trailing spaces; may return NULL
233 +extern char *trim_all(char *buffer); // like trim(), but also remove duplicate spaces inside the string; may return NULL
234 +
235 +extern int vsnprintfz(char *dst, size_t n, const char *fmt, va_list args);
236 +extern int snprintfz(char *dst, size_t n, const char *fmt, ...) PRINTFLIKE(3, 4);
237 +
238 +// memory allocation functions that handle failures
239 +#ifdef NETDATA_LOG_ALLOCATIONS
240 +#define strdupz(s) strdupz_int(__FILE__, __FUNCTION__, __LINE__, s)
241 +#define callocz(nmemb, size) callocz_int(__FILE__, __FUNCTION__, __LINE__, nmemb, size)
242 +#define mallocz(size) mallocz_int(__FILE__, __FUNCTION__, __LINE__, size)
243 +#define reallocz(ptr, size) reallocz_int(__FILE__, __FUNCTION__, __LINE__, ptr, size)
244 +#define freez(ptr) freez_int(__FILE__, __FUNCTION__, __LINE__, ptr)
245 +
246 +extern char *strdupz_int(const char *file, const char *function, const unsigned long line, const char *s);
247 +extern void *callocz_int(const char *file, const char *function, const unsigned long line, size_t nmemb, size_t size);
248 +extern void *mallocz_int(const char *file, const char *function, const unsigned long line, size_t size);
249 +extern void *reallocz_int(const char *file, const char *function, const unsigned long line, void *ptr, size_t size);
250 +extern void freez_int(const char *file, const char *function, const unsigned long line, void *ptr);
251 +#else
252 +extern char *strdupz(const char *s) MALLOCLIKE NEVERNULL;
253 +extern void *callocz(size_t nmemb, size_t size) MALLOCLIKE NEVERNULL;
254 +extern void *mallocz(size_t size) MALLOCLIKE NEVERNULL;
255 +extern void *reallocz(void *ptr, size_t size) MALLOCLIKE NEVERNULL;
256 +extern void freez(void *ptr);
257 +#endif
258 +
259 +extern void json_escape_string(char *dst, const char *src, size_t size);
260 +extern void json_fix_string(char *s);
261 +
262 +extern void *mymmap(const char *filename, size_t size, int flags, int ksm);
263 +extern int memory_file_save(const char *filename, void *mem, size_t size);
264 +
265 +extern int fd_is_valid(int fd);
266 +
267 +extern struct rlimit rlimit_nofile;
268 +
269 +extern int enable_ksm;
270 +
271 +extern int sleep_usec(usec_t usec);
272 +
273 +extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
274 +
275 +extern int verify_netdata_host_prefix();
276 +
277 +extern int recursively_delete_dir(const char *path, const char *reason);
278 +
279 +extern volatile sig_atomic_t netdata_exit;
280 +extern const char *os_type;
281 +
282 +extern const char *program_version;
283 +
284 +extern char *strdupz_path_subpath(const char *path, const char *subpath);
285 +extern int path_is_dir(const char *path, const char *subpath);
286 +extern int path_is_file(const char *path, const char *subpath);
287 +extern void recursive_config_double_dir_load(
288 + const char *user_path
289 + , const char *stock_path
290 + , const char *subpath
291 + , int (*callback)(const char *filename, void *data)
292 + , void *data
293 + , size_t depth
294 +);
295 +
296 +/* fix for alpine linux */
297 +#ifndef RUSAGE_THREAD
298 +#ifdef RUSAGE_CHILDREN
299 +#define RUSAGE_THREAD RUSAGE_CHILDREN
300 +#endif
301 +#endif
302 +
303 +#define BITS_IN_A_KILOBIT 1000
304 +
305 +
306 +extern void netdata_cleanup_and_exit(int ret) NORETURN;
307 +extern char *netdata_configured_host_prefix;
308 +
309 +#endif // NETDATA_LIB_H
src/libnetdata/locks.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // ----------------------------------------------------------------------------
6 // automatic thread cancelability management, based on locks
src/libnetdata/locks.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_LOCKS_H
4 #define NETDATA_LOCKS_H 1
5
6 +#include "libnetdata.h"
7 +
8 typedef pthread_mutex_t netdata_mutex_t;
9 #define NETDATA_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
10
src/libnetdata/log.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 int web_server_is_multithreaded = 1;
6
src/libnetdata/log.h renamed
+2 -2
@@ -1,10 +1,10 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
4 -
3 #ifndef NETDATA_LOG_H
4 #define NETDATA_LOG_H 1
5
6 +#include "libnetdata.h"
7 +
8 #define D_WEB_BUFFER 0x0000000000000001
9 #define D_WEB_CLIENT 0x0000000000000002
10 #define D_LISTENER 0x0000000000000004
src/libnetdata/os.c new
+218
@@ -0,0 +1,218 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "os.h"
4 +
5 +// ----------------------------------------------------------------------------
6 +// system functions
7 +// to retrieve settings of the system
8 +
9 +int processors = 1;
10 +long get_system_cpus(void) {
11 + processors = 1;
12 +
13 +#ifdef __APPLE__
14 + int32_t tmp_processors;
15 +
16 + if (unlikely(GETSYSCTL_BY_NAME("hw.logicalcpu", tmp_processors))) {
17 + error("Assuming system has %d processors.", processors);
18 + } else {
19 + processors = tmp_processors;
20 + }
21 +
22 + return processors;
23 +#elif __FreeBSD__
24 + int32_t tmp_processors;
25 +
26 + if (unlikely(GETSYSCTL_BY_NAME("hw.ncpu", tmp_processors))) {
27 + error("Assuming system has %d processors.", processors);
28 + } else {
29 + processors = tmp_processors;
30 + }
31 +
32 + return processors;
33 +#else
34 +
35 + char filename[FILENAME_MAX + 1];
36 + snprintfz(filename, FILENAME_MAX, "%s/proc/stat", netdata_configured_host_prefix);
37 +
38 + procfile *ff = procfile_open(filename, NULL, PROCFILE_FLAG_DEFAULT);
39 + if(!ff) {
40 + error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
41 + return processors;
42 + }
43 +
44 + ff = procfile_readall(ff);
45 + if(!ff) {
46 + error("Cannot open file '%s'. Assuming system has %d processors.", filename, processors);
47 + return processors;
48 + }
49 +
50 + processors = 0;
51 + unsigned int i;
52 + for(i = 0; i < procfile_lines(ff); i++) {
53 + if(!procfile_linewords(ff, i)) continue;
54 +
55 + if(strncmp(procfile_lineword(ff, i, 0), "cpu", 3) == 0) processors++;
56 + }
57 + processors--;
58 + if(processors < 1) processors = 1;
59 +
60 + procfile_close(ff);
61 +
62 + debug(D_SYSTEM, "System has %d processors.", processors);
63 + return processors;
64 +
65 +#endif /* __APPLE__, __FreeBSD__ */
66 +}
67 +
68 +pid_t pid_max = 32768;
69 +pid_t get_system_pid_max(void) {
70 +#ifdef __APPLE__
71 + // As we currently do not know a solution to query pid_max from the os
72 + // we use the number defined in bsd/sys/proc_internal.h in XNU sources
73 + pid_max = 99999;
74 + return pid_max;
75 +#elif __FreeBSD__
76 + int32_t tmp_pid_max;
77 +
78 + if (unlikely(GETSYSCTL_BY_NAME("kern.pid_max", tmp_pid_max))) {
79 + pid_max = 99999;
80 + error("Assuming system's maximum pid is %d.", pid_max);
81 + } else {
82 + pid_max = tmp_pid_max;
83 + }
84 +
85 + return pid_max;
86 +#else
87 +
88 + static char read = 0;
89 + if(unlikely(read)) return pid_max;
90 + read = 1;
91 +
92 + char filename[FILENAME_MAX + 1];
93 + snprintfz(filename, FILENAME_MAX, "%s/proc/sys/kernel/pid_max", netdata_configured_host_prefix);
94 +
95 + unsigned long long max = 0;
96 + if(read_single_number_file(filename, &max) != 0) {
97 + error("Cannot open file '%s'. Assuming system supports %d pids.", filename, pid_max);
98 + return pid_max;
99 + }
100 +
101 + if(!max) {
102 + error("Cannot parse file '%s'. Assuming system supports %d pids.", filename, pid_max);
103 + return pid_max;
104 + }
105 +
106 + pid_max = (pid_t) max;
107 + return pid_max;
108 +
109 +#endif /* __APPLE__, __FreeBSD__ */
110 +}
111 +
112 +unsigned int system_hz;
113 +void get_system_HZ(void) {
114 + long ticks;
115 +
116 + if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
117 + error("Cannot get system clock ticks");
118 + }
119 +
120 + system_hz = (unsigned int) ticks;
121 +}
122 +
123 +// =====================================================================================================================
124 +// FreeBSD
125 +
126 +#if (TARGET_OS == OS_FREEBSD)
127 +
128 +int getsysctl_by_name(const char *name, void *ptr, size_t len) {
129 + size_t nlen = len;
130 +
131 + if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
132 + error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
133 + return 1;
134 + }
135 + if (unlikely(nlen != len)) {
136 + error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
137 + return 1;
138 + }
139 + return 0;
140 +}
141 +
142 +int getsysctl_simple(const char *name, int *mib, size_t miblen, void *ptr, size_t len) {
143 + size_t nlen = len;
144 +
145 + if (unlikely(!mib[0]))
146 + if (unlikely(getsysctl_mib(name, mib, miblen)))
147 + return 1;
148 +
149 + if (unlikely(sysctl(mib, miblen, ptr, &nlen, NULL, 0) == -1)) {
150 + error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
151 + return 1;
152 + }
153 + if (unlikely(nlen != len)) {
154 + error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
155 + return 1;
156 + }
157 +
158 + return 0;
159 +}
160 +
161 +int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len) {
162 + size_t nlen = *len;
163 +
164 + if (unlikely(!mib[0]))
165 + if (unlikely(getsysctl_mib(name, mib, miblen)))
166 + return 1;
167 +
168 + if (unlikely(sysctl(mib, miblen, ptr, len, NULL, 0) == -1)) {
169 + error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
170 + return 1;
171 + }
172 + if (unlikely(ptr != NULL && nlen != *len)) {
173 + error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)*len, (unsigned long)nlen);
174 + return 1;
175 + }
176 +
177 + return 0;
178 +}
179 +
180 +int getsysctl_mib(const char *name, int *mib, size_t len) {
181 + size_t nlen = len;
182 +
183 + if (unlikely(sysctlnametomib(name, mib, &nlen) == -1)) {
184 + error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
185 + return 1;
186 + }
187 + if (unlikely(nlen != len)) {
188 + error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
189 + return 1;
190 + }
191 + return 0;
192 +}
193 +
194 +
195 +#endif
196 +
197 +
198 +// =====================================================================================================================
199 +// MacOS
200 +
201 +#if (TARGET_OS == OS_MACOS)
202 +
203 +int getsysctl_by_name(const char *name, void *ptr, size_t len) {
204 + size_t nlen = len;
205 +
206 + if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
207 + error("MACOS: sysctl(%s...) failed: %s", name, strerror(errno));
208 + return 1;
209 + }
210 + if (unlikely(nlen != len)) {
211 + error("MACOS: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
212 + return 1;
213 + }
214 + return 0;
215 +}
216 +
217 +#endif // (TARGET_OS == OS_MACOS)
218 +
src/libnetdata/os.h new
+70
@@ -0,0 +1,70 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_OS_H
4 +#define NETDATA_OS_H
5 +
6 +#include "libnetdata.h"
7 +
8 +// =====================================================================================================================
9 +// Linux
10 +
11 +#if (TARGET_OS == OS_LINUX)
12 +
13 +
14 +// =====================================================================================================================
15 +// FreeBSD
16 +
17 +#elif (TARGET_OS == OS_FREEBSD)
18 +
19 +#include <sys/sysctl.h>
20 +
21 +#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
22 +extern int getsysctl_by_name(const char *name, void *ptr, size_t len);
23 +
24 +#define GETSYSCTL_MIB(name, mib) getsysctl_mib(name, mib, sizeof(mib)/sizeof(int))
25 +
26 +extern int getsysctl_mib(const char *name, int *mib, size_t len);
27 +
28 +#define GETSYSCTL_SIMPLE(name, mib, var) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), &(var), sizeof(var))
29 +#define GETSYSCTL_WSIZE(name, mib, var, size) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), var, size)
30 +
31 +extern int getsysctl_simple(const char *name, int *mib, size_t miblen, void *ptr, size_t len);
32 +
33 +#define GETSYSCTL_SIZE(name, mib, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), NULL, &(size))
34 +#define GETSYSCTL(name, mib, var, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), &(var), &(size))
35 +
36 +extern int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len);
37 +
38 +
39 +// =====================================================================================================================
40 +// MacOS
41 +
42 +#elif (TARGET_OS == OS_MACOS)
43 +
44 +#include <sys/sysctl.h>
45 +
46 +#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
47 +extern int getsysctl_by_name(const char *name, void *ptr, size_t len);
48 +
49 +
50 +// =====================================================================================================================
51 +// unknown O/S
52 +
53 +#else
54 +#error unsupported operating system
55 +#endif
56 +
57 +
58 +// =====================================================================================================================
59 +// common for all O/S
60 +
61 +extern int processors;
62 +extern long get_system_cpus(void);
63 +
64 +extern pid_t pid_max;
65 +extern pid_t get_system_pid_max(void);
66 +
67 +extern unsigned int system_hz;
68 +extern void get_system_HZ(void);
69 +
70 +#endif //NETDATA_OS_H
src/libnetdata/popen.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 /*
6 struct mypopen {
src/libnetdata/popen.h renamed
+5
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_POPEN_H
4 #define NETDATA_POPEN_H 1
5
6 +#include "libnetdata.h"
7 +
8 #define PIPE_READ 0
9 #define PIPE_WRITE 1
10
@@ -10,4 +12,7 @@ extern FILE *mypopen(const char *command, volatile pid_t *pidptr);
12 extern FILE *mypopene(const char *command, volatile pid_t *pidptr, char **env);
13 extern int mypclose(FILE *fp, pid_t pid);
14
15 +extern void signals_unblock(void);
16 +extern void signals_reset(void);
17 +
18 #endif /* NETDATA_POPEN_H */
src/libnetdata/procfile.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 #define PF_PREFIX "PROCFILE"
6
src/libnetdata/procfile.h renamed
+3
@@ -1,4 +1,5 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 /*
4 * procfile is a library for reading kernel files from /proc
5 *
@@ -26,6 +27,8 @@
27 #ifndef NETDATA_PROCFILE_H
28 #define NETDATA_PROCFILE_H 1
29
30 +#include "libnetdata.h"
31 +
32 // ----------------------------------------------------------------------------
33 // An array of words
34
src/libnetdata/simple_pattern.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 struct simple_pattern {
6 const char *match;
src/libnetdata/simple_pattern.h renamed
+3
@@ -3,6 +3,9 @@
3 #ifndef NETDATA_SIMPLE_PATTERN_H
4 #define NETDATA_SIMPLE_PATTERN_H
5
6 +#include "libnetdata.h"
7 +
8 +
9 typedef enum {
10 SIMPLE_PATTERN_EXACT,
11 SIMPLE_PATTERN_PREFIX,
src/libnetdata/socket.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // --------------------------------------------------------------------------------------------------------------------
6 // various library calls
src/libnetdata/socket.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_SOCKET_H
4 #define NETDATA_SOCKET_H
5
6 +#include "libnetdata.h"
7 +
8 #ifndef MAX_LISTEN_FDS
9 #define MAX_LISTEN_FDS 50
10 #endif
src/libnetdata/statistical.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // --------------------------------------------------------------------------------------------------------------------
6
src/libnetdata/statistical.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_STATISTICAL_H
4 #define NETDATA_STATISTICAL_H 1
5
6 +#include "libnetdata.h"
7 +
8 extern LONG_DOUBLE average(const LONG_DOUBLE *series, size_t entries);
9 extern LONG_DOUBLE moving_average(const LONG_DOUBLE *series, size_t entries, size_t period);
10 extern LONG_DOUBLE median(const LONG_DOUBLE *series, size_t entries);
src/libnetdata/storage_number.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 storage_number pack_storage_number(calculated_number value, uint32_t flags)
6 {
src/libnetdata/storage_number.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_STORAGE_NUMBER_H
4 #define NETDATA_STORAGE_NUMBER_H 1
5
6 +#include "libnetdata.h"
7 +
8 #ifdef NETDATA_WITHOUT_LONG_DOUBLE
9
10 #define powl pow
src/libnetdata/threads.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 static size_t default_stacksize = 0, wanted_stacksize = 0;
6 static pthread_attr_t *attr = NULL;
src/libnetdata/threads.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_THREADS_H
4 #define NETDATA_THREADS_H 1
5
6 +#include "libnetdata.h"
7 +
8 extern pid_t gettid(void);
9
10 typedef enum {
src/libnetdata/url.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 // ----------------------------------------------------------------------------
6 // URL encode / decode
src/libnetdata/url.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_URL_H
4 #define NETDATA_URL_H 1
5
6 +#include "libnetdata.h"
7 +
8 // ----------------------------------------------------------------------------
9 // URL encode / decode
10 // code from: http://www.geekhideout.com/urlcode.shtml
src/libnetdata/web_buffer.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "libnetdata.h"
4
5 #define BUFFER_OVERFLOW_EOF "EOF"
6
src/libnetdata/web_buffer.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_WEB_BUFFER_H
4 #define NETDATA_WEB_BUFFER_H 1
5
6 +#include "libnetdata.h"
7 +
8 #define WEB_DATA_LENGTH_INCREASE_STEP 1024
9
10 typedef struct web_buffer {
src/main.c
+24 -38
@@ -2,8 +2,6 @@
2
3 #include "common.h"
4
5 -extern void *cgroups_main(void *ptr);
6 -
5 void netdata_cleanup_and_exit(int ret) {
6 // enabling this, is wrong
7 // because the threads will be cancelled while cleaning up
@@ -41,43 +39,31 @@ void netdata_cleanup_and_exit(int ret) {
39
40 struct netdata_static_thread static_threads[] = {
41
44 -#ifdef INTERNAL_PLUGIN_NFACCT
45 - // nfacct requires root access
46 - // so, we build it as an external plugin with setuid to root
47 - {"PLUGIN[nfacct]", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
48 -#endif
49 -
50 -#ifdef NETDATA_INTERNAL_CHECKS
51 - // debugging plugin
52 - {"PLUGIN[check]", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
53 -#endif
42 + NETDATA_PLUGIN_HOOK_CHECKS
43 + NETDATA_PLUGIN_HOOK_FREEBSD
44 + NETDATA_PLUGIN_HOOK_MACOS
45
55 -#if defined(__FreeBSD__)
56 - // FreeBSD internal plugins
57 - {"PLUGIN[freebsd]", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
58 -#elif defined(__APPLE__)
59 - // macOS internal plugins
60 - {"PLUGIN[macos]", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
61 -#else
46 // linux internal plugins
63 - {"PLUGIN[proc]", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
64 - {"PLUGIN[diskspace]", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
65 - {"PLUGIN[cgroup]", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
66 - {"PLUGIN[tc]", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
67 -#endif /* __FreeBSD__, __APPLE__*/
68 -
69 - // common plugins for all systems
70 - {"PLUGIN[idlejitter]", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
71 - {"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
72 - {"HEALTH", NULL, NULL, 1, NULL, NULL, health_main},
73 - {"PLUGINSD", NULL, NULL, 1, NULL, NULL, pluginsd_main},
74 - {"WEB_SERVER[multi]", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
75 - {"WEB_SERVER[single]", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
76 - {"WEB_SERVER[static1]", NULL, NULL, 0, NULL, NULL, socket_listen_main_static_threaded},
77 - {"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
78 - {"STATSD", NULL, NULL, 1, NULL, NULL, statsd_main},
79 -
80 - {NULL, NULL, NULL, 0, NULL, NULL, NULL}
47 + NETDATA_PLUGIN_HOOK_LINUX_NFACCT
48 + NETDATA_PLUGIN_HOOK_LINUX_PROC
49 + NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE
50 + NETDATA_PLUGIN_HOOK_LINUX_CGROUPS
51 + NETDATA_PLUGIN_HOOK_LINUX_TC
52 +
53 + NETDATA_PLUGIN_HOOK_IDLEJITTER
54 + NETDATA_PLUGIN_HOOK_STATSD
55 +
56 + // common plugins for all systems
57 + {"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
58 + {"WEB_SERVER[multi]", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
59 + {"WEB_SERVER[single]", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
60 + {"WEB_SERVER[static1]", NULL, NULL, 0, NULL, NULL, socket_listen_main_static_threaded},
61 + {"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
62 +
63 + NETDATA_PLUGIN_HOOK_PLUGINSD
64 + NETDATA_PLUGIN_HOOK_HEALTH
65 +
66 + {NULL, NULL, NULL, 0, NULL, NULL, NULL}
67 };
68
69 void web_server_threading_selection(void) {
@@ -1053,7 +1039,7 @@ int main(int argc, char **argv) {
1039 if(getrlimit(RLIMIT_NOFILE, &rlimit_nofile) != 0)
1040 error("getrlimit(RLIMIT_NOFILE) failed");
1041 else
1056 - info("resources control: allowed file descriptors: soft = %zu, max = %zu", rlimit_nofile.rlim_cur, rlimit_nofile.rlim_max);
1042 + info("resources control: allowed file descriptors: soft = %zu, max = %zu", (size_t)rlimit_nofile.rlim_cur, (size_t)rlimit_nofile.rlim_max);
1043
1044 // fork, switch user, create pid file, set process priority
1045 if(become_daemon(dont_fork, user) == -1)
src/main.h
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_MAIN_H
4 #define NETDATA_MAIN_H 1
5
6 +#include "common.h"
7 +
8 #define NETDATA_MAIN_THREAD_RUNNING CONFIG_BOOLEAN_YES
9 #define NETDATA_MAIN_THREAD_EXITING (CONFIG_BOOLEAN_YES + 1)
10 #define NETDATA_MAIN_THREAD_EXITED CONFIG_BOOLEAN_NO
src/plugin_checks.h deleted
-10
@@ -1,10 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_CHECKS_H
4 -#define NETDATA_PLUGIN_CHECKS_H 1
5 -
6 -#ifdef NETDATA_INTERNAL_CHECKS
7 -void *checks_main(void *ptr);
8 -#endif // NETDATA_INTERNAL_CHECKS
9 -
10 -#endif /* NETDATA_PLUGIN_PROC_H */
src/plugin_freebsd.h deleted
-132
@@ -1,132 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_FREEBSD_H
4 -#define NETDATA_PLUGIN_FREEBSD_H 1
5 -
6 -#include <sys/sysctl.h>
7 -
8 -#define KILO_FACTOR 1024
9 -#define MEGA_FACTOR 1048576 // 1024 * 1024
10 -#define GIGA_FACTOR 1073741824 // 1024 * 1024 * 1024
11 -
12 -#define MAX_INT_DIGITS 10 // maximum number of digits for int
13 -
14 -void *freebsd_main(void *ptr);
15 -
16 -extern int freebsd_plugin_init();
17 -
18 -extern int do_vm_loadavg(int update_every, usec_t dt);
19 -extern int do_vm_vmtotal(int update_every, usec_t dt);
20 -extern int do_kern_cp_time(int update_every, usec_t dt);
21 -extern int do_kern_cp_times(int update_every, usec_t dt);
22 -extern int do_dev_cpu_temperature(int update_every, usec_t dt);
23 -extern int do_dev_cpu_0_freq(int update_every, usec_t dt);
24 -extern int do_hw_intcnt(int update_every, usec_t dt);
25 -extern int do_vm_stats_sys_v_intr(int update_every, usec_t dt);
26 -extern int do_vm_stats_sys_v_soft(int update_every, usec_t dt);
27 -extern int do_vm_stats_sys_v_swtch(int update_every, usec_t dt);
28 -extern int do_vm_stats_sys_v_forks(int update_every, usec_t dt);
29 -extern int do_vm_swap_info(int update_every, usec_t dt);
30 -extern int do_system_ram(int update_every, usec_t dt);
31 -extern int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt);
32 -extern int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt);
33 -extern int do_kern_ipc_sem(int update_every, usec_t dt);
34 -extern int do_kern_ipc_shm(int update_every, usec_t dt);
35 -extern int do_kern_ipc_msq(int update_every, usec_t dt);
36 -extern int do_uptime(int update_every, usec_t dt);
37 -extern int do_net_isr(int update_every, usec_t dt);
38 -extern int do_net_inet_tcp_states(int update_every, usec_t dt);
39 -extern int do_net_inet_tcp_stats(int update_every, usec_t dt);
40 -extern int do_net_inet_udp_stats(int update_every, usec_t dt);
41 -extern int do_net_inet_icmp_stats(int update_every, usec_t dt);
42 -extern int do_net_inet_ip_stats(int update_every, usec_t dt);
43 -extern int do_net_inet6_ip6_stats(int update_every, usec_t dt);
44 -extern int do_net_inet6_icmp6_stats(int update_every, usec_t dt);
45 -extern int do_getifaddrs(int update_every, usec_t dt);
46 -extern int do_getmntinfo(int update_every, usec_t dt);
47 -extern int do_kern_devstat(int update_every, usec_t dt);
48 -extern int do_kstat_zfs_misc_arcstats(int update_every, usec_t dt);
49 -extern int do_kstat_zfs_misc_zio_trim(int update_every, usec_t dt);
50 -extern int do_ipfw(int update_every, usec_t dt);
51 -
52 -#define GETSYSCTL_MIB(name, mib) getsysctl_mib(name, mib, sizeof(mib)/sizeof(int))
53 -
54 -static inline int getsysctl_mib(const char *name, int *mib, size_t len)
55 -{
56 - size_t nlen = len;
57 -
58 - if (unlikely(sysctlnametomib(name, mib, &nlen) == -1)) {
59 - error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
60 - return 1;
61 - }
62 - if (unlikely(nlen != len)) {
63 - error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
64 - return 1;
65 - }
66 - return 0;
67 -}
68 -
69 -#define GETSYSCTL_SIMPLE(name, mib, var) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), &(var), sizeof(var))
70 -#define GETSYSCTL_WSIZE(name, mib, var, size) getsysctl_simple(name, mib, sizeof(mib)/sizeof(int), var, size)
71 -
72 -static inline int getsysctl_simple(const char *name, int *mib, size_t miblen, void *ptr, size_t len)
73 -{
74 - size_t nlen = len;
75 -
76 - if (unlikely(!mib[0]))
77 - if (unlikely(getsysctl_mib(name, mib, miblen)))
78 - return 1;
79 -
80 - if (unlikely(sysctl(mib, miblen, ptr, &nlen, NULL, 0) == -1)) {
81 - error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
82 - return 1;
83 - }
84 - if (unlikely(nlen != len)) {
85 - error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
86 - return 1;
87 - }
88 -
89 - return 0;
90 -}
91 -
92 -#define GETSYSCTL_SIZE(name, mib, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), NULL, &(size))
93 -#define GETSYSCTL(name, mib, var, size) getsysctl(name, mib, sizeof(mib)/sizeof(int), &(var), &(size))
94 -
95 -static inline int getsysctl(const char *name, int *mib, size_t miblen, void *ptr, size_t *len)
96 -{
97 - size_t nlen = *len;
98 -
99 - if (unlikely(!mib[0]))
100 - if (unlikely(getsysctl_mib(name, mib, miblen)))
101 - return 1;
102 -
103 - if (unlikely(sysctl(mib, miblen, ptr, len, NULL, 0) == -1)) {
104 - error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
105 - return 1;
106 - }
107 - if (unlikely(ptr != NULL && nlen != *len)) {
108 - error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)*len, (unsigned long)nlen);
109 - return 1;
110 - }
111 -
112 - return 0;
113 -}
114 -
115 -#define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
116 -
117 -static inline int getsysctl_by_name(const char *name, void *ptr, size_t len)
118 -{
119 - size_t nlen = len;
120 -
121 - if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
122 - error("FREEBSD: sysctl(%s...) failed: %s", name, strerror(errno));
123 - return 1;
124 - }
125 - if (unlikely(nlen != len)) {
126 - error("FREEBSD: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
127 - return 1;
128 - }
129 - return 0;
130 -}
131 -
132 -#endif /* NETDATA_PLUGIN_FREEBSD_H */
src/plugin_idlejitter.h deleted
-8
@@ -1,8 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_IDLEJITTER_H
4 -#define NETDATA_PLUGIN_IDLEJITTER_H 1
5 -
6 -extern void *cpuidlejitter_main(void *ptr);
7 -
8 -#endif /* NETDATA_PLUGIN_IDLEJITTER_H */
src/plugin_nfacct.h deleted
-9
@@ -1,9 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_NFACCT_H
4 -#define NETDATA_NFACCT_H 1
5 -
6 -extern void *nfacct_main(void *ptr);
7 -
8 -#endif /* NETDATA_NFACCT_H */
9 -
src/plugin_proc_diskspace.h deleted
-8
@@ -1,8 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_PROC_DISKSPACE_H
4 -#define NETDATA_PLUGIN_PROC_DISKSPACE_H
5 -
6 -extern void *proc_diskspace_main(void *ptr);
7 -
8 -#endif //NETDATA_PLUGIN_PROC_DISKSPACE_H
src/plugin_tc.h deleted
-9
@@ -1,9 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_PLUGIN_TC_H
4 -#define NETDATA_PLUGIN_TC_H 1
5 -
6 -extern void *tc_main(void *ptr);
7 -
8 -#endif /* NETDATA_PLUGIN_TC_H */
9 -
src/plugins/Makefile.am new
+38
@@ -0,0 +1,38 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +MAINTAINERCLEANFILES = Makefile.in
4 +
5 +SUBDIRS = \
6 + apps.plugin \
7 + checks.plugin \
8 + idlejitter.plugin \
9 + plugins.d.plugin \
10 + statsd.plugin \
11 + $(NULL)
12 +
13 +if FREEBSD
14 +
15 +SUBDIRS += \
16 + freebsd.plugin \
17 + $(NULL)
18 +
19 +else
20 +if MACOS
21 +
22 +SUBDIRS += \
23 + macos.plugin \
24 + $(NULL)
25 +
26 +else
27 +
28 +SUBDIRS += \
29 + linux-cgroups.plugin \
30 + linux-diskspace.plugin \
31 + linux-freeipmi.plugin \
32 + linux-nfacct.plugin \
33 + linux-proc.plugin \
34 + linux-tc.plugin \
35 + $(NULL)
36 +
37 +endif
38 +endif
src/plugins/all.h new
+103
@@ -0,0 +1,103 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_ALL_H
4 +#define NETDATA_ALL_H 1
5 +
6 +#include "../common.h"
7 +
8 +// netdata internal data collection plugins
9 +
10 +#include "checks.plugin/plugin_checks.h"
11 +#include "freebsd.plugin/plugin_freebsd.h"
12 +#include "idlejitter.plugin/plugin_idlejitter.h"
13 +#include "linux-cgroups.plugin/sys_fs_cgroup.h"
14 +#include "linux-diskspace.plugin/plugin_diskspace.h"
15 +#include "linux-nfacct.plugin/plugin_nfacct.h"
16 +#include "linux-proc.plugin/plugin_proc.h"
17 +#include "linux-tc.plugin/plugin_tc.h"
18 +#include "macos.plugin/plugin_macos.h"
19 +#include "plugins.d.plugin/plugins_d.h"
20 +#include "statsd.plugin/statsd.h"
21 +
22 +
23 +// ----------------------------------------------------------------------------
24 +// netdata chart priorities
25 +
26 +// This is a work in progress - to scope is to collect here all chart priorities.
27 +// These should be based on the CONTEXT of the charts + the chart id when needed
28 +// - for each SECTION +1000 (or +X000 for big sections)
29 +// - for each FAMILY +100
30 +// - for each CHART +10
31 +
32 +#define NETDATA_CHART_PRIO_SYSTEM_IP 501
33 +#define NETDATA_CHART_PRIO_SYSTEM_IPV6 502
34 +
35 +// Memory Section - 1xxx
36 +#define NETDATA_CHART_PRIO_MEM_SYSTEM 1000
37 +#define NETDATA_CHART_PRIO_MEM_SYSTEM_AVAILABLE 1010
38 +#define NETDATA_CHART_PRIO_MEM_SYSTEM_COMMITTED 1020
39 +#define NETDATA_CHART_PRIO_MEM_SYSTEM_PGFAULTS 1030
40 +#define NETDATA_CHART_PRIO_MEM_KERNEL 1100
41 +#define NETDATA_CHART_PRIO_MEM_SLAB 1200
42 +#define NETDATA_CHART_PRIO_MEM_HUGEPAGES 1250
43 +#define NETDATA_CHART_PRIO_MEM_KSM 1300
44 +#define NETDATA_CHART_PRIO_MEM_NUMA 1400
45 +#define NETDATA_CHART_PRIO_MEM_HW 1500
46 +
47 +
48 +// IP
49 +
50 +#define NETDATA_CHART_PRIO_IP 4000
51 +#define NETDATA_CHART_PRIO_IP_ERRORS 4100
52 +#define NETDATA_CHART_PRIO_IP_TCP 4200
53 +#define NETDATA_CHART_PRIO_IP_TCP_MEM 4290
54 +#define NETDATA_CHART_PRIO_IP_BCAST 4500
55 +#define NETDATA_CHART_PRIO_IP_MCAST 4600
56 +#define NETDATA_CHART_PRIO_IP_ECN 4700
57 +
58 +
59 +// IPv4
60 +
61 +#define NETDATA_CHART_PRIO_IPV4 5100
62 +#define NETDATA_CHART_PRIO_IPV4_SOCKETS 5100
63 +#define NETDATA_CHART_PRIO_IPV4_PACKETS 5130
64 +#define NETDATA_CHART_PRIO_IPV4_ERRORS 5150
65 +#define NETDATA_CHART_PRIO_IPV4_ICMP 5170
66 +#define NETDATA_CHART_PRIO_IPV4_TCP 5200
67 +#define NETDATA_CHART_PRIO_IPV4_TCP_MEM 5290
68 +#define NETDATA_CHART_PRIO_IPV4_UDP 5300
69 +#define NETDATA_CHART_PRIO_IPV4_UDP_MEM 5390
70 +#define NETDATA_CHART_PRIO_IPV4_UDPLITE 5400
71 +#define NETDATA_CHART_PRIO_IPV4_RAW 5450
72 +#define NETDATA_CHART_PRIO_IPV4_FRAGMENTS 5460
73 +#define NETDATA_CHART_PRIO_IPV4_FRAGMENTS_MEM 5470
74 +
75 +// IPv6
76 +
77 +#define NETDATA_CHART_PRIO_IPV6 6200
78 +#define NETDATA_CHART_PRIO_IPV6_PACKETS 6200
79 +#define NETDATA_CHART_PRIO_IPV6_ERRORS 6300
80 +#define NETDATA_CHART_PRIO_IPV6_FRAGMENTS 6400
81 +#define NETDATA_CHART_PRIO_IPV6_TCP 6500
82 +#define NETDATA_CHART_PRIO_IPV6_UDP 6600
83 +#define NETDATA_CHART_PRIO_IPV6_UDP_ERRORS 6610
84 +#define NETDATA_CHART_PRIO_IPV6_UDPLITE 6700
85 +#define NETDATA_CHART_PRIO_IPV6_UDPLITE_ERRORS 6710
86 +#define NETDATA_CHART_PRIO_IPV6_RAW 6800
87 +#define NETDATA_CHART_PRIO_IPV6_BCAST 6840
88 +#define NETDATA_CHART_PRIO_IPV6_MCAST 6850
89 +#define NETDATA_CHART_PRIO_IPV6_ICMP 6900
90 +
91 +
92 +// SCTP
93 +
94 +#define NETDATA_CHART_PRIO_SCTP 7000
95 +
96 +
97 +// Netfilter
98 +
99 +#define NETDATA_CHART_PRIO_NETFILTER 8700
100 +#define NETDATA_CHART_PRIO_SYNPROXY 8750
101 +
102 +
103 +#endif //NETDATA_ALL_H
src/plugins/apps.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/apps.plugin/apps_plugin.c renamed
+26 -11
@@ -6,7 +6,32 @@
6 * Released under GPL v3+
7 */
8
9 -#include "common.h"
9 +#include "../../libnetdata/libnetdata.h"
10 +
11 +// ----------------------------------------------------------------------------
12 +
13 +// callback required by fatal()
14 +void netdata_cleanup_and_exit(int ret) {
15 + exit(ret);
16 +}
17 +
18 +// callbacks required by popen()
19 +void signals_block(void) {};
20 +void signals_unblock(void) {};
21 +void signals_reset(void) {};
22 +
23 +// callback required by eval()
24 +int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
25 + (void)variable;
26 + (void)hash;
27 + (void)rc;
28 + (void)result;
29 + return 0;
30 +};
31 +
32 +// required by get_system_cpus()
33 +char *netdata_configured_host_prefix = "";
34 +
35
36 // ----------------------------------------------------------------------------
37 // debugging
@@ -99,7 +124,6 @@ static int
124 enable_groups_charts = 1,
125 include_exited_childs = 1;
126
102 -
127 // will be changed to getenv(NETDATA_USER_CONFIG_DIR) if it exists
128 static char *user_config_dir = CONFIG_DIR;
129 static char *stock_config_dir = LIBCONFIG_DIR;
@@ -461,13 +485,6 @@ static int
485 all_files_len = 0,
486 all_files_size = 0;
487
464 -// ----------------------------------------------------------------------------
465 -// callback required by fatal()
466 -
467 -void netdata_cleanup_and_exit(int ret) {
468 - exit(ret);
469 -}
470 -
488 // ----------------------------------------------------------------------------
489 // apps_groups.conf
490 // aggregate all processes in groups, to have a limited number of dimensions
@@ -2806,8 +2823,6 @@ static void calculate_netdata_statistics(void) {
2823 // ----------------------------------------------------------------------------
2824 // update chart dimensions
2825
2809 -int print_calculated_number(char *str, calculated_number value) { (void)str; (void)value; return 0; }
2810 -
2826 static inline void send_BEGIN(const char *type, const char *id, usec_t usec) {
2827 fprintf(stdout, "BEGIN %s.%s %llu\n", type, id, usec);
2828 }
src/plugins/checks.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/checks.plugin/plugin_checks.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_checks.h"
4
5 #ifdef NETDATA_INTERNAL_CHECKS
6
src/plugins/checks.plugin/plugin_checks.h new
+29
@@ -0,0 +1,29 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_PLUGIN_CHECKS_H
4 +#define NETDATA_PLUGIN_CHECKS_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#ifdef NETDATA_INTERNAL_CHECKS
9 +
10 +#define NETDATA_PLUGIN_HOOK_CHECKS \
11 + { \
12 + .name = "PLUGIN[check]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "checks", \
15 + .enabled = 0, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = checks_main \
19 + },
20 +
21 +extern void *checks_main(void *ptr);
22 +
23 +#else // !NETDATA_INTERNAL_CHECKS
24 +
25 +#define NETDATA_PLUGIN_HOOK_CHECKS
26 +
27 +#endif // NETDATA_INTERNAL_CHECKS
28 +
29 +#endif // NETDATA_PLUGIN_CHECKS_H
src/plugins/freebsd.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/freebsd.plugin/freebsd_devstat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 #include <sys/devicestat.h>
6
src/plugins/freebsd.plugin/freebsd_getifaddrs.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 #include <ifaddrs.h>
6
src/plugins/freebsd.plugin/freebsd_getmntinfo.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 #include <sys/mount.h>
6
src/plugins/freebsd.plugin/freebsd_ipfw.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 #include <netinet/ip_fw.h>
6
src/plugins/freebsd.plugin/freebsd_kstat_zfs.c renamed
+2 -3
@@ -1,8 +1,7 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
4 -
5 -#include "zfs_common.h"
3 +#include "plugin_freebsd.h"
4 +#include "../linux-proc.plugin/zfs_common.h"
5
6 extern struct arcstats arcstats;
7
src/plugins/freebsd.plugin/freebsd_sysctl.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 #include <sys/vmmeter.h>
6 #include <vm/vm_param.h>
src/plugins/freebsd.plugin/plugin_freebsd.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_freebsd.h"
4
5 static struct freebsd_module {
6 const char *name;
src/plugins/freebsd.plugin/plugin_freebsd.h new
+74
@@ -0,0 +1,74 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_PLUGIN_FREEBSD_H
4 +#define NETDATA_PLUGIN_FREEBSD_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#if (TARGET_OS == OS_FREEBSD)
9 +
10 +#define NETDATA_PLUGIN_HOOK_FREEBSD \
11 + { \
12 + .name = "PLUGIN[freebsd]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "freebsd", \
15 + .enabled = 1, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = freebsd_main \
19 + },
20 +
21 +
22 +#include <sys/sysctl.h>
23 +
24 +#define KILO_FACTOR 1024
25 +#define MEGA_FACTOR 1048576 // 1024 * 1024
26 +#define GIGA_FACTOR 1073741824 // 1024 * 1024 * 1024
27 +
28 +#define MAX_INT_DIGITS 10 // maximum number of digits for int
29 +
30 +void *freebsd_main(void *ptr);
31 +
32 +extern int freebsd_plugin_init();
33 +
34 +extern int do_vm_loadavg(int update_every, usec_t dt);
35 +extern int do_vm_vmtotal(int update_every, usec_t dt);
36 +extern int do_kern_cp_time(int update_every, usec_t dt);
37 +extern int do_kern_cp_times(int update_every, usec_t dt);
38 +extern int do_dev_cpu_temperature(int update_every, usec_t dt);
39 +extern int do_dev_cpu_0_freq(int update_every, usec_t dt);
40 +extern int do_hw_intcnt(int update_every, usec_t dt);
41 +extern int do_vm_stats_sys_v_intr(int update_every, usec_t dt);
42 +extern int do_vm_stats_sys_v_soft(int update_every, usec_t dt);
43 +extern int do_vm_stats_sys_v_swtch(int update_every, usec_t dt);
44 +extern int do_vm_stats_sys_v_forks(int update_every, usec_t dt);
45 +extern int do_vm_swap_info(int update_every, usec_t dt);
46 +extern int do_system_ram(int update_every, usec_t dt);
47 +extern int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt);
48 +extern int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt);
49 +extern int do_kern_ipc_sem(int update_every, usec_t dt);
50 +extern int do_kern_ipc_shm(int update_every, usec_t dt);
51 +extern int do_kern_ipc_msq(int update_every, usec_t dt);
52 +extern int do_uptime(int update_every, usec_t dt);
53 +extern int do_net_isr(int update_every, usec_t dt);
54 +extern int do_net_inet_tcp_states(int update_every, usec_t dt);
55 +extern int do_net_inet_tcp_stats(int update_every, usec_t dt);
56 +extern int do_net_inet_udp_stats(int update_every, usec_t dt);
57 +extern int do_net_inet_icmp_stats(int update_every, usec_t dt);
58 +extern int do_net_inet_ip_stats(int update_every, usec_t dt);
59 +extern int do_net_inet6_ip6_stats(int update_every, usec_t dt);
60 +extern int do_net_inet6_icmp6_stats(int update_every, usec_t dt);
61 +extern int do_getifaddrs(int update_every, usec_t dt);
62 +extern int do_getmntinfo(int update_every, usec_t dt);
63 +extern int do_kern_devstat(int update_every, usec_t dt);
64 +extern int do_kstat_zfs_misc_arcstats(int update_every, usec_t dt);
65 +extern int do_kstat_zfs_misc_zio_trim(int update_every, usec_t dt);
66 +extern int do_ipfw(int update_every, usec_t dt);
67 +
68 +#else // (TARGET_OS == OS_FREEBSD)
69 +
70 +#define NETDATA_PLUGIN_HOOK_FREEBSD
71 +
72 +#endif // (TARGET_OS == OS_FREEBSD)
73 +
74 +#endif /* NETDATA_PLUGIN_FREEBSD_H */
src/plugins/idlejitter.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/idlejitter.plugin/plugin_idlejitter.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_idlejitter.h"
4
5 #define CPU_IDLEJITTER_SLEEP_TIME_MS 20
6
src/plugins/idlejitter.plugin/plugin_idlejitter.h new
+21
@@ -0,0 +1,21 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_PLUGIN_IDLEJITTER_H
4 +#define NETDATA_PLUGIN_IDLEJITTER_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#define NETDATA_PLUGIN_HOOK_IDLEJITTER \
9 + { \
10 + .name = "PLUGIN[idlejitter]", \
11 + .config_section = CONFIG_SECTION_PLUGINS, \
12 + .config_name = "idlejitter", \
13 + .enabled = 1, \
14 + .thread = NULL, \
15 + .init_routine = NULL, \
16 + .start_routine = cpuidlejitter_main \
17 + },
18 +
19 +extern void *cpuidlejitter_main(void *ptr);
20 +
21 +#endif /* NETDATA_PLUGIN_IDLEJITTER_H */
src/plugins/linux-cgroups.plugin/Makefile.am new
+28
@@ -0,0 +1,28 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
6 +CLEANFILES = \
7 + cgroup-name.sh \
8 + $(NULL)
9 +
10 +cgroup-name.sh: cgroup-name.sh.in
11 + if sed \
12 + -e 's#[@]configdir_POST@#$(configdir)#g' \
13 + -e 's#[@]libconfigdir_POST@#$(libconfigdir)#g' \
14 + $< > $@.tmp; then \
15 + mv "$@.tmp" "$@"; \
16 + else \
17 + rm -f "$@.tmp"; \
18 + false; \
19 + fi
20 +
21 +dist_plugins_SCRIPTS = \
22 + cgroup-name.sh \
23 + cgroup-network-helper.sh \
24 + $(NULL)
25 +
26 +dist_noinst_DATA = \
27 + cgroup-name.sh.in \
28 + $(NULL)
src/plugins/linux-cgroups.plugin/cgroup-name.sh.in renamed
src/plugins/linux-cgroups.plugin/cgroup-network-helper.sh renamed
src/plugins/linux-cgroups.plugin/cgroup-network.c renamed
+18 -5
@@ -1,7 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
4 -#include <libgen.h>
3 +#include "../../common.h"
4
5 #ifdef HAVE_SETNS
6 #ifndef _GNU_SOURCE
@@ -19,14 +18,28 @@ char *environment[] = {
18
19
20 // ----------------------------------------------------------------------------
22 -// callback required by fatal()
21
22 +// callback required by fatal()
23 void netdata_cleanup_and_exit(int ret) {
24 exit(ret);
25 }
27 -void health_reload(void) {};
28 -void rrdhost_save_all(void) {};
26
27 +// callbacks required by popen()
28 +void signals_block(void) {};
29 +void signals_unblock(void) {};
30 +void signals_reset(void) {};
31 +
32 +// callback required by eval()
33 +int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
34 + (void)variable;
35 + (void)hash;
36 + (void)rc;
37 + (void)result;
38 + return 0;
39 +};
40 +
41 +// required by get_system_cpus()
42 +char *netdata_configured_host_prefix = "";
43
44 // ----------------------------------------------------------------------------
45
src/plugins/linux-cgroups.plugin/sys_fs_cgroup.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "sys_fs_cgroup.h"
4
5 // ----------------------------------------------------------------------------
6 // cgroup globals
src/plugins/linux-cgroups.plugin/sys_fs_cgroup.h new
+31
@@ -0,0 +1,31 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_SYS_FS_CGROUP_H
4 +#define NETDATA_SYS_FS_CGROUP_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#if (TARGET_OS == OS_LINUX)
9 +
10 +#define NETDATA_PLUGIN_HOOK_LINUX_CGROUPS \
11 + { \
12 + .name = "PLUGIN[cgroup]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "cgroups", \
15 + .enabled = 1, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = cgroups_main \
19 + },
20 +
21 +extern void *cgroups_main(void *ptr);
22 +
23 +#include "../linux-proc.plugin/plugin_proc.h"
24 +
25 +#else // (TARGET_OS == OS_LINUX)
26 +
27 +#define NETDATA_PLUGIN_HOOK_LINUX_CGROUPS
28 +
29 +#endif // (TARGET_OS == OS_LINUX)
30 +
31 +#endif //NETDATA_SYS_FS_CGROUP_H
src/plugins/linux-diskspace.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/linux-diskspace.plugin/plugin_diskspace.c renamed
+2 -2
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_diskspace.h"
4
5 #define DELAULT_EXCLUDED_PATHS "/proc/* /sys/* /var/run/user/* /run/user/* /snap/* /var/lib/docker/*"
6 #define DEFAULT_EXCLUDED_FILESYSTEMS "*gvfs *gluster* *s3fs *ipfs *davfs2 *httpfs *sshfs *gdfs *moosefs fusectl"
@@ -339,7 +339,7 @@ static void diskspace_main_cleanup(void *ptr) {
339 static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
340 }
341
342 -void *proc_diskspace_main(void *ptr) {
342 +void *diskspace_main(void *ptr) {
343 netdata_thread_cleanup_push(diskspace_main_cleanup, ptr);
344
345 int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
src/plugins/linux-diskspace.plugin/plugin_diskspace.h new
+34
@@ -0,0 +1,34 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_PLUGIN_PROC_DISKSPACE_H
4 +#define NETDATA_PLUGIN_PROC_DISKSPACE_H
5 +
6 +#include "../../common.h"
7 +
8 +
9 +#if (TARGET_OS == OS_LINUX)
10 +
11 +#define NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE \
12 + { \
13 + .name = "PLUGIN[diskspace]", \
14 + .config_section = CONFIG_SECTION_PLUGINS, \
15 + .config_name = "diskspace", \
16 + .enabled = 1, \
17 + .thread = NULL, \
18 + .init_routine = NULL, \
19 + .start_routine = diskspace_main \
20 + },
21 +
22 +extern void *diskspace_main(void *ptr);
23 +
24 +#include "../linux-proc.plugin/plugin_proc.h"
25 +
26 +#else // (TARGET_OS == OS_LINUX)
27 +
28 +#define NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE
29 +
30 +#endif // (TARGET_OS == OS_LINUX)
31 +
32 +
33 +
34 +#endif //NETDATA_PLUGIN_PROC_DISKSPACE_H
src/plugins/linux-freeipmi.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/linux-freeipmi.plugin/freeipmi_plugin.c renamed
+27 -5
@@ -15,7 +15,7 @@
15 * UCRL-CODE-222073
16 */
17
18 -#include "common.h"
18 +#include "../../libnetdata/libnetdata.h"
19
20 #include <stdio.h>
21 #include <stdlib.h>
@@ -28,6 +28,32 @@
28
29 #ifdef HAVE_FREEIPMI
30
31 +// ----------------------------------------------------------------------------
32 +
33 +// callback required by fatal()
34 +void netdata_cleanup_and_exit(int ret) {
35 + exit(ret);
36 +}
37 +
38 +// callbacks required by popen()
39 +void signals_block(void) {};
40 +void signals_unblock(void) {};
41 +void signals_reset(void) {};
42 +
43 +// callback required by eval()
44 +int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) {
45 + (void)variable;
46 + (void)hash;
47 + (void)rc;
48 + (void)result;
49 + return 0;
50 +};
51 +
52 +// required by get_system_cpus()
53 +char *netdata_configured_host_prefix = "";
54 +
55 +// ----------------------------------------------------------------------------
56 +
57 #include <ipmi_monitoring.h>
58 #include <ipmi_monitoring_bitmasks.h>
59
@@ -723,10 +749,6 @@ static void netdata_get_sel(
749 }
750
751
726 -void netdata_cleanup_and_exit(int ret) {
727 - exit(ret);
728 -}
729 -
752 // END NETDATA CODE
753 // ----------------------------------------------------------------------------
754
src/plugins/linux-nfacct.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/linux-nfacct.plugin/plugin_nfacct.c renamed
+2 -2
@@ -1,8 +1,8 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_nfacct.h"
4
5 -#ifdef INTERNAL_PLUGIN_NFACCT
5 +#if defined(INTERNAL_PLUGIN_NFACCT)
6
7 #ifdef HAVE_LIBMNL
8 #include <libmnl/libmnl.h>
src/plugins/linux-nfacct.plugin/plugin_nfacct.h new
+30
@@ -0,0 +1,30 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_NFACCT_H
4 +#define NETDATA_NFACCT_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#if defined(INTERNAL_PLUGIN_NFACCT)
9 +
10 +#define NETDATA_PLUGIN_HOOK_LINUX_NFACCT \
11 + { \
12 + .name = "PLUGIN[nfacct]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "nfacct", \
15 + .enabled = 1, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = nfacct_main \
19 + },
20 +
21 +extern void *nfacct_main(void *ptr);
22 +
23 +#else // !defined(INTERNAL_PLUGIN_NFACCT)
24 +
25 +#define NETDATA_PLUGIN_HOOK_LINUX_NFACCT
26 +
27 +#endif // defined(INTERNAL_PLUGIN_NFACCT)
28 +
29 +#endif /* NETDATA_NFACCT_H */
30 +
src/plugins/linux-proc.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/linux-proc.plugin/ipc.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #include <sys/sem.h>
6 #include <sys/msg.h>
src/plugins/linux-proc.plugin/plugin_proc.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 static struct proc_module {
6 const char *name;
src/plugins/linux-proc.plugin/plugin_proc.h renamed
+27 -2
@@ -3,7 +3,22 @@
3 #ifndef NETDATA_PLUGIN_PROC_H
4 #define NETDATA_PLUGIN_PROC_H 1
5
6 -void *proc_main(void *ptr);
6 +#include "../../common.h"
7 +
8 +#if (TARGET_OS == OS_LINUX)
9 +
10 +#define NETDATA_PLUGIN_HOOK_LINUX_PROC \
11 + { \
12 + .name = "PLUGIN[proc]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "proc", \
15 + .enabled = 1, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = proc_main \
19 + },
20 +
21 +extern void *proc_main(void *ptr);
22
23 extern int do_proc_net_dev(int update_every, usec_t dt);
24 extern int do_proc_diskstats(int update_every, usec_t dt);
@@ -32,7 +47,7 @@ extern int do_sys_fs_btrfs(int update_every, usec_t dt);
47 extern int do_proc_net_sockstat(int update_every, usec_t dt);
48 extern int do_proc_net_sockstat6(int update_every, usec_t dt);
49 extern int do_proc_net_sctp_snmp(int update_every, usec_t dt);
35 -
50 +extern int do_ipc(int update_every, usec_t dt);
51 extern int get_numa_node_count(void);
52
53 // metrics that need to be shared among data collectors
@@ -42,4 +57,14 @@ extern unsigned long long tcpext_TCPSynRetrans;
57 extern void netdev_rename_device_add(const char *host_device, const char *container_device, const char *container_name);
58 extern void netdev_rename_device_del(const char *host_device);
59
60 +#include "proc_self_mountinfo.h"
61 +#include "zfs_common.h"
62 +
63 +#else // (TARGET_OS == OS_LINUX)
64 +
65 +#define NETDATA_PLUGIN_HOOK_LINUX_PROC
66 +
67 +#endif // (TARGET_OS == OS_LINUX)
68 +
69 +
70 #endif /* NETDATA_PLUGIN_PROC_H */
src/plugins/linux-proc.plugin/proc_diskstats.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_DISK "disk"
6
src/plugins/linux-proc.plugin/proc_interrupts.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define MAX_INTERRUPT_NAME 50
6
src/plugins/linux-proc.plugin/proc_loadavg.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 // linux calculates this once every 5 seconds
6 #define MIN_LOADAVG_UPDATE_EVERY 5
src/plugins/linux-proc.plugin/proc_meminfo.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 int do_proc_meminfo(int update_every, usec_t dt) {
6 (void)dt;
src/plugins/linux-proc.plugin/proc_net_dev.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 // ----------------------------------------------------------------------------
6 // netdev list
src/plugins/linux-proc.plugin/proc_net_ip_vs_stats.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_IPVS "ipvs"
6
src/plugins/linux-proc.plugin/proc_net_netstat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_NETSTAT "ip"
6
src/plugins/linux-proc.plugin/proc_net_rpc_nfs.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 struct nfs_procs {
6 char name[30];
src/plugins/linux-proc.plugin/proc_net_rpc_nfsd.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 struct nfsd_procs {
6 char name[30];
src/plugins/linux-proc.plugin/proc_net_sctp_snmp.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 int do_proc_net_sctp_snmp(int update_every, usec_t dt) {
6 (void)dt;
src/plugins/linux-proc.plugin/proc_net_snmp.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_SNMP "ipv4"
6
src/plugins/linux-proc.plugin/proc_net_snmp6.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_SNMP6 "ipv6"
6
src/plugins/linux-proc.plugin/proc_net_sockstat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 static struct proc_net_sockstat {
6 kernel_uint_t sockets_used;
src/plugins/linux-proc.plugin/proc_net_sockstat6.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 static struct proc_net_sockstat6 {
6 kernel_uint_t tcp6_inuse;
src/plugins/linux-proc.plugin/proc_net_softnet_stat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 static inline char *softnet_column_name(size_t column) {
6 switch(column) {
src/plugins/linux-proc.plugin/proc_net_stat_conntrack.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_STAT_NETFILTER "netfilter"
6 #define RRD_TYPE_NET_STAT_CONNTRACK "conntrack"
src/plugins/linux-proc.plugin/proc_net_stat_synproxy.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define RRD_TYPE_NET_STAT_NETFILTER "netfilter"
6 #define RRD_TYPE_NET_STAT_SYNPROXY "synproxy"
src/plugins/linux-proc.plugin/proc_self_mountinfo.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 // ----------------------------------------------------------------------------
6 // taken from gnulib/mountlist.c
src/plugins/linux-proc.plugin/proc_self_mountinfo.h renamed
src/plugins/linux-proc.plugin/proc_softirqs.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 #define MAX_INTERRUPT_NAME 50
6
src/plugins/linux-proc.plugin/proc_spl_kstat_zfs.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4 #include "zfs_common.h"
5
6 #define ZFS_PROC_ARCSTATS "/proc/spl/kstat/zfs/arcstats"
src/plugins/linux-proc.plugin/proc_stat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 struct per_core_single_number_file {
6 unsigned char found:1;
src/plugins/linux-proc.plugin/proc_sys_kernel_random_entropy_avail.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 int do_proc_sys_kernel_random_entropy_avail(int update_every, usec_t dt) {
6 (void)dt;
src/plugins/linux-proc.plugin/proc_uptime.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 static inline collected_number uptime_from_boottime(void) {
6 #ifdef CLOCK_BOOTTIME_IS_AVAILABLE
src/plugins/linux-proc.plugin/proc_vmstat.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 int do_proc_vmstat(int update_every, usec_t dt) {
6 (void)dt;
src/plugins/linux-proc.plugin/sys_devices_system_edac_mc.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 struct mc {
6 char *name;
src/plugins/linux-proc.plugin/sys_devices_system_node.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 struct node {
6 char *name;
src/plugins/linux-proc.plugin/sys_fs_btrfs.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 typedef struct btrfs_disk {
6 char *name;
src/plugins/linux-proc.plugin/sys_kernel_mm_ksm.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_proc.h"
4
5 typedef struct ksm_name_value {
6 char filename[FILENAME_MAX + 1];
src/plugins/linux-proc.plugin/zfs_common.c renamed
-1
@@ -1,6 +1,5 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 #include "zfs_common.h"
4
5 struct arcstats arcstats = { 0 };
src/plugins/linux-proc.plugin/zfs_common.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_ZFS_COMMON_H
4 #define NETDATA_ZFS_COMMON_H 1
5
6 +#include "../../common.h"
7 +
8 #define ZFS_FAMILY_SIZE "size"
9 #define ZFS_FAMILY_EFFICIENCY "efficiency"
10 #define ZFS_FAMILY_ACCESSES "accesses"
src/plugins/linux-tc.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/linux-tc.plugin/plugin_tc.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_tc.h"
4
5 #define RRD_TYPE_TC "tc"
6
src/plugins/linux-tc.plugin/plugin_tc.h new
+31
@@ -0,0 +1,31 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_PLUGIN_TC_H
4 +#define NETDATA_PLUGIN_TC_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#if (TARGET_OS == OS_LINUX)
9 +
10 +#define NETDATA_PLUGIN_HOOK_LINUX_TC \
11 + { \
12 + .name = "PLUGIN[tc]", \
13 + .config_section = CONFIG_SECTION_PLUGINS, \
14 + .config_name = "tc", \
15 + .enabled = 1, \
16 + .thread = NULL, \
17 + .init_routine = NULL, \
18 + .start_routine = tc_main \
19 + },
20 +
21 +extern void *tc_main(void *ptr);
22 +
23 +#else // (TARGET_OS == OS_LINUX)
24 +
25 +#define NETDATA_PLUGIN_HOOK_LINUX_TC
26 +
27 +#endif // (TARGET_OS == OS_LINUX)
28 +
29 +
30 +#endif /* NETDATA_PLUGIN_TC_H */
31 +
src/plugins/macos.plugin/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/plugins/macos.plugin/macos_fw.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_macos.h"
4
5 #include <CoreFoundation/CoreFoundation.h>
6 #include <IOKit/IOKitLib.h>
src/plugins/macos.plugin/macos_mach_smi.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_macos.h"
4
5 #include <mach/mach.h>
6
src/plugins/macos.plugin/macos_sysctl.c renamed
+1 -16
@@ -1,9 +1,8 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_macos.h"
4
5 #include <Availability.h>
6 -#include <sys/sysctl.h>
6 // NEEDED BY: do_bandwidth
7 #include <net/route.h>
8 // NEEDED BY do_tcp...
@@ -1491,17 +1490,3 @@ int do_macos_sysctl(int update_every, usec_t dt) {
1490 return 0;
1491 }
1492
1494 -int getsysctl_by_name(const char *name, void *ptr, size_t len)
1495 -{
1496 - size_t nlen = len;
1497 -
1498 - if (unlikely(sysctlbyname(name, ptr, &nlen, NULL, 0) == -1)) {
1499 - error("MACOS: sysctl(%s...) failed: %s", name, strerror(errno));
1500 - return 1;
1501 - }
1502 - if (unlikely(nlen != len)) {
1503 - error("MACOS: sysctl(%s...) expected %lu, got %lu", name, (unsigned long)len, (unsigned long)nlen);
1504 - return 1;
1505 - }
1506 - return 0;
1507 -}
src/plugins/macos.plugin/plugin_macos.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugin_macos.h"
4
5 static void macos_main_cleanup(void *ptr) {
6 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
src/plugins/macos.plugin/plugin_macos.h renamed
+27
@@ -1,8 +1,24 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 +
4 #ifndef NETDATA_PLUGIN_MACOS_H
5 #define NETDATA_PLUGIN_MACOS_H 1
6
7 +#include "../../common.h"
8 +
9 +#if (TARGET_OS == OS_MACOS)
10 +
11 +#define NETDATA_PLUGIN_HOOK_MACOS \
12 + { \
13 + .name = "PLUGIN[macos]", \
14 + .config_section = CONFIG_SECTION_PLUGINS, \
15 + .config_name = "macos", \
16 + .enabled = 1, \
17 + .thread = NULL, \
18 + .init_routine = NULL, \
19 + .start_routine = macos_main \
20 + },
21 +
22 void *macos_main(void *ptr);
23
24 #define GETSYSCTL_BY_NAME(name, var) getsysctl_by_name(name, &(var), sizeof(var))
@@ -13,4 +29,15 @@ extern int do_macos_sysctl(int update_every, usec_t dt);
29 extern int do_macos_mach_smi(int update_every, usec_t dt);
30 extern int do_macos_iokit(int update_every, usec_t dt);
31
32 +
33 +#else // (TARGET_OS == OS_MACOS)
34 +
35 +#define NETDATA_PLUGIN_HOOK_MACOS
36 +
37 +#endif // (TARGET_OS == OS_MACOS)
38 +
39 +
40 +
41 +
42 +
43 #endif /* NETDATA_PLUGIN_MACOS_H */
src/plugins/plugins.d.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/plugins.d.plugin/plugins_d.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "plugins_d.h"
4
5 char *plugin_directories[PLUGINSD_MAX_DIRECTORIES] = { NULL };
6 char *netdata_configured_plugins_dir_base;
src/plugins/plugins.d.plugin/plugins_d.h renamed
+14
@@ -3,6 +3,20 @@
3 #ifndef NETDATA_PLUGINS_D_H
4 #define NETDATA_PLUGINS_D_H 1
5
6 +#include "../../common.h"
7 +
8 +#define NETDATA_PLUGIN_HOOK_PLUGINSD \
9 + { \
10 + .name = "PLUGINSD", \
11 + .config_section = NULL, \
12 + .config_name = NULL, \
13 + .enabled = 1, \
14 + .thread = NULL, \
15 + .init_routine = NULL, \
16 + .start_routine = pluginsd_main \
17 + },
18 +
19 +
20 #define PLUGINSD_FILE_SUFFIX ".plugin"
21 #define PLUGINSD_FILE_SUFFIX_LEN strlen(PLUGINSD_FILE_SUFFIX)
22 #define PLUGINSD_CMD_MAX (FILENAME_MAX*2)
src/plugins/statsd.plugin/Makefile.am new
+5
@@ -0,0 +1,5 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
5 +
src/plugins/statsd.plugin/statsd.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "statsd.h"
4
5 #define STATSD_CHART_PREFIX "statsd"
6 #define STATSD_CHART_PRIORITY 90000
src/plugins/statsd.plugin/statsd.h new
+25
@@ -0,0 +1,25 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_STATSD_H
4 +#define NETDATA_STATSD_H 1
5 +
6 +#include "../../common.h"
7 +
8 +#define STATSD_LISTEN_PORT 8125
9 +#define STATSD_LISTEN_BACKLOG 4096
10 +
11 +#define NETDATA_PLUGIN_HOOK_STATSD \
12 + { \
13 + .name = "STATSD", \
14 + .config_section = NULL, \
15 + .config_name = NULL, \
16 + .enabled = 1, \
17 + .thread = NULL, \
18 + .init_routine = NULL, \
19 + .start_routine = statsd_main \
20 + },
21 +
22 +
23 +extern void *statsd_main(void *ptr);
24 +
25 +#endif //NETDATA_STATSD_H
src/registry/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/registry/registry.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 #define REGISTRY_STATUS_OK "ok"
src/registry/registry.h renamed
+2
@@ -49,6 +49,8 @@
49 #ifndef NETDATA_REGISTRY_H
50 #define NETDATA_REGISTRY_H 1
51
52 +#include "../common.h"
53 +
54 #define NETDATA_REGISTRY_COOKIE_NAME "netdata_registry_id"
55
56 // initialize the registry
src/registry/registry_db.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 int registry_db_should_be_saved(void) {
src/registry/registry_init.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 int registry_init(void) {
src/registry/registry_internals.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 struct registry registry;
src/registry/registry_internals.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_REGISTRY_INTERNALS_H_H
4 #define NETDATA_REGISTRY_INTERNALS_H_H 1
5
6 +#include "registry.h"
7 +
8 #define REGISTRY_URL_FLAGS_DEFAULT 0x00
9 #define REGISTRY_URL_FLAGS_EXPIRED 0x01
10
src/registry/registry_log.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 void registry_log(char action, REGISTRY_PERSON *p, REGISTRY_MACHINE *m, REGISTRY_URL *u, char *name) {
src/registry/registry_machine.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 // ----------------------------------------------------------------------------
src/registry/registry_machine.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_REGISTRY_MACHINE_H
4 #define NETDATA_REGISTRY_MACHINE_H 1
5
6 +#include "registry_internals.h"
7 +
8 // ----------------------------------------------------------------------------
9 // MACHINE structures
10
src/registry/registry_person.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 // ----------------------------------------------------------------------------
src/registry/registry_person.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_REGISTRY_PERSON_H
4 #define NETDATA_REGISTRY_PERSON_H 1
5
6 +#include "registry_internals.h"
7 +
8 // ----------------------------------------------------------------------------
9 // PERSON structures
10
src/registry/registry_url.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "../common.h"
4 #include "registry_internals.h"
5
6 // ----------------------------------------------------------------------------
src/registry/registry_url.h renamed
+2
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_REGISTRY_URL_H
4 #define NETDATA_REGISTRY_URL_H 1
5
6 +#include "registry_internals.h"
7 +
8 // ----------------------------------------------------------------------------
9 // URL structures
10 // Save memory by de-duplicating URLs
src/statsd.h deleted
-11
@@ -1,11 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#ifndef NETDATA_STATSD_H
4 -#define NETDATA_STATSD_H 1
5 -
6 -#define STATSD_LISTEN_PORT 8125
7 -#define STATSD_LISTEN_BACKLOG 4096
8 -
9 -extern void *statsd_main(void *ptr);
10 -
11 -#endif //NETDATA_STATSD_H
src/streaming/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/streaming/rrdpush.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "rrdpush.h"
4
5 /*
6 * rrdpush
src/streaming/rrdpush.h renamed
+3
@@ -3,6 +3,9 @@
3 #ifndef NETDATA_RRDPUSH_H
4 #define NETDATA_RRDPUSH_H 1
5
6 +#include "../webserver/web_client.h"
7 +#include "../common.h"
8 +
9 extern unsigned int default_rrdpush_enabled;
10 extern char *default_rrdpush_destination;
11 extern char *default_rrdpush_api_key;
src/webserver/Makefile.am new
+4
@@ -0,0 +1,4 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +AUTOMAKE_OPTIONS = subdir-objects
4 +MAINTAINERCLEANFILES = Makefile.in
src/webserver/web_client.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "web_client.h"
4
5 // this is an async I/O implementation of the web server request parser
6 // it is used by all netdata web servers
src/webserver/web_client.h renamed
+4
@@ -3,6 +3,8 @@
3 #ifndef NETDATA_WEB_CLIENT_H
4 #define NETDATA_WEB_CLIENT_H 1
5
6 +#include "../libnetdata/libnetdata.h"
7 +
8 #ifdef NETDATA_WITH_ZLIB
9 extern int web_enable_gzip,
10 web_gzip_level,
@@ -189,4 +191,6 @@ extern void buffer_data_options2string(BUFFER *wb, uint32_t options);
191
192 extern int mysendfile(struct web_client *w, char *filename);
193
194 +#include "../common.h"
195 +
196 #endif
src/webserver/web_server.c renamed
+1 -1
@@ -1,6 +1,6 @@
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 -#include "common.h"
3 +#include "web_server.h"
4
5 // this file includes 3 web servers:
6 //
src/webserver/web_server.h renamed
+3
@@ -3,6 +3,9 @@
3 #ifndef NETDATA_WEB_SERVER_H
4 #define NETDATA_WEB_SERVER_H 1
5
6 +#include "../common.h"
7 +#include "web_client.h"
8 +
9 #ifndef API_LISTEN_PORT
10 #define API_LISTEN_PORT 19999
11 #endif