Digital Memo All begin with 0 & 1

5Jul/140

Monitor CPU Usage and send E-mail alerts

Sometimes the server is having CPU load more than 100, and SSH is virtually not accessible. I am unable to execute "TOP" command to check the misbehaving processes.

Here is my first Shell Script, tested on CentOS. It checks the threshold for last 5 minutes, and send email with TOP log to designated E-mail.

#!/bin/bash

THRESHOLD=10.0
EMAIL="example@gmail.com"

#grab usage of last 5 minutes.
USAGE5=$(uptime | grep -ohe 'load average[s:][: ].*' | awk '{ print $4 }' | tr -d ',')
echo "Current usage:" $USAGE5

if (( $(echo "$USAGE5 > $THRESHOLD" | bc -l ) )); then
echo "Dangerous"
echo "Subject: vps.example.com CPU HIGH ($USAGE5)" > /tmp/top-output.txt
echo "" >> /tmp/top-output.txt ; top -n1 -b >> /tmp/top-output.txt
sendmail $EMAIL < /tmp/top-output.txt
else
echo "Safe"
fi

To make this script work, remember to add the cronjob /etc/crontab, and chmod +x to allow execution of Shell Script via cron job.

pixelstats trackingpixel
Filed under: Linux No Comments
31Jan/140

Slow QVod (Kuaibo) on Mac OSX

To date, I am using QVod 1.1.26. It has been a great video player with a lot of sources across the internet.

However, I have been experienced a slow download. The download speed is around 80kB/s with a 4M broadband. Supposely it should run 300kB - 400kB without any trouble.

Fortunately, I am able to find out the issue. It happens once your MacBook is offline ( sleeping to save battery) and then awake / online again.

The only thing you need to do to gain back the download speed, is to kill the process "QvodTerminal".

If you are unsure how to do this, here are the steps:

How to kill QvodTerminal process to speed up downloads

How to kill QvodTerminal process to speed up downloads

  1. Use spotlight to look for "Activity Monitor" and open it.
  2. In Activity Monitor window, switch to "Network" tab.
  3. Look for the "QvodTerminal" terminal in the long list. Select it, and hit the "Force a process to quit" button (x) on the left side.
  4. Wait for a few seconds, QvodTerminal will be restarted again. All downloads are stopped and restarted too. Observe your Qvod Application if the download speed has been gradually increased.

This is it. I wish you enjoy your Kuaibo!

pixelstats trackingpixel
Tagged as: , , No Comments
2Dec/130

A more productive Windows 8

Make your Windows 8 more productive in desktop! Get back how your Start Menu should look like. Finally, I don't feel like dumb and lost in Windows 8.

http://www.classicshell.net/

pixelstats trackingpixel
Filed under: windows No Comments
2Dec/130

MySQL: Update table record base on record from another table

Useful MYSQL code snippet. It update certain table column value base on value from another table.

UPDATE updatefrom p, updateto pp
SET pp.last_name = p.last_name
WHERE pp.visid = p.id
pixelstats trackingpixel
Tagged as: No Comments
20Jun/130

Importance of Header Response Content-type

Does header response content-type a matter?

There is a problem bugging me for a few months: a small bunch of users using my Android app are unable to view the content when they turn on their 3G. The content data is fetched as web services, either in XML or JSON format.

Pretty weird. First of all I suspect the problem could be due to routing problem, from my web services to the users. Few months later, I changed my web hosting and with different server and IP address, the problem still persist.

Further investigation found out that:

  1. They are from the same telco M.
  2. And it comes from the same range x.x.x.* .

Then I suspect that is there something wrong with the backbone ISP, or with the domain registrar.

Until two users told me the same thing: they managed to visit my website via browser, but were unable to see the drop down menu (my dropdown menu is base on JSON response).

Until then, I re-check my services, and put header response for each of the output.

For XML:


header("Content-type:application/xml");

For JSON:


header("Content-type:application/json");

And finally, users reported that they are able to view the contents.

Though the problems seem to be solved, but the mystery still remain: why is it only with Telco M, with that kind of IP range, is having problem viewing the JSON/XML format when the header content-type is not set?

pixelstats trackingpixel
Filed under: Uncategorized No Comments
19Mar/130

PHP Snippet: read files info and contents without extracting

A very useful PHP code snippet. It read the contents and info of the files in zip file without actually extracting them.


$zip = zip_open("D:tests".$outFile);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
echo "Name: " . zip_entry_name($zip_entry) . "n";
echo "Actual Filesize: " . zip_entry_filesize($zip_entry) . "n";
echo "Compressed Size: " . zip_entry_compressedsize($zip_entry) . "n";
echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "n";
if (zip_entry_open($zip, $zip_entry, "r")) {
echo "File Contents:n";
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
echo "$bufn";
zip_entry_close($zip_entry);
}
echo "n";
}
zip_close($zip);
}

For performance wise, I didn't really test it, as I did not feel any performance hit with a zip file of 20MB and 100MB+ uncompressed file.

Referrel link: http://www.whileifblog.com/2012/03/24/php-read-filescontentfile-details-from-a-zip-archive-without-extracting-them/

pixelstats trackingpixel
Filed under: PHP No Comments
8Feb/130

iOS development notes

Locating iOS Simulator folder location in Finder:

  1. from spotlight, open Activity Monitor
  2. Look for "your app name"
  3. Double click, and click on the tab "Open Files and Ports"
  4. Copy the first path
  5. Open finder window, press "Command + Shift + G", paste in the path and open.
    * Note that Users/username/Library folder is hidden.

Checking line number and filename from crash reports

  1. Need to locate file ".app.dSYM" of the release
    1. From XCode > Organizer > Archives
    2. Select the correct version that match the crash reports downloaded from itunes Connect
    3. Right click > Show in Finder
    4. On archive file, right click > Show package content
    5. folder dSYMs > copy the file to new folder of your convenient
  2. Open terminal
  3. Use the command below:
    dwarfdump --lookup 0x00107fef -arch armv7 yourappname.app.dSYM
  4. Command above might be different (might be armv6)
pixelstats trackingpixel
26Jan/131

Google Analytics: the Gone by Hours

Google Analytics had one of my favourite report before: the 00 to 24 hourly reports option in the past.

Google Analytics Hourly in old time

However, overtime when GA has changed and change, the option is now longer there. It's frustrating.

Though not as good as before, I am able to get the average views by hours over defined periods by using Custom Reports. Here is how:

  1. Click on Customization
  2. Fill in Title of your report
  3. Under Report Content, choose "Visits" (or PageViews, Unique Vistors, etc of your preference) for Metric, and choose "Hour" for Dimension Drilldown.
  4. Scroll to the bottom and click "Save"
Google Analytics Custom Report

Google Analytics Custom Report

Now you will able to see the report as follow:

Analytics by Table

Analytics by Plain Table

Analytics bar graph

Analytics bar graph

Unfortunately, one of the problem now is that, when you view by Graph, you can't sort the hour value. It can be sorted by the number of visits only. I have sent this report to GA team and lets hope they can fix this in near future. In the meantime, you may export the report as CSV and do the charting at Microsoft Excel.

pixelstats trackingpixel
21Jan/130

MySQL ODBC issue in C#

Recently I have migrated my office PC from Windows XP 32-bit to Windows 7 64-bit.

The migration was smooth until I am unable to connect to the MySQL via ODBC in my Visual Studio 2010 c# project.

The debugger throws the following message:

ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
this.DbConnection.ServerVersion' threw an exception of type 'System.InvalidOperationException'

I have installed both 64-bit ODBC driver from MySQL  and surprisingly, not working at all. I have been tinkering with the connection string too, but without success too.

Finally, base on some information found online, I decided to install the 32-bit MySQL ODBC drivers and finally it works! It works on both version 5.1 and version 5.2.


<add name="databaseString" connectionString="Driver={MySQL ODBC 5.2a Driver};Server=localhost;Database=dbname;User=root;Password=;option=3" providerName="System.Data.Odbc" />

I am wondering what happen to 64-bit drivers?

pixelstats trackingpixel
Tagged as: , , No Comments
9Sep/122

SQLite drives me crazy

I have been using SQLite in Android development. Some calculation is needed through query, e.g:


SELECT sum(ColumnA* ColumnB) / sum(ColumnC) FROM table

In certain circumstance, when the ColumnA and Column B are both integer, the resulting simply give me an integer (which should be a number with decimal point).

For example, a value of 500 / 200 = 2.5, but the resulting value is simply 2.

Have been checking through coding and query to check what's wrong, taking me few hours due to slow Eclipse IDE during debugging.

To fix this, if we wish to return a decimal point number, always make the number as decimal point even if it is an integer, before any calculation.


SELECT sum(ColumnA * 1.0 * ColumnB) / sum(ColumnC) FROM table

pixelstats trackingpixel