Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
do not report to netdata not-collected values as zero
  • Loading branch information
ktsaou committed Dec 29, 2016
1 parent 616e4dc commit 7c081b0
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions python.d/mysql.chart.py
Expand Up @@ -398,10 +398,26 @@ def _get_data_slave(self):
return None

if slave_raw_data is not None:
slave_data = {'slave_behind': 0, 'slave_sql': 0, 'slave_io': 0 }
slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1))
slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1
slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1
slave_data = {
'slave_behind': None,
'slave_sql': None,
'slave_io': None
}

try:
slave_data['slave_behind'] = int(slave_raw_data.setdefault('Seconds_Behind_Master', -1))
except:
slave_data['slave_behind'] = None

try:
slave_data['slave_sql'] = 1 if slave_raw_data.get('Slave_SQL_Running') == 'Yes' else -1
except:
slave_data['slave_sql'] = None

try:
slave_data['slave_io'] = 1 if slave_raw_data.get('Slave_IO_Running') == 'Yes' else -1
except:
slave_data['slave_io'] = None

return slave_data

Expand Down Expand Up @@ -442,11 +458,14 @@ def _get_data(self):
data = dict(raw_data)

# check for slave data
# the first time is -1 (so we do it)
# then it is set to 1 or 0 and we keep it like that
if self.do_slave != 0:
slave_data = self._get_data_slave()
if slave_data is not None:
data.update(slave_data)
self.do_slave = 1
if self.do_slave == -1:
self.do_slave = 1
else:
if self.do_slave == -1:
self.error("replication metrics will be disabled - please allow netdata to collect them.")
Expand All @@ -456,8 +475,8 @@ def _get_data(self):
try:
data["Thread_cache_misses"] = int(data["Threads_created"] * 10000 / float(data["Connections"]))
except:
data["Thread_cache_misses"] = 0
data["Thread_cache_misses"] = None

return data

def check(self):
Expand Down

4 comments on commit 7c081b0

@ilyam8
Copy link
Member

@ilyam8 ilyam8 commented on 7c081b0 Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception will never raise
if it should be None if there is no 'key' in the slave_raw_data dict you need to remove get and setdefault methods

        try:
             slave_data['slave_behind'] = int(slave_raw_data['Seconds_Behind_Master'])
         except:
             slave_data['slave_behind'] = None

         try:
             slave_data['slave_sql'] = 1 if slave_raw_data['Slave_SQL_Running'] == 'Yes' else -1
         except:
             slave_data['slave_sql'] = None

         try:
             slave_data['slave_io'] = 1 if slave_raw_data['Slave_IO_Running'] == 'Yes' else -1
         except:
            slave_data['slave_io'] = None

@ktsaou
Copy link
Member Author

@ktsaou ktsaou commented on 7c081b0 Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. you are the python expert. I just tried to follow the same principle I found on the Thread_cache_misses.

Actually, if slave_raw_data is already a dict, why do we need all these? We could just pass it back and use the official mysql names for the members.

Am I missing something?

@ilyam8
Copy link
Member

@ilyam8 ilyam8 commented on 7c081b0 Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not an expert too.

slave_raw_data['Slave_SQL_Running'] / slave_raw_data['Slave_IO_Running'] == 'Yes' or 'No'
slave_raw_data['Seconds_Behind_Master'] type is Long thats why there is int() (maybe we dont need it here)

So we need to build own dict based on the slave_raw_data values.
I am not sure about try/except stuff.
I mean whether there can be a situation when a bool(slave_raw_data) is True and needed keys(Seconds_Behind_Master etc ) are missing - but it never hurts .

@ktsaou
Copy link
Member Author

@ktsaou ktsaou commented on 7c081b0 Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to build own dict based on the slave_raw_data values.

ok, you are right.

but it never hurts

this is what I think too.

Thanks!

Please sign in to comment.