Fix elasticsearch null values returned by _cat/indices API (#11501)
vpiserchia committed
Sep 14, 2021 at 08:49 UTC
3f2b6d638edf315f264095cbd5b21d29f2e881da
1 file changed
+36
-2
collectors/python.d.plugin/elasticsearch/elasticsearch.chart.py
+36
-2
@@ -506,7 +506,9 @@ CHARTS = {
506
507
508
def convert_index_store_size_to_bytes(size):
509
- # can be b, kb, mb, gb
509
+ # can be b, kb, mb, gb or None
510
+ if size is None:
511
+ return -1
512
if size.endswith('kb'):
513
return round(float(size[:-2]) * 1024)
514
elif size.endswith('mb'):
@@ -520,6 +522,12 @@ def convert_index_store_size_to_bytes(size):
522
return -1
523
524
525
+def convert_index_null_value(value):
526
+ if value is None:
527
+ return -1
528
+ return value
529
+
530
+
531
def convert_index_health(health):
532
if health == 'green':
533
return 0
@@ -634,6 +642,30 @@ class Service(UrlService):
642
# "docs.count": "10",
643
# "docs.deleted": "3",
644
# "store.size": "650b"
645
+ # },
646
+ # {
647
+ # "status":"open",
648
+ # "index":".kibana_3",
649
+ # "health":"red",
650
+ # "uuid":"umAdNrq6QaOXrmZjAowTNw",
651
+ # "store.size":null,
652
+ # "pri.store.size":null,
653
+ # "docs.count":null,
654
+ # "rep":"0",
655
+ # "pri":"1",
656
+ # "docs.deleted":null
657
+ # },
658
+ # {
659
+ # "health" : "green",
660
+ # "status" : "close",
661
+ # "index" : "siem-events-2021.09.12",
662
+ # "uuid" : "mTQ-Yl5TS7S3lGoRORE-Pg",
663
+ # "pri" : "4",
664
+ # "rep" : "0",
665
+ # "docs.count" : null,
666
+ # "docs.deleted" : null,
667
+ # "store.size" : null,
668
+ # "pri.store.size" : null
669
# }
670
# ]
671
raw_data = self._get_raw_data(url)
@@ -654,10 +686,12 @@ class Service(UrlService):
686
continue
687
688
v = {
657
- '{0}_index_docs_count'.format(name): idx['docs.count'],
689
'{0}_index_replica'.format(name): idx['rep'],
690
'{0}_index_health'.format(name): convert_index_health(idx['health']),
691
}
692
+ docs_count = convert_index_null_value(idx['docs.count'])
693
+ if docs_count != -1:
694
+ v['{0}_index_docs_count'.format(name)] = idx['docs.count']
695
size = convert_index_store_size_to_bytes(idx['store.size'])
696
if size != -1:
697
v['{0}_index_store_size'.format(name)] = size