インポートエラーが発生しました。 「HAProxyServer」の名前を取得できません。

インポートエラーが発生しました。 「HAProxyServer」の名前を取得できません。
#!/usr/bin/python3.6

from haproxystats import HAProxyServer

class HAProxyServer:
    haproxy=HAProxyServer('x.x.x.x:x222')
    for b in haproxy.backends:
        print('%s: %s' % (b.name, b.status))

上記のコードを実行するとエラーが発生します。

python3.6hatop.py

  File "hatop.py", line 3, in <module>
    from haproxystats import HAProxyServer
ImportError: cannot import name 'HAProxyServer'```

ベストアンサー1

これは、「HAProxyServer」モジュールがPythonモジュールに存在しないことを意味します。次のコマンドを使用してインストールする必要があります。

pip install haproxy-stats

公式ドキュメントをご覧ください。

https://github.com/bcicen/haproxy-stats

おすすめ記事