@cryptotaxi247 / netdata-1 / commits / 84dd44e98

Add allocated space metrics to oracledb charts (#10197)

Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>

Jürgen Haas committed Nov 10, 2020 at 18:12 UTC 84dd44e980c807fefb72c920bb3e7ecf442743f8
2 files changed +122
collectors/python.d.plugin/oracledb/README.md
+4
@@ -41,6 +41,10 @@ It produces following charts:
41 - Size
42 - Usage
43 - Usage In Percent
44 +- allocated space
45 + - Size
46 + - Usage
47 + - Usage In Percent
48
49 ## prerequisite
50
collectors/python.d.plugin/oracledb/oracledb.chart.py
+118
@@ -34,6 +34,9 @@ ORDER = [
34 'tablespace_size',
35 'tablespace_usage',
36 'tablespace_usage_in_percent',
37 + 'allocated_size',
38 + 'allocated_usage',
39 + 'allocated_usage_in_percent',
40 ]
41
42 CHARTS = {
@@ -170,6 +173,18 @@ CHARTS = {
173 'options': [None, 'Usage', '%', 'tablespace', 'oracledb.tablespace_usage_in_percent', 'line'],
174 'lines': [],
175 },
176 + 'allocated_size': {
177 + 'options': [None, 'Size', 'B', 'tablespace', 'oracledb.allocated_size', 'line'],
178 + 'lines': [],
179 + },
180 + 'allocated_usage': {
181 + 'options': [None, 'Usage', 'B', 'tablespace', 'oracledb.allocated_usage', 'line'],
182 + 'lines': [],
183 + },
184 + 'allocated_usage_in_percent': {
185 + 'options': [None, 'Usage', '%', 'tablespace', 'oracledb.allocated_usage_in_percent', 'line'],
186 + 'lines': [],
187 + },
188 }
189
190 CX_CONNECT_STRING = "{0}/{1}@//{2}/{3}"
@@ -193,6 +208,27 @@ FROM
208 dba_tablespace_usage_metrics m
209 JOIN dba_tablespaces t ON m.tablespace_name = t.tablespace_name
210 '''
211 +QUERY_ALLOCATED = '''
212 +SELECT
213 + nvl(b.tablespace_name,nvl(a.tablespace_name,'UNKNOWN')) tablespace_name,
214 + bytes_alloc used_bytes,
215 + bytes_alloc-nvl(bytes_free,0) max_bytes,
216 + ((bytes_alloc-nvl(bytes_free,0))/ bytes_alloc)*100 used_percent
217 +FROM
218 + (SELECT
219 + sum(bytes) bytes_free,
220 + tablespace_name
221 + FROM sys.dba_free_space
222 + GROUP BY tablespace_name
223 + ) a,
224 + (SELECT
225 + sum(bytes) bytes_alloc,
226 + tablespace_name
227 + FROM sys.dba_data_files
228 + GROUP BY tablespace_name
229 + ) b
230 +WHERE a.tablespace_name (+) = b.tablespace_name
231 +'''
232 QUERY_ACTIVITIES_COUNT = '''
233 SELECT
234 name,
@@ -397,6 +433,26 @@ class Service(SimpleService):
433 data['{0}_tablespace_used'.format(name)] = int(used * 1000)
434 data['{0}_tablespace_used_in_percent'.format(name)] = int(used_in_percent * 1000)
435
436 + # ALLOCATED SPACE
437 + try:
438 + rv = self.gather_allocated_metrics()
439 + except cx_Oracle.Error as error:
440 + self.error(error)
441 + self.alive = False
442 + return None
443 + else:
444 + for name, offline, size, used, used_in_percent in rv:
445 + # TODO: skip offline?
446 + if not (not offline and self.charts):
447 + continue
448 + # TODO: remove inactive?
449 + if name not in self.active_tablespaces:
450 + self.active_tablespaces.add(name)
451 + self.add_tablespace_to_charts(name)
452 + data['{0}_allocated_size'.format(name)] = int(size * 1000)
453 + data['{0}_allocated_used'.format(name)] = int(used * 1000)
454 + data['{0}_allocated_used_in_percent'.format(name)] = int(used_in_percent * 1000)
455 +
456 return data or None
457
458 def gather_system_metrics(self):
@@ -612,6 +668,44 @@ class Service(SimpleService):
668 )
669 return metrics
670
671 + def gather_allocated_metrics(self):
672 + """
673 + :return:
674 +
675 + [['SYSTEM', 874250240.0, 3233169408.0, 27.040038107400033, 0],
676 + ['SYSAUX', 498860032.0, 3233169408.0, 15.429443033997678, 0],
677 + ['TEMP', 0.0, 3233177600.0, 0.0, 0],
678 + ['USERS', 1048576.0, 3233169408.0, 0.03243182981397305, 0]]
679 + """
680 + metrics = list()
681 + with self.conn.cursor() as cursor:
682 + cursor.execute(QUERY_ALLOCATED)
683 + for tablespace_name, used_bytes, max_bytes, used_percent in cursor.fetchall():
684 + if used_bytes is None:
685 + offline = True
686 + used = 0
687 + else:
688 + offline = False
689 + used = float(used_bytes)
690 + if max_bytes is None:
691 + size = 0
692 + else:
693 + size = float(max_bytes)
694 + if used_percent is None:
695 + used_percent = 0
696 + else:
697 + used_percent = float(used_percent)
698 + metrics.append(
699 + [
700 + tablespace_name,
701 + offline,
702 + size,
703 + used,
704 + used_percent,
705 + ]
706 + )
707 + return metrics
708 +
709 def gather_wait_time_metrics(self):
710 """
711 :return:
@@ -711,3 +805,27 @@ class Service(SimpleService):
805 1,
806 1000,
807 ])
808 + self.charts['allocated_size'].add_dimension(
809 + [
810 + '{0}_allocated_size'.format(name),
811 + name,
812 + 'absolute',
813 + 1,
814 + 1000,
815 + ])
816 + self.charts['allocated_usage'].add_dimension(
817 + [
818 + '{0}_allocated_used'.format(name),
819 + name,
820 + 'absolute',
821 + 1,
822 + 1000,
823 + ])
824 + self.charts['allocated_usage_in_percent'].add_dimension(
825 + [
826 + '{0}_allocated_used_in_percent'.format(name),
827 + name,
828 + 'absolute',
829 + 1,
830 + 1000,
831 + ])