Скрипт для снятия показателей температуры
Сначала необходимо установить модуль для python3 - psutil:apt install python3-pip pip3 install psutil
Листинг скрипта для снятия текущего состояния температуры процессоров:
Размещаем его по пути /etc/zabbix/scripts/cpu-temperature.py и делаем его выполняемым (chmod+x /etc/zabbix/scripts/cpu-temperature.py )
#!/usr/bin/env python3.4 # ON DEBIAN IT CAN BE python3.4 so change it if you will not have psutil module import psutil import os import os.path import sys output_dir = '/etc/zabbix/' # Where will saved info about CPU's """ Get current temperature of all CPU's """ def cputemperature(): cputemp = [] try: for i in range (0, len(psutil.sensors_temperatures()['coretemp'])): cputemp.append(psutil.sensors_temperatures()['coretemp'][i][1]) return cputemp # Return list of current temperature except: return False # Else - False """ Putting CPU temperature into separate file """ def saveinfo(): temperature = cputemperature() if temperature != False: for i in range(0, len(temperature)): #print ('CPU'+str(i)+' is: '+str(temperature[i])) file = None try: file = open(output_dir+'cpu'+str(i)+'-temp', 'w') except IOError: msg = ("Unable to create file on disk.") file.close() return finally: if file != None: file.write(str(round(temperature[i]))) file.close() else: print ('Error. Can\'t give cpu temperature!') if __name__ == "__main__": saveinfo() else: sys.exit(1)
Результатом выполнения данного скрипта будут файлы в /etc/zabbix в виде cpu[0-X]-temp, в которых будет указано текущее значение температуры для каждого процессора.
Далее выполнение данного скрипта необходимо разместить в планировщик cron (скрипт будет выполняться каждую минуту):
crontab -e */1 * * * * /etc/zabbix/scripts/cpu-temperature.py && chown zabbix:zabbix /etc/zabbix/cpu*
Настраиваем агента zabbix
Добавляем в конец /etc/zabbix/zabbix_agentd.conf необходимые значения
для снятия данных (смотрим результат выполнения скрипта в
/etc/zabbix/cpu[0-X]-temp по кол-ву файлов):
Создаём триггеры
Перезагружаем zabbix агента:... UserParameter=cpu0.temp,cat /etc/zabbix/cpu0-temp UserParameter=cpu1.temp,cat /etc/zabbix/cpu1-temp UserParameter=cpu2.temp,cat /etc/zabbix/cpu2-temp UserParameter=cpu3.temp,cat /etc/zabbix/cpu3-temp UserParameter=cpu4.temp,cat /etc/zabbix/cpu4-temp UserParameter=cpu5.temp,cat /etc/zabbix/cpu5-temp UserParameter=cpu6.temp,cat /etc/zabbix/cpu6-temp UserParameter=cpu7.temp,cat /etc/zabbix/cpu7-temp ...
systemctl restart zabbix-agent.service
Комментариев нет:
Отправить комментарий