Saturday, September 25, 2010

How to combine Munin and TEMPer (USB Temperature Sensor) ?

Long long ago I always wrote about technical stuff in my computer experience.
It's about time to write something on that topic again and the story is about Munin (example) and TEMPer (USB Temperature Sensor).



I decided that I want to keep an eye on the room's temperature and I searched for the cheapest possible external (USB) Termal Sensor. That's how I get hands on one of these TEMPer termal sensors.
It turns out that the sensor is great for the job except it's installation under linux (Ubuntu) in my case.

So here are the steps for installing it under Ubuntu and adding a patched "sensors_" plugin for Munin.

First you need to install "temper_mon.pl"

1) sudo apt-get install libusb-dev
2) sudo cpan -fi ExtUtils::MakeMaker
3) sudo cpan -fi Inline::MakeMaker
4) sudo cpan -fi Device::USB
5) sudo cpan -fi Device::USB::PCSensor::HidTEMPer
6) wget -O temper_mon.pl http://www.svilen.com/temper_mon.pl.txt
(alternative: wget -O temper_mon.pl http://www.cs.unc.edu/~hays/dev/bash/temper/temper_mon.pl)

7) chmod a+x temper_mon.pl
8) run: sudo ./temper_mon.pl
(you should see temperature readings now)

9) sudo cp ./temper_mon.pl /usr/bin/
(this is needed for the Munin plugin)

10) sudo wget -O /etc/udev/rules.d/99-tempsensor.rules http://www.svilen.com/99-tempsensor.rules

or create file: /etc/udev/rules.d/99-tempsensor.rules
with this line inside:
SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="1130", ATTRS{idProduct}=="660c", MODE="666"

11) sudo /etc/init.d/udev restart

Now you should have fully running "temper_mon.pl" script which will give you readings from the USB Temper device.

Next step is to backup and replace Munin's "sensors_" plugin in /usr/share/munin/plugins

1) sudo mv /usr/share/munin/plugins/sensors_ /usr/share/munin/plugins/sensors_old
2) sudo wget -O /usr/share/munin/plugins/sensors_ http://www.svilen.com/sensors_.txt
3) service munin-node stop
4) service munin-node start

Now wait 5-10min and you should have reading in your Munin graphics.



Enjoy!

Home Made Surge Protector

After my Petzl Tikka upgrade I am continuing with the electro stuff (my new-old childhood hobby).

Two days ago a lightning stroke our neighbours, so it was time for all-in-the-house Surge Protectors so I went to the local hardware shop to buy some.
Unfortunately the cheapest ones costed 13-15$ which is pretty much for me as I needed at least 4 or 5. I already had connection-blocks and I had to add only the protection.

Why not do it myself? Of course I will and it costed around 2$ per piece. What a bargain? Huh?
Yes, that it 2$ per piece. All you need is a proper varistor (in my case 20N391K) and put it into a nice plug.

In short what you need is:
- a new Plug
- a varistor 250V, ~25ns (example: 20N391K)

1) All you need.

1) Initial setup on the varistor inside the Plug.

3) How I added this to a connection-block.

4) Plug is ready lets close it.



5) Plug is close and ready for some tests.

6) I decided to add some image so that I know which plugs are protected already.


Nice job!
3 hours, no more than 10$ and all home connection-blocks are protected from lightning.

Try it but be very careful.
You are working with 220V.
It can kill you if do not take precautions!

Sunday, September 12, 2010

Petzl Tikka Plus mod

Last week I was wondering if it's worth buying a new Petzl Tikka XP 2 headtourch.So I decided that I need to see it live first and went to the local shop. Unfortunately I was badly surprised. This new Tikka was heavier, bigger and wasn't producing much more light than my old one - Petzl Tikka Plus.

When I came back home I started reading forum about upgrading Tikka Plus and I saw that most people managed to change the LEDs with some new Ultra bright LEDs from Nichia (Japan) and the result was astonishing.
And as a ex-Technical university student I was eager to try this, too - ordered Nichia GS diodes from www.led-tech.de and started the test.

Below I am showing some pictures taken during the switch to the new diodes.


1) Here are all the tools I've used and disassembled Tikka.






2) Original Tikka PCB with one LED removed




3) All old LEDs removed.


4) Package from LED-TECH.de with the new diodes - Nichia GS.


5) Petzl Tikka Plus PCB with Nichia GS diodes installed.





6) Tikka Plus with Nichia GS (on the left) vs Tikka Plus with original diodes (on the right)
You can see that the GS is more warm and slightly better.

*) I could also add that the batteries of the Tikka with Nichia GS were a little bit "exhausted" (I had only 3 new batteries, so I decided to put them on the Tikka Original)


7) Petzl Tikka - Nichia GS diodes vs Petzl Tikka - Original diodes


As a conclusion I could say only - TRY Nichia GS or Nichia DS LEDs!!!

*) Nichia DS should be a little bit warmer than GS, but GS are brighter. Both are great! Do not hesitate to try the DS, too. Difference is really small.

Sunday, May 02, 2010

Google App Engine Twitter Bot

After I became familiar with Python and Google's hosting platform (called App Engine) I decided to write my first app for the platform.

And here it is - a simple Twitter bot which get's shared posts with comments "#twitter" from your Google Reader Atom feed and posts them to your Twitter feed.

*) UPDATE (02 Feb 2011): Since Twitter discontinued the Basic API Access, I modified the bot to use the oAuth Twitter API
I also changed the shorten url service to http://bit.ly

Take a look and change the following lines in twitter.py file accordingly in order to run the app successfully:

# First you need to create an app here
# http://twitter.com/oauth or http://dev.twitter.com/apps/
# and get the codes below
TWITTER_CONSUMER_KEY = 'YOUR KEY'
TWITTER_CONSUMER_SECRET = 'YOUR SECRET'
# The next codes are found http://dev.twitter.com/apps/
# right menu, after you clicked on the app
TWITTER_ACCESS_TOKEN = 'TWITTER TOKEN'
TWITTER_ACCESS_TOKEN_SECRET = 'TWITTER TOKEN SECRET'
# bit.ly api keys found at: http://bit.ly/a/your_api_key
BIT_LY_USERNAME = 'YOUR USERNAME'
BIT_LY_API_KEY = 'YOUR API KEY'
# Google reader feed URL
# example is mine below
GOOGLE_READER_FEED_URL = 'http://www.google.com/reader/public/atom/user/07723902623423188282/state/com.google/broadcast'

If you have questions leave your comments below. I will try to help you.

Python 2.6 & Google App Engine

Some of you may know that I am mainly developing on PHP (as a backend language) and MySQL database with different storage engines (XtraDB, InnoDb and PBXT).

A week ago I decided to get involved more deeply into Python and Google App Engine platform. I was already looking into Python as a generic type language for my system administration needs which arised in the last two months.
I know that all (most of) sys-admins use Perl as it is their old-school tool-language, but I wanted something better with easier and cleaner syntax and flexible enough.

So here came Python and it's brief tutorial. I must say it's fabulous and easy to understand.
I recommend you take a look at it (please read it carefully, there is nothing unnecessary written) and also watch some of the Google I/O talks of the Google Python gurus - Guido van Rossum (Pythons creator) and Alex Martelli.

Painless Python part 1 by Alex Martelli
Painless Python part 2 by Alex Martelli

Google App Engine is a new (to me) scalable platform for building web apps and I must say it's very easy for start. You don't have to think about software tuning, optimization, etc. Except of course the optimization algorithms and hints given from Google on how to build a successful app, which are easy to take in account. After you've become familiar with Python you may want to take a closer look at App Engine and the provided Python APIs.
Yes instead of software and a dedicated server you get an application storage space and a bunch of APIs. Pretty interesting approach for hosting from Google, but I must admit it is very conveninent. That way Google takes care about all software and service tuning, configuration, etc. and as a Developet you only have to ... DEVELOP.

Here are some interesting talks about Google's App Engine:

Python, Django and App Engine by Guido van Rossum
Building Scalable Web Apps with App Engine by Brett Slatkin (Google's App Engine main engineers)
App Engine Datastore Under the Covers by Ryan Barrett (lead App Engine datastore)

Enjoy!

Monday, April 26, 2010

MySQL Tuner

For those of you which does not have a clue how to optimize your MySQL machines, try MySQL Tuner script.

I recommend it even to experienced guys.

Hope Major Hayden will find a good follower who will continue the support of the script.

Sunday, April 25, 2010

NoSQL fashion

I am sure some of you have already heard about NoSQL and available solutions like MongoDB, Cassandra, etc.

Yes, everything came back from Google's Bigtable and the ideas standing behind it.
And if you want to learn more go watch the Guide to NoSQL from Brian Aker and part 2.

Performance tool

Today I went over Poor man's profiler.
A simple & great tool to see what's going on your server.


Wednesday, March 03, 2010

XMPP Web Chat

Recently I had to develop a scalable web chat which should be compatable with normal chat software like Aduim, Miranda, etc.
I decided to use a XMPP server and I liked Brad Fritzpatriks Djabberd because it's easy scalable, memory optimized (300k+ connection in only 1GB RAM), written in Perl (one of the languages I am familiar with) and easily customizable.

All went okay during the tests with Adium and PSI and I managed to complete the custom modules in just two days.

But then there was the last part - web chat system integration. I stoped my attention to JwChat looks nice and has a Facebook alike bar aka iJabBar.

And here begins the Hell ...

All web based XMPP chat clients use so called HTPP-Binding ot Polling for communication (aka BOSH) to connect to Jabber server and Djabberd has no plugin for that. Sure at first I thought I can write one but ... isn't there anything already done? ... and no, there is nothing.

I started searching for a compromise solution and I went over JabberHTTPBind and Punjab. Both unreliable and buggy. Both tested on Mac OS X and Linux. At first I tried to fix JabberHTTPBind which is written in Java, but unfortunately I am not so experienced in Java programming to fix everything and XML parsing bugs left.
Punjab on the other hand is written in python which I am familiar with but after 4 hours of debugging and trying to fix it's XML parser, too, finally I gave up.

Now, after posting this I will go and write a working XMPP BOSH script using libevent and based on phpDaemon (asynchronous PHP framework). I am starting to think like Brad (formerly SixApart's guy and now working for Google) - if there is no solution or everything out there just sux, do write your own and do it well.

Tuesday, March 02, 2010

Performance

Everyone in IT field who know me well is aware that I am a performance maniac.
I love making software run faster with the same resources, I love saving machines/hardware, etc.

On this topic I would recommend you a short paper about optimizations which focuses on how you should think about it to do it in the right way.

One we interesting part of the paper is:

"Won’t software with extra code path to measure timings be slower than the same software without that extra code path?

I like an answer that I heard Tom Kyte give once in response to this question.15 He estimated that the measurement intrusion effect of Oracle’s extensive performance instrumentation is negative 10% or less. 16 He went on to explain to a now-­‐vexed questioner that the product is at least 10% faster now because of the knowledge that Oracle Corporation has gained from its performance instrumentation code, more than making up for any “overhead” the instrumentation might have caused."

I admire the Tom Kyte's answer. I want to point a finger at the face of all system administrators, CTO's, etc. - people turn on logs and your profile systems. They really help developers to optimize their code. Do not just blame them that the application sucks.


And if you want to read more check Baron Schwartz's bookshelf.

Thursday, February 25, 2010

Fast & efficient Smarty view renderer for Yii Framework

Working with online games and especially PenguinFarmer and using Yii Framework I've been driven to solve a problem with Smarty view renderers available already on the internet.

Smarty was a required template engine by the web designers, so I should have found a way to optimize the plugin or just write a new one.

And here it is. Fast, efficient and tested on a huge traffic.
One of the first problems I faced wa that the regular Smarty renderers do failer when there were huge amount of traffic as they render the template then saves it into a temp file ready for the PHP renderer mechanism which Yii has.
There are major issues here which cause unnecessary overhead.

1) Why do we need to save the rendered view template? This is a unnecessary disk I/O
2) Why do we need to read the smarty parsed temp file again to parse it as a PHP template? Again unnecessary disk I/O
3) When there is a lot of traffik there is a gap between writing a smarty template and reading it again. So many times there were a blank pages or wrong smarty templates. Even with fast HDDs there we enought time between reads and writes so we can get problems.

After going throught the code, optimizing it and testing I am glad to present you a good and reliable Smarty view renderer for Yii Framework that you can use as a drop in replacement for your current one.


Tuesday, February 09, 2010

Git - Linus Torvalds

I finally tried Torvald's Git version system and I can tell you - it's AWESOME!

Really. The way you can commit in just a second is so comfortable.

Watch his tech talk here.

More comming soon ...