Merhabalar,
Cosm.com cihazlarınızından veri alarak/isteyerek çalışan ve bunu hoş grafiklere dökerek size sunan bir hizmettir. Cihazımızın disk durumu, sıcaklık, hafıza gibi bilgilerini buradan zamana bağlı olarak takip edebiliriz.
Öncelikle cosm.com sitesine gidip üyelik açıyoruz. Üye olduktan sonra Device/Feed ekle butonu kullanarak Something Else tıklıyoruz.
Step 1 Data: No, I will push data to Cosm
Step 2 Title: Cihazın ismini yazabilirsiniz
Step 3 Tags: Anahtar kelimelerinizi yazabilirsiniz, ben boş bıraktım.
Step 4- Create: Ve oluştur butonu ile cihaz besleme verimizi ekliyoruz. Feed idyi bir yere not ediyoruz.
Sağ üst taraftaki menüden Keys linkine tıklıyoruz. Label kısmına bir isim yazıp erişim ve güvenlik ayarlarınızı seçiyorsunuz ve oluştur butonu ile devam ediyoruz. Çıkan uzun kodlu anahtarı tekrar bir yere not ediyoruz az sonra lazım olacak. Burada işimiz bitti, piye geri dönüyoruz.
/home/pi içine scripts isimli bir klasör açıp içine cosm.py isimli bir dosya yaratıyoruz. Bunu gerek terminalden komut girerek gerekse webmin kullanarak yapabilirsiniz.
Dosya için şu komutları yazıyoruz;
1# cosm.py Copyrigth 2012 Itxaka Serrano Garcia
2 # licensed under the GPL2
3 # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt
4 #
5 # You only need to add 2 things, YOUR_API KEY HERE and YOUR_FEED_NUMBER_HERE
6 # also, you can change your stream ids, in that case change the id names in the "data = json.dumps..." line</code>
7
8import json, subprocess, os
9
10cpu_temp = subprocess.check_output(["sudo /opt/vc/bin/vcgencmd measure_temp | cut -c6-9"], shell=True)
11
12hdd = subprocess.check_output(["df | grep rootfs | awk '{print $2,$4,$5}'"], shell=True)
13 hdd = hdd.split()
14 hdd = int(hdd[1]) / 1024
15
16cpu = subprocess.check_output(["vmstat | awk '{print $13}'"], shell=True)
17 cpu = cpu.split()[1]
18
19mem = subprocess.check_output(["cat /proc/meminfo | grep Mem | awk '{print $2}'"], shell=True)
20 mem = mem.split()
21 mem_total = int(mem[0]) / 1024
22 mem_free = int(mem[1]) / 1024
23 mem_used = mem_total - mem_free
24
25data = json.dumps({"version":"1.0.0", "datastreams":[{"id":"cpu_temp","current_value":cpu_temp},{"id":"hdd","current_value":hdd },{"id":"cpu","current_value":cpu},{"id":"free_mem","current_value":mem_free},{"id":"used_mem","current_value":mem_used}]})
26 with open("temp.tmp", "w") as f:
27 f.write(data)
28
29subprocess.call(['curl --request PUT --data-binary @temp.tmp --header "X-ApiKey: BURAYA API ANAHTARINIZ GELECEK" http://api.cosm.com/v2/feeds/BURAYA FEED NUMARANIZ GELECEK'], shell=True)
30
31os.remove("temp.tmp")
Sondan 2. satırda BURAYA API ANATARINIZ GELECEK yazan yere API anahtarınızı kopyalıyorsunuz, feed no isteyen yere ise feed idnizi kopyalayın. Dosyayı kaydedip kapatabiliriz.
/etc içindeki crontab dosyasını açıp en alt satıra
1*/10 * * * * python /home/pi/scripts/cosm.py
ekliyoruz. Bu her 10 dakikada bir siteye bilgi gönderecektir. Ve 5-10 dakika sonra siteye girip grafiklerin oluşmasını bekleyebiliriz.
Cosm.com cihazlarınızından veri alarak/isteyerek çalışan ve bunu hoş grafiklere dökerek size sunan bir hizmettir. Cihazımızın disk durumu, sıcaklık, hafıza gibi bilgilerini buradan zamana bağlı olarak takip edebiliriz.
Öncelikle cosm.com sitesine gidip üyelik açıyoruz. Üye olduktan sonra Device/Feed ekle butonu kullanarak Something Else tıklıyoruz.
Step 1 Data: No, I will push data to Cosm
Step 2 Title: Cihazın ismini yazabilirsiniz
Step 3 Tags: Anahtar kelimelerinizi yazabilirsiniz, ben boş bıraktım.
Step 4- Create: Ve oluştur butonu ile cihaz besleme verimizi ekliyoruz. Feed idyi bir yere not ediyoruz.
Sağ üst taraftaki menüden Keys linkine tıklıyoruz. Label kısmına bir isim yazıp erişim ve güvenlik ayarlarınızı seçiyorsunuz ve oluştur butonu ile devam ediyoruz. Çıkan uzun kodlu anahtarı tekrar bir yere not ediyoruz az sonra lazım olacak. Burada işimiz bitti, piye geri dönüyoruz.
/home/pi içine scripts isimli bir klasör açıp içine cosm.py isimli bir dosya yaratıyoruz. Bunu gerek terminalden komut girerek gerekse webmin kullanarak yapabilirsiniz.
Dosya için şu komutları yazıyoruz;
1# cosm.py Copyrigth 2012 Itxaka Serrano Garcia
2 # licensed under the GPL2
3 # see the full license at http://www.gnu.org/licenses/gpl-2.0.txt
4 #
5 # You only need to add 2 things, YOUR_API KEY HERE and YOUR_FEED_NUMBER_HERE
6 # also, you can change your stream ids, in that case change the id names in the "data = json.dumps..." line</code>
7
8import json, subprocess, os
9
10cpu_temp = subprocess.check_output(["sudo /opt/vc/bin/vcgencmd measure_temp | cut -c6-9"], shell=True)
11
12hdd = subprocess.check_output(["df | grep rootfs | awk '{print $2,$4,$5}'"], shell=True)
13 hdd = hdd.split()
14 hdd = int(hdd[1]) / 1024
15
16cpu = subprocess.check_output(["vmstat | awk '{print $13}'"], shell=True)
17 cpu = cpu.split()[1]
18
19mem = subprocess.check_output(["cat /proc/meminfo | grep Mem | awk '{print $2}'"], shell=True)
20 mem = mem.split()
21 mem_total = int(mem[0]) / 1024
22 mem_free = int(mem[1]) / 1024
23 mem_used = mem_total - mem_free
24
25data = json.dumps({"version":"1.0.0", "datastreams":[{"id":"cpu_temp","current_value":cpu_temp},{"id":"hdd","current_value":hdd },{"id":"cpu","current_value":cpu},{"id":"free_mem","current_value":mem_free},{"id":"used_mem","current_value":mem_used}]})
26 with open("temp.tmp", "w") as f:
27 f.write(data)
28
29subprocess.call(['curl --request PUT --data-binary @temp.tmp --header "X-ApiKey: BURAYA API ANAHTARINIZ GELECEK" http://api.cosm.com/v2/feeds/BURAYA FEED NUMARANIZ GELECEK'], shell=True)
30
31os.remove("temp.tmp")
Sondan 2. satırda BURAYA API ANATARINIZ GELECEK yazan yere API anahtarınızı kopyalıyorsunuz, feed no isteyen yere ise feed idnizi kopyalayın. Dosyayı kaydedip kapatabiliriz.
/etc içindeki crontab dosyasını açıp en alt satıra
1*/10 * * * * python /home/pi/scripts/cosm.py
ekliyoruz. Bu her 10 dakikada bir siteye bilgi gönderecektir. Ve 5-10 dakika sonra siteye girip grafiklerin oluşmasını bekleyebiliriz.