Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
name = '/var/log/WLAN_Thermo/TEMPLOG.csv'
else:
create_logfile(name, log_kanal)
new_config = ConfigParser.SafeConfigParser()
Temperatur = [None for i in xrange(channel_count)]
alarm_state = [None for i in xrange(channel_count)]
test_alarm = False
config_mtime = 0
alarm_time = 0
try:
while True:
time_start = time.time()
CPU_usage = psutil.cpu_percent(interval=1, percpu=True)
ram = psutil.virtual_memory()
ram_free = ram.free // 2**20
logger.debug(u'CPU: {} RAM free: {}'.format(CPU_usage, ram_free))
alarm_irgendwo = False
alarm_neu = False
alarm_repeat = False
alarme = []
statusse = []
pit = {}
pit2 = {}
if enable_maverick:
logger.info(u'Reading from Maverick receiver...')
maverick = read_maverick()
else:
logger.info(u'Maverick is disabled')
#!/usr/bin/python
import psutil
while True:
cpu_percents = str(psutil.cpu_percent(interval=0.5, percpu=True))
line = str(cpu_percents)[1:-1]
print line
datafile = open("cpuData.txt", "a")
datafile.write(line + "\n")
datafile.close()
#!/usr/bin/python
import socket
import psutil
HOST = 'localhost'
PORT = 1027
ADDR = (HOST,PORT)
serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
while True:
cpu_percent = str(psutil.cpu_percent(interval=0.5))
serv.sendto(cpu_percent, ADDR)
print 'written ' + cpu_percent
def main():
# Hostname Info
hostname = socket.gethostname()
print("Hostname:", hostname)
# CPU Info
cpu_count = psutil.cpu_count()
cpu_usage = psutil.cpu_percent(interval=1)
print("CPU:\n\tCount:", cpu_count, "\n\tUsage:", cpu_usage)
# Memory Info
memory_stats = psutil.virtual_memory()
memory_total = memory_stats.total
memory_used = memory_stats.used
memory_used_percent = memory_stats.percent
print("Memory:\n\tPercent:", memory_used_percent, "\n\tTotal:", memory_total / 1e+6, "MB", "\n\tUsed:", memory_used / 1e+6, "MB")
# Disk Info
disk_info = psutil.disk_partitions()
print("Disks:")
disks = []
for x in disk_info:
# Try fixes issues with connected 'disk' such as CD-ROMS, Phones, etc.
try:
def get_cpu_load():
# returns cpu load as a decimal value between 0 and 1
return psutil.cpu_percent(interval=1)
import psutil
from ISStreamer.Streamer import Streamer
streamer = Streamer(bucket_name="test object logging", debug_level=2)
# Example dict
streamer.log_object({"foo": "1", "bar": "2"})
# Example lists
cpu_percents = psutil.cpu_percent(percpu=True)
streamer.log_object(cpu_percents, key_prefix="cpu")
streamer.log_object(['1', '2', '3'])
# Example objects with attributes
streamer.log_object(psutil.virtual_memory())
streamer.close()
if sys.argv[i].startswith("-C"):
components = sys.argv[i][2::]
if testing:
time_start = int(round(time.time() * 1000))
pcpu, avg, speed, temp, fans, memory = None, None, None, None, None, None
output = ""
# prepare ONLY requested data, ONLY once
if "g" in components or "p" in components:
pcpu = psutil.cpu_percent(interval=1, percpu=True)
if "a" in components:
avg = psutil.cpu_percent(interval=1)
if "s" in components or "S" in components:
try:
speed = psutil.cpu_freq(False)
except:
pass
if "t" in components:
temp = psutil.sensors_temperatures(fahrenheit)
if "f" in components:
try:
fans = psutil.sensors_fans()
except:
pass
total=q.get_total(self.r_server),
dynamic_ncols=True,
# position=queue_position+0,
),
processed_counter=tqdm(desc='%s processed jobs [batch size: %i]'%(queue_id,q.batch_size),
unit=' jobs',
total=q.get_total(self.r_server),
dynamic_ncols=True,
# position=queue_position+1,
),
last_status = None
)
while not self.is_done():
'''get machine status data'''
cpu_load = psutil.cpu_percent(interval=None)
if isinstance(cpu_load, float):
self.historical_data['machine_status']['cpu_load'].append(cpu_load)
else:
self.historical_data['machine_status']['cpu_load'].append(0.)
memory_load = psutil.virtual_memory()
self.historical_data['machine_status']['memory_load'].append(memory_load.percent)
self.historical_data['machine_status']['memory_use'].append(round(memory_load.used / (1024 * 1024 * 1024), 2)) # Gb of used memory
self.log_machine_status()
''' get queue(s) data'''
for _, q in enumerate(self.queues):
data = q.get_status(self.r_server)
self.log(data)
last_data = self.bars[q.queue_id]['last_status']
submitted_counter = data['submitted_counter']
processed_counter = data['processed_counter']
if last_data:
muted = "no"
if "can_send_messages" in usr:
if not usr["can_send_messages"]:
muted = "si"
text = text.replace("+is_muted+", muted)
if "+benvenuto+" in text:
state = DBs.read_obj(infos.cid, infos.entity, "groups")["ext"]
if not state or state == "0":
state = "sì"
else:
state = "no"
text = text.replace("+benvenuto+", state)
if "cpu%" in text:
text = text.replace("cpu", str(psutil.cpu_percent()))
if "ram%" in text:
text = text.replace("ram", str(psutil.virtual_memory()[2]))
if "disk%" in text:
text = text.replace("disk", str(psutil.disk_usage('/')[3]))
if "+upt+" in text:
t = datetime.fromtimestamp(Unreloaded.get_time()).strftime("%d alle %H:%M:%S")
text = text.replace("+upt+", t)
if infos.to_user and infos.to_user.uid != infos.bid:
text = text.replace("+is_admin2+", "sì" if infos.to_user.perms.is_admin else "no")
if infos.to_user.perms.is_admin:
text = text.replace("+can_mute2+", "sì" if infos.to_user.perms.can_restrict_members else "no")
else:
text = text.replace("+can_mute2+", "no")
def system_data():
io_data_start = psutil.net_io_counters()
time.sleep(PERIOD)
cpu_data = psutil.cpu_percent(interval=None)
ram_data = psutil.virtual_memory()
disk_data = psutil.disk_usage('/')
user_data = psutil.users()
io_data = psutil.net_io_counters()
try:
user_name = user_data[0].name
except IndexError:
user_name = 'root'
data = {
'cpu': {
'percent': cpu_data
},
'ram': {
'percent': ram_data.percent,