38 from diagnostic_updater
import DiagnosticTask, Updater
39 from diagnostic_msgs.msg
import DiagnosticStatus
47 DiagnosticTask.__init__(self,
"CPU Information")
51 cpu_percentages = psutil.cpu_percent(percpu=
True)
52 cpu_average = sum(cpu_percentages) / len(cpu_percentages)
54 stat.add(
"CPU Load Average", cpu_average)
57 for idx, val
in enumerate(cpu_percentages):
58 stat.add(
"CPU {} Load".format(idx),
"{}".format(val))
63 stat.summary(DiagnosticStatus.WARN,
"At least one CPU exceeds %d percent" % self.
_warning_percentage)
65 stat.summary(DiagnosticStatus.OK,
"CPU Average %.1f percent" % cpu_average)
71 hostname = socket.gethostname()
72 rospy.init_node(
'cpu_monitor_%s' % hostname.replace(
"-",
"_"))
75 updater.setHardwareID(hostname)
76 updater.add(
CpuTask(rospy.get_param(
"~warning_percentage", 90)))
78 rate = rospy.Rate(rospy.get_param(
"~rate", 1))
79 while not rospy.is_shutdown():
84 if __name__ ==
'__main__':
def __init__(self, warning_percentage)