diff --git a/prometheus_ss_exporter/stats.py b/prometheus_ss_exporter/stats.py index 14abf09..a493acb 100644 --- a/prometheus_ss_exporter/stats.py +++ b/prometheus_ss_exporter/stats.py @@ -29,28 +29,15 @@ def __init__(self): self.args.all = False self.args.unix = False - def _reset_io(self): - if sys.version_info[0] == 2: - import cStringIO - self.stream_sink = cStringIO.StringIO() - else: - self.stream_sink = io.StringIO() - def provide_tcp_stats(self): - _stdout = sys.stdout - sys.stdout = self.stream_sink - - ss2.run(self.args) - # catch stdout - sys.stdout = _stdout - sk_stats_raw = self.stream_sink.getvalue() + ss2.RUN_AS_MODULE = True - self._reset_io() + sk_stats_raw = ss2.run(self.args) sk_stats_parsed = dict(TCP=dict(flows=list())) try: - sk_stats_parsed = json.loads(sk_stats_raw) + sk_stats_parsed = json.loads(sk_stats_raw[0]) except json.decoder.JSONDecodeError as err: logging.error("Failed parsing sample") logging.error("-----")