Nazalaki ntango nyonso komituna mpo na molunge ya ba HDD na NAS na ngai. Naza na NAS na chambre fermée sans airco. D’ailleurs, na démonter NAS il y a quelque temps, pe ba disques ezalaki vraiment chaud... Na mesure température te na tango wana, mais na bandaki ko soucier. Okoki kozwa masolo mingi na ntina ya température ya lecteur NAS mpe kolandela yango uta na environnement Linux/Python. Kasi ata solution moko te esalaki ngai!
Oyo nalingaki:
Tokosangisa ba données na nzela ya protocole SNMP na nzela ya ensemble pysnmp .
Kososola SNMP mpe ba MIB
SNMP (Simple Network Management Protocol) ezali protocole oyo esalelamaka mingi mpo na kolandela bokolongono mpe bosali ya ba dispositifs ya réseau. Ezali kopesa nzela na kosangisa ba données lokola températures, usage ya CPU, mpe état ya disque.
Ba MIB (Bases d’information ya gestion) ezali ba bases de données ya ba informations oyo ekoki kotunama na nzela ya SNMP. Eteni moko na moko ya ba données e identifier na OID (Identifier objet), oyo e identifiaka na ndenge ya unique variable oyo ekoki kotangama to ko fixer na nzela ya SNMP.
Esengeli o lakisa ba valeurs ya MIB pona kosangisa. Nazali na Synology NAS. Ba publier fichier MIB na ba pages na bango. Tosengeli kosangisa:
Ezali na chatbot moko ya malamu mpenza na lokasa ya pysnmp. Ekomaki nzoto ya script ya Python mpo na ngai, kosimba ba difficultés nionso na SNMP API mpe ko gérer ba appels async. Eteni ya ntina elandi:
async def run(server_name, ipaddress, username, passwd, outinfo): # SNMP walk for disk name, model, and temperature oids = [ ObjectType(ObjectIdentity('1.3.6.1.4.1.6574.2.1.1.2')), # Disk name (diskID) ObjectType(ObjectIdentity('1.3.6.1.4.1.6574.2.1.1.3')), # Disk model (diskModel) ObjectType(ObjectIdentity('1.3.6.1.4.1.6574.2.1.1.6')) # Disk temperature (diskTemperature) ] errorIndication, errorStatus, errorIndex, varBinds = await bulkCmd( SnmpEngine(), UsmUserData(username, passwd, authProtocol=usmHMACSHAAuthProtocol), # Use the appropriate auth protocol await UdpTransportTarget.create((ipaddress, 161)), ContextData(), 0, 10, # Increase the max-repetitions to get more results in one request *oids # Query disk name, model, and temperature ) if errorIndication: print(f"Error: {errorIndication}") elif errorStatus: print(f"Error Status: {errorStatus.prettyPrint()} at {errorIndex and varBinds[int(errorIndex) - 1] or '?'}") else: disk_data = {} for varBind in varBinds: oid, value = varBind oid_str = str(oid) # Disk name if oid_str.startswith('1.3.6.1.4.1.6574.2.1.1.2'): index = oid_str.split('.')[-1] if index not in disk_data: disk_data[index] = {} disk_data[index]['name'] = value # Disk model elif oid_str.startswith('1.3.6.1.4.1.6574.2.1.1.3'): index = oid_str.split('.')[-1] if index not in disk_data: disk_data[index] = {} disk_data[index]['model'] = value # Disk temperature elif oid_str.startswith('1.3.6.1.4.1.6574.2.1.1.6'): index = oid_str.split('.')[-1] if index not in disk_data: disk_data[index] = {} disk_data[index]['temperature'] = value # Print out the disk information for index, info in disk_data.items(): name = info.get('name', 'Unknown') model = info.get('model', 'Unknown') temperature = info.get('temperature', 'Unknown') name = str(name) model = str(model) temperature = str(temperature) print(f"IP Address {ipaddress}, Disk {index}: Name: {name}, Model: {model}, Temperature: {temperature} °C") outinfo.append({'server_name': server_name, 'ip': ipaddress, 'disk': index, 'name': name, 'model': model, 'temperature': temperature})
Esengeli o activer protocole SNMP na ba paramètres ya Synology NAS:
Na déployé script directement na NAS na environnement ya Docker. Esengeli osala ete esika ya Docker ebanda lisusu sima ya bobandi lisusu ya suka. Nabongisi fichier docker-compose.yaml ya pete pona raison wana:
version: '3.8' services: pingchart: build: . restart: always container_name: synology-temperature
Na sima banda Docker na docker-compose up -d
.
Nazali affilié na 2minlog - système moko ya pete pona kosangisa, ko traité, pe ko visualiser ba données. Otindi ba données kuna na nzela ya ba demandes HTTPS (encodé na URL to na nzoto) pe o setup script ya visualisation kuna. Na nsima, ba graphiques ezwamaka mbala moko uta esika nyonso oyo osengeli na yango.
Okoki kosalela 2minlog. Na lolenge mosusu, okoki kotinda ba données na base de données to na système ya ba fichiers local.
Nabongisi script ya Matplotlib ya pete mpo na kolakisa graphique. Kutu, nasengaki ChatGPT (o1-preview) esala yango, mpe esalaki malamu mpenza. Script ya Python ezalaki ya kokoka te, kasi ezalaki ezalaki malamu mpo na kosilisa mosala noki. Prompt ezali awa na se.
Here is a csv file. Can you write a code: Split data into different graphs by combining the server name and name (eg, DS920+ / Disk 1). Each graph will show the temperature. There will be a title in each graph (eg, DS920+ / Disk 1) The graphs will have the same temperature range. The background will be black, graph background will be also black, the graph color will be from dark green (low temperatures) to light green (high temperatures). There will be two thin lines - 20 °C (blue) and 45 °C (red). Trim the data for last week with tickmarks at midnight of every day. The data are in UTC time. Convert it to Europe/Berlin time zone. The resolution of the total image is hxw 600 x 1024 pixels. Save the image to PNG. disk,ip,model,name,server_name,temperature,timestamp 0,10.0.0.9,ST4000VN008-2DR166,Disk 3,DS920+,38,2024-09-19T20:19:48.723761 1,10.0.0.9,ST16000NM000J-2TW103,Disk 4,DS920+,42,2024-09-19T20:19:49.253975 2,10.0.0.9,ST4000VX007-2DT166,Disk 1,DS920+,38,2024-09-19T20:19:49.818734 3,10.0.0.9,ST4000VX007-2DT166,Disk 2,DS920+,39,2024-09-19T20:19:50.393793 0,10.0.2.9,ST12000NM001G-2MV103,Disk 1,DS220j,28,2024-09-19T20:19:50.873142 0,10.0.0.9,ST4000VN008-2DR166,Disk 3,DS920+,38,2024-09-19T20:20:02.119583 1,10.0.0.9,ST16000NM000J-2TW103,Disk 4,DS920+,42,2024-09-19T20:20:02.596654 2,10.0.0.9,ST4000VX007-2DT166,Disk 1,DS920+,38,2024-09-19T20:20:03.101480 3,10.0.0.9,ST4000VX007-2DT166,Disk 2,DS920+,39,2024-09-19T20:20:03.697423 0,10.0.2.9,ST12000NM001G-2MV103,Disk 1,DS220j,28,2024-09-19T20:20:04.221348 0,10.0.0.9,ST4000VN008-2DR166,Disk 3,DS920+,38,2024-09-19T20:25:02.254611 1,10.0.0.9,ST16000NM000J-2TW103,Disk 4,DS920+,42,2024-09-19T20:25:02.714633 2,10.0.0.9,ST4000VX007-2DT166,Disk 1,DS920+,38,2024-09-19T20:25:03.295622 3,10.0.0.9,ST4000VX007-2DT166,Disk 2,DS920+,39,2024-09-19T20:25:03.780728 ...
Script ya visualisation e déployé na kati ya plateforme ya 2minlog. Okoki mpe kosala yango na esika ofandi.
Script ezali na GitHub .
Okoki kosalela 2minlog oyo ekambami mobimba mpo na kosangisa, kosala, mpe komona na makanisi ba données. Tala mikanda oyo ezali na kati . Nalakisaka ba résultats na tablette Android oyo efandi na mesa na ngai mpe na cycle na ba graphiques ndenge na ndenge na Image Tuner . Okoki mpe kobomba ba données na système ya ba fichiers local na yo mpe kosala ndenge moko.
Solution yango emekamaka na Synology NAS, kasi ekoki kozala adapté mpo na basusu.
#Synologie #SynologieNAS #Bolandi #Temperatura #Visualisation #Matplotlib #SNMP #2minlog #Python #Docker