alspitz / cpu_monitor Goto Github PK
View Code? Open in Web Editor NEWROS node that publishes all nodes' CPU and memory usage
License: MIT License
ROS node that publishes all nodes' CPU and memory usage
License: MIT License
I have a distributed ROS system with three computers. I would like to start on every computer the cpu_monitor under a different name. In the launch files on the different machines I set up the following:
Unfortunately on all three computers still the same topic "namespace" is used and brings the same topic names like:
/cpu_monitor/total_cpu
instead of
/computer1_cpu_monitor/total_cpu
/computer2_cpu_monitor/total_cpu
/computer3_cpu_monitor/total_cpu
Looking in the script I found that topic prefix is hard coded. In order solve this I applied the following patch:
index 4671a9c..f7bccb7 100755
--- a/monitor.py
+++ b/monitor.py
@@ -24,8 +24,8 @@ class Node:
def __init__(self, name, pid):
self.name = name
self.proc = psutil.Process(pid)
- self.cpu_publisher = rospy.Publisher(ns_join("cpu_monitor", name[1:], "cpu"), Float32, queue_size=20)
- self.mem_publisher = rospy.Publisher(ns_join("cpu_monitor", name[1:], "mem"), UInt64, queue_size=20)
+ self.cpu_publisher = rospy.Publisher(ns_join(rospy.get_name(), name[1:], "cpu"), Float32, queue_size=20)
+ self.mem_publisher = rospy.Publisher(ns_join(rospy.get_name(), name[1:], "mem"), UInt64, queue_size=20)
def publish(self):
self.cpu_publisher.publish(Float32(self.proc.cpu_percent()))
@@ -45,7 +45,7 @@ if __name__ == "__main__":
node_map = {}
ignored_nodes = set()
- cpu_publish = rospy.Publisher("cpu_monitor/total_cpu", Float32, queue_size=20)
+ cpu_publish = rospy.Publisher("%s/total_cpu" % rospy.get_name() ,Float32, queue_size=20)
mem_topics = ["available", "used", "free", "active", "inactive", "buffers", "cached", "shared", "slab"]
@@ -54,7 +54,7 @@ if __name__ == "__main__":
mem_publishers = []
for mem_topic in mem_topics:
- mem_publishers.append(rospy.Publisher("cpu_monitor/total_%s_mem" % mem_topic,
+ mem_publishers.append(rospy.Publisher("%s/total_%s_mem" % (rospy.get_name(), mem_topic),
UInt64, queue_size=20))
while not rospy.is_shutdown():
Hey, first, thanks for the great work, I've been working on a system with ROS lately and great to use your monitor.
I just have a slight question about it, my system is composed of multiple ROS nodes communicating, if I check cpu usage of each I find (12, 17, 30%....), however if I check the total_cpu I get 30% which doesn't fit the sum of all cpu usages (the sum exceeds way more).
Any possible explanation for this ?
Would be glad to get an answer.
Thanks a lot !
Really cool project!
I was wondering if you plan to support multi-device monitoring at some point? Not exactly sure how it would be accomplished, but I am currently using 2 different devices to run my ROS stack, and having multi-device support would be huge.
hi
when i run the program, this is my output:
7H:~/PycharmProjects/cpu_monitor-master$ python monitor.py
[INFO] [1609940542.760856]: [cpu monitor] adding new node /cpu_monitor
[INFO] [1609940542.769134]: [cpu monitor] adding new node /rosout
[INFO] [1609940542.777597]: [cpu monitor] adding new node /Mono
I'm not getting any of the memory information or any other information about the program i'm running! Is there something that I have to modify in the program?
thanks,
Hello,
When testing the monitor.py, I've tried using rosrun commands on python scripts in the terminal to initialize nodes which had no problem in finding the process IDs of the nodes even when I've killed the nodes an re-rosrun the scripts. When I first used the roslaunch command in the terminal to initialize multiple nodes using their respective scripts, they were able to be added and their process IDs can be found. However, once I've killed the nodes (ctrl+c) and then re-roslaunch them, it gave me the error "[cpu monitor] failed to get pid of node" for all the nodes initialized by the launch file.
Out of curiosity, I put line 123 outside of the try-except statement, and it gave me the following error when i relaunch a previously killed node:
`Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
exec(code, globals, locals)
File "/home/cajun/catkin_ws/src/cpu_monitor/nodes/monitor.py", line 187, in
resp = ServerProxy(node_api).getPid('/rosnode') #Pid = Process ID (ID in system monitor)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1109, in call
return self.__send(self.__name, args)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1450, in __request
response = self.__transport.request(
File "/usr/lib/python3.8/xmlrpc/client.py", line 1153, in request
return self.single_request(host, handler, request_body, verbose)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1165, in single_request
http_conn = self.send_request(host, handler, request_body, verbose)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1278, in send_request
self.send_content(connection, request_body)
File "/usr/lib/python3.8/xmlrpc/client.py", line 1308, in send_content
connection.endheaders(request_body)
File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 951, in send
self.connect()
File "/usr/lib/python3.8/http/client.py", line 922, in connect
self.sock = self._create_connection(
File "/usr/lib/python3.8/socket.py", line 808, in create_connection
raise err
File "/usr/lib/python3.8/socket.py", line 796, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.