Linux 板


LINE

※ 引述《smile2359630 (。。。)》之铭言: : 小弟刚步入linux系统没多久而已,目前遇到一个问题 : 我想在macbook上使用speedometer这个网路监测软体,想说都是以unix下去发展出来的OS, : 执行上照理说可行的,但目前遇到下面问题 : speedometer -rx eth0 时显示以下 : Traceback (most recent call last): : File "/usr/local/bin/speedometer", line 1093, in <module> : console() : File "/usr/local/bin/speedometer", line 797, in console : wait_all(cols) : File "/usr/local/bin/speedometer", line 1088, in wait_all : tap.wait_creation() : File "/usr/local/bin/speedometer", line 856, in wait_creation : if self.feed() is None: : File "/usr/local/bin/speedometer", line 610, in networkfn : f = open('/proc/net/dev') : IOError: [Errno 2] No such file or directory: '/proc/net/dev' 这个程式写法是抓 linux 特有的 /proc/net/dev 分析内容,所以 linux 适合使用, mac 没该档案所以运作失败。 要改写支援 mac 也很简单,刚看一下大约这样子 /usr/local/bin/speedometer.py 档案打开,几个地方要改: 1. 找一下一开始 import 部分语法 #!/usr/local/opt/python@2/bin/python2.7 # speedometer.py # Copyright (C) 2001-2011 Ian Ward # # This module is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This module is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. __version__ = "2.8" import time import sys import os import string import math import re 在 import re 之後,多加一行: import psutil 2. 下面这段要改: def network_feed(device,rxtx): """network_feed(device,rxtx) -> function that returns given device stream speed rxtx is "RX" or "TX" """ assert rxtx in ["RX","TX"] r = re.compile(r"^\s*" + re.escape(device) + r":(.*)$", re.MULTILINE) def networkfn(devre=r,rxtx=rxtx): f = open('/proc/net/dev') dev_lines = f.read() f.close() match = devre.search(dev_lines) if not match: return None parts = match.group(1).split() if rxtx == 'RX': return long(parts[0]) else: return long(parts[8]) return networkfn 改成: def network_feed(device,rxtx): """network_feed(device,rxtx) -> function that returns given device stream speed rxtx is "RX" or "TX" """ assert rxtx in ["RX","TX"] r = re.compile(r"^\s*" + re.escape(device) + r":(.*)$", re.MULTILINE) def networkfn(devre=r,rxtx=rxtx): if rxtx == 'RX': return psutil.net_io_counters(pernic=True)[device].bytes_recv else: return psutil.net_io_counters(pernic=True)[device].bytes_sent return networkfn 主要是 networkfn() 里面改改就好。 最後系统用 pip install psutil 安装上该 python module,刚刚跑一下可以运作。 --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.117.155.17
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1523509703.A.842.html
1F:推 smile2359630: 真的太感谢您了!!! 04/12 13:30
2F:推 ddtsatan: 推 04/12 20:51
3F:→ kenduest: 比较意外的是改很快一直没有人提交新的更新给作者蛮可 04/14 16:44
4F:→ kenduest: 惜的,後续也来提交看看不过可能得顺便处理py3的问题 04/14 16:44
5F:→ kenduest: fork 版本可以请测试用看看,py3 也可以支援了: 04/15 01:37
6F:→ kenduest: https://github.com/kenduest/speedometer 04/15 01:38







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP