【问题标题】:Need assistance to generate a real time data plot需要帮助来生成实时数据图
【发布时间】:2017-05-07 06:22:14
【问题描述】:

在 Python 中,我使用 paramiko 对远程设备进行 ssh。现在,我想从结果输出中获得一个实时数据图(时间与吞吐量),这基本上是两个模块之间的吞吐量测量。有没有人可以帮助我如何做到这一点?提前致谢。我在这里分享的代码和结果输出是为了让您更好地理解。

import sys
import time
import select
import paramiko

host = '169.254.115.1'
i = 1

#
# Try to connect to the host.
# Retry a few times if it fails.
#
while True:
    print ('Trying to connect to %s (%i/3)' % (host, i))

    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(host, port=22, username='user', password='user')
        print ("Connected to %s" % host)
        break
    except paramiko.AuthenticationException:
        print ("Authentication failed when connecting to %s") % host
        sys.exit(1)
    except:
        print ("Could not SSH to %s, waiting for it to start" % host)
        i += 1
        time.sleep(2)

    # If we could not connect within time limit
    if i == 3:
        print ("Could not connect to %s. Giving up") % host
        sys.exit(1)

# Send the command (non-blocking)
stdin, stdout, stderr = ssh.exec_command("cd /opt/cohda/test; sudo ./runtest_iperf_tx.sh")

# Wait for the command to terminate
while not stdout.channel.exit_status_ready():
    # Only print data if there is data to read in the channel
    if stdout.channel.recv_ready():
        rl, wl, xl = select.select([stdout.channel], [], [], 0.0)
        if len(rl) > 0:
            # Print data from stdout
            print (stdout.channel.recv(1024)),
#
# Disconnect from the host
#
print ("Command done, closing SSH connection")
ssh.close()

Throughput or resultant output

【问题讨论】:

  • 显示你到目前为止所做的代码
  • 请再看一下我的帖子,然后点击:看这里的代码
  • 您应该将答案中的代码粘贴为文本,而不是图片。
  • 我觉得现在可以理解了。

标签: python ssh paramiko throughput


【解决方案1】:

如果我的任务是解决这个问题,我会考虑使用 Bokeh,因为它允许您使用 Python 编码,并且可以将数据更新流式传输到可视化:http://docs.bokeh.org

但是肯定有很多方法可以做到这一点,还有很多选择!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-28
    • 2021-10-20
    • 2022-07-12
    • 1970-01-01
    • 2015-03-16
    • 2015-01-25
    • 1970-01-01
    • 2021-03-19
    相关资源
    最近更新 更多