/collectors/python.d.plugin/third_party: patch monotonic synolo… (#7980)
Ilya Mashchenko committed
Feb 6, 2020 at 09:30 UTC
a90838e628e1adcea59bcac97c9d018f7643165d
1 file changed
+36
-6
collectors/python.d.plugin/python_modules/third_party/monotonic.py
+36
-6
@@ -54,6 +54,41 @@ except AttributeError:
54
import os
55
import sys
56
import threading
57
+
58
+
59
+ def clock_clock_gettime_c_library():
60
+ return ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True).clock_gettime
61
+
62
+
63
+ def clock_clock_gettime_rt_library():
64
+ return ctypes.CDLL(ctypes.util.find_library('rt'), use_errno=True).clock_gettime
65
+
66
+
67
+ def clock_clock_gettime_c_library_synology6():
68
+ return ctypes.CDLL('/usr/lib/libc.so.6', use_errno=True).clock_gettime
69
+
70
+
71
+ def clock_clock_gettime_rt_library_synology6():
72
+ return ctypes.CDLL('/usr/lib/librt.so.1', use_errno=True).clock_gettime
73
+
74
+
75
+ def clock_gettime_linux():
76
+ # see https://github.com/netdata/netdata/issues/7976
77
+ order = [
78
+ clock_clock_gettime_c_library,
79
+ clock_clock_gettime_rt_library,
80
+ clock_clock_gettime_c_library_synology6,
81
+ clock_clock_gettime_rt_library_synology6,
82
+ ]
83
+
84
+ for gettime in order:
85
+ try:
86
+ return gettime()
87
+ except (RuntimeError, AttributeError, OSError):
88
+ continue
89
+ raise RuntimeError('can not find c and rt libraries')
90
+
91
+
92
try:
93
if sys.platform == 'darwin': # OS X, iOS
94
# See Technical Q&A QA1398 of the Mac Developer Library:
@@ -132,12 +167,7 @@ except AttributeError:
167
return final_milliseconds / 1000.0
168
169
else:
135
- try:
136
- clock_gettime = ctypes.CDLL(ctypes.util.find_library('c'),
137
- use_errno=True).clock_gettime
138
- except Exception:
139
- clock_gettime = ctypes.CDLL(ctypes.util.find_library('rt'),
140
- use_errno=True).clock_gettime
170
+ clock_gettime = clock_gettime_linux()
171
172
class timespec(ctypes.Structure):
173
"""Time specification, as described in clock_gettime(3)."""