English is not my mother tongue, this page may contain incorrect words or sentences.
urriellu.net => Articles => Software => Scripts for cacti
Cacti is a rrdtool frontend that makes easy the creation and administration of graphs, mainly used for showing info about a computer or network.
CPU temperature
This script retrieves local CPU temperature. You need to enable ACPI and know the path to the file that shows the CPU temp. By default it is set to /proc/acpi/thermal_zone/THRM/temperature. It just runs on Linux (or Unix-like).
cputemp.py, 8 lines [download]
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- TemperatureString=open('/proc/acpi/thermal_zone/THRM/temperature', 'ro')
- CpuTempArray=TemperatureString.readline().split(" ")
- CpuTempArray2=CpuTempArray[1].split(" ") #I know, too much code, but is easy to understand the code in this way
- CpuTemp=CpuTempArray2[0]
- print CpuTemp
Templates required by cacti for graphs generation:
cacti_data_template_linux_cpu_temperature.xml, 81 lines [download]
- <cacti>
- <hash_0100129ce4ea160a6bc98071432804c815133b>
- <name>Linux - CPU Temperature</name>
- <ds>
- <t_name></t_name>
- <name>|host_description| - CPU Temperature</name>
- <data_input_id>hash_030012ed73b72e78600194d76aeb45acba6c91</data_input_id>
- <t_rra_id></t_rra_id>
- <t_rrd_step></t_rrd_step>
- <rrd_step>300</rrd_step>
- <t_active></t_active>
- <active>on</active>
- <rra_items>hash_150012c21df5178e5c955013591239eb0afd46|hash_1500120d9c0af8b8acdc7807943937b3208e29|hash_1500126fc2d038fb42950138b0ce3e9874cc60|hash_150012e36f3adb9f152adfa5dc50fd2b23337e</rra_items>
- </ds>
- <items>
- [...]
cacti_graph_template_linux_cpu_temperature.xml, 192 lines [download]
- <cacti>
- <hash_000012a27d0a0c50135897c3512003842ee4b7>
- <name>Linux - CPU Temperature</name>
- <graph>
- <t_title></t_title>
- <title>|host_description| - CPU Temperature</title>
- <t_image_format_id></t_image_format_id>
- <image_format_id>1</image_format_id>
- <t_height></t_height>
- <height>120</height>
- <t_width></t_width>
- <width>500</width>
- <t_auto_scale></t_auto_scale>
- <auto_scale>on</auto_scale>
- <t_auto_scale_opts></t_auto_scale_opts>
- [...]
uptime
This script gets the uptime of the local system. Only for linux:
uptime.py, 7 lines [download]
- #!/usr/bin/python
- # -*- coding: UTF-8 -*-
- UptimeString=open('/proc/uptime', 'ro')
- UptimeStrings=UptimeString.readline().split(" ")
- UptimeTotal=eval(UptimeStrings[0])
- UptimeIdle=eval(UptimeStrings[1])
- print "up_total:"+str(UptimeTotal/(60.*60.*24.))+" up_idle:"+str(UptimeIdle/(60.*60.*24.))
And cacti templates:
cacti_data_template_linux_uptime.xml, 104 lines [download]
- <cacti>
- <hash_0100123d1c7767910ab74d09e7dcda0c21cc6a>
- <name>Linux - Uptime</name>
- <ds>
- <t_name></t_name>
- <name>|host_description| - Uptime</name>
- <data_input_id>hash_030012cf27b91d2d60b82d92209f123ccc43cd</data_input_id>
- <t_rra_id></t_rra_id>
- <t_rrd_step></t_rrd_step>
- <rrd_step>300</rrd_step>
- <t_active></t_active>
- <active>on</active>
- <rra_items>hash_150012c21df5178e5c955013591239eb0afd46|hash_1500120d9c0af8b8acdc7807943937b3208e29|hash_1500126fc2d038fb42950138b0ce3e9874cc60|hash_150012e36f3adb9f152adfa5dc50fd2b23337e</rra_items>
- </ds>
- <items>
- [...]
cacti_graph_template_linux_uptime.xml, 233 lines [download]
- <cacti>
- <hash_00001268bbf93247900d33874f4ad3b553adb0>
- <name>Linux - Uptime</name>
- <graph>
- <t_title></t_title>
- <title>|host_description| - Uptime</title>
- <t_image_format_id></t_image_format_id>
- <image_format_id>1</image_format_id>
- <t_height></t_height>
- <height>120</height>
- <t_width></t_width>
- <width>500</width>
- <t_auto_scale></t_auto_scale>
- <auto_scale>on</auto_scale>
- <t_auto_scale_opts></t_auto_scale_opts>
- [...]
ProjectsElectronicsCLK³pic³progMechatronicsSoftwarePigmeoOthermabxArticlesElectronicsSoftwareOtherAdvantages of C#Events2nd (inter)Universitary Free Software ContestMicrobotics championship at the University of Oviedo. Summer 2007About urriellu.netThis websiteAbout mePublishing licensesContact
languageespañolrot13morse codebrailleenglishrot13morse codebraille