Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<type 'exceptions.ValueError'>: could not convert string to float: postgres #809

Open
Ezhvtumane opened this issue Oct 31, 2019 · 2 comments

Comments

@Ezhvtumane
Copy link

When I using [[inputs.postgres]] I receive this error, because this plugin has string metrics.

https://github.com/yandex/yandex-tank/blob/develop/yandextank/plugins/Telegraf/plugin.py#L299
This type conversion throw exception.

Please, check type before cast. Thanks.
Hope it's be fixed.

@fomars
Copy link
Contributor

fomars commented Jan 16, 2020

не понял
пожалуйста, приложите полный текст ошибки

@Ezhvtumane
Copy link
Author

К сожалению, сейчас нет возможности запустить тест и полностью привести текст ошибки.
В целом там проблема в том, что может прийти не числовая метрика, а стринга. Тогда весь тест валится. Например имя хоста или любая другая метрика теста которая не int.

В своем проекте я пофиксил следующим образом:
добавил дополнительную проверку:

elif isinstance(value, basestring) or isinstance(self.data[host][metric], basestring):
self.sign[host][metric] = 0
self.data[host][metric] = value

        for metric, value in data.iteritems():
            if value == '':
                self.sign[host][metric] = -1
                self.data[host][metric] = value
            elif isinstance(value, basestring) or isinstance(self.data[host][metric], basestring):
                self.sign[host][metric] = 0
                self.data[host][metric] = value
            else:
                if not self.data[host].get(metric, None):
                    self.sign[host][metric] = 1
                elif float(value) > float(self.data[host][metric]):
                    self.sign[host][metric] = 1
                elif float(value) < float(self.data[host][metric]):
                    self.sign[host][metric] = -1
                else:
                    self.sign[host][metric] = 0
                self.data[host][metric] = "%.2f" % float(value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants