4 from std_msgs.msg
import Float32
5 from collections
import deque
9 return name.lower().replace(
"-",
"_")
13 rospy.init_node(
'network')
15 self.
hz = rospy.get_param(
'~hz', 10)
16 rospy.logdebug(
'publish network status (bps) at ' + str(self.
hz) +
'Hz')
17 rospy.logdebug(
'usage:\n$rosrun jsk_network_tools network_status.py _hz:=[Hz]')
19 rospy.Timer(rospy.Duration(1.0/self.
hz), self.
publish)
31 pub_transmit = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/transmit', Float32)
32 pub_receive = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/receive', Float32)
33 pub_transmit_kbps = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/transmit_kbps', Float32)
34 pub_receive_kbps = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/receive_kbps', Float32)
35 pub_transmit_mbps = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/transmit_mbps', Float32)
36 pub_receive_mbps = rospy.Publisher(
rosSafeName(os.uname()[1]) +
"/" + face[0] +
'/receive_mbps', Float32)
37 queue_transmit = deque()
38 queue_reveice = deque()
40 for i
in range(self.
hz):
41 queue_transmit.append(-1)
42 queue_reveice.append(-1)
45 self.
faces_map[face[0]][
"transmit"] = {
"publisher": pub_transmit,
"value": queue_transmit,
46 "publisher_kbps": pub_transmit_kbps,
47 "publisher_mbps": pub_transmit_mbps}
48 self.
faces_map[face[0]][
"receive"] = {
"publisher": pub_receive,
"value": queue_reveice,
49 "publisher_kbps": pub_receive_kbps,
50 "publisher_mbps": pub_receive_mbps}
54 non_local_transmit = 0
59 self.
faces_map[name][
"transmit"][
"value"].append(int(face[1]))
60 self.
faces_map[name][
"receive"][
"value"].append(int(face[2]))
61 transmit_value = (int(face[1]) - self.
faces_map[name][
"transmit"][
"value"].popleft()) * 8
62 receive_value = (int(face[2]) - self.
faces_map[name][
"receive"][
"value"].popleft()) * 8
70 non_local_receive = receive_value + non_local_receive
71 non_local_transmit = transmit_value + non_local_transmit
72 self.non_local_transmit_pub.publish(
Float32(non_local_transmit))
73 self.non_local_receive_pub.publish(
Float32(non_local_receive))
74 self.non_local_transmit_kbps_pub.publish(
Float32(non_local_transmit / 1024))
75 self.non_local_receive_kbps_pub.publish(
Float32(non_local_receive / 1024))
76 self.non_local_transmit_mbps_pub.publish(
Float32(non_local_transmit / 1024 / 1024))
77 self.non_local_receive_mbps_pub.publish(
Float32(non_local_receive / 1024 / 1024))
79 with open(
"/proc/net/dev")
as f:
80 status = f.readlines()
83 match = self.match_face.match(s)
85 nums = match.group(2).split()
86 ret.append([match.group(1).strip(), nums[8], nums[0]])
89 if __name__ ==
'__main__':
non_local_transmit_kbps_pub
non_local_receive_mbps_pub
non_local_transmit_mbps_pub
non_local_receive_kbps_pub