Display system uptime in a website

15 06 2018

Here are the steps to set up a simple website which shows the uptime values of a system.

First of all, install the requirements. Tuptime for monitor the system, apache as web server and php for the web. The web server can be nginx as well, their only requirement is that has to be able to work with php.
apt-get install tuptime apache2 php

Go to the document root location of the webserver and download the web file from the offical repo:
cd /var/www/html/
wget https://raw.githubusercontent.com/rfrail3/tuptime/master/misc/web/sample-wrapper-tuptime.php -O tuptime.php

That’s all, use a web browser to open the following url and view it:
http://127.0.0.1/tuptime.php

Uptime web

Advertisements




Testing IOPS in VMware

23 04 2018

Take a test vm and add a new spare hard disk. Don’t use the operating system disk or any other with is already in use.

Limit the IOPS in that disk to 17, for example. Do that in the menu of the vm under Edit Configuration > Hard Disk (the new one) > Limit IOPS > Custom > 17

Create a partition, format it and mount, in this case, under “/mnt/sdb1”

In one terminal, launch a basic dd which write to that directory:
# while :; do dd if=/dev/zero of=/mnt/sdb1/test bs=1k count=1; done

In other terminal, watch how iostat report the exact “IOps” in the “tps” column:

# iostat 1 /dev/sdb
avg-cpu: %user %nice %system %iowait %steal %idle
1.50 0.00 0.50 49.00 0.00 49.00
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sdc 17.00 0.00 84.00 0 84

If you have a graphic monitoring system, like Prometheus + Grafa + Node Exporter Full, check it in the graphs:

iops vmware

iops vmware





Encrypt a file with .asc public key

27 02 2018

gpg --import file.asc
gpg -se -r "Name of imported public key" file_to_encrypt





Add autopkgtest to .deb package

25 01 2018

These are the example steps for add a very simple autopkgtest test to an existing Debian package:

  • Add to debian/control the following line:
Testsuite: autopkgtest
  • Create the folder debian/tests
  • Add the control file under debian/tests/control with the following content:
Tests: smoke
Depends: @
  • Create a simple script using the name of the test debian/tests/smoke:
#!/bin/sh
my_program
  • Create the package as usual (maybe with dpkg-buildpackage -us -uc) and run the test:
autopkgtest --output-dir /tmp/output-dir1 -B my_program*.changes -- null

Note: Usefull examples in https://codesearch.debian.net/
More info: https://ci.debian.net/doc/file.MAINTAINERS.html





Check SLA uptime in a linux server

13 01 2018

When a new server is up, usually from a remote provider, their reliability is covered under a Service License Agreement. In that document is reflected the garanteed uptime of the machine, a percentage value close to 100% which assure the time that the server have to be up.

There can be other clauses with the network uptime, storage uptime, what ever other service we had uptime that will aso have to be taken into account to the global uptime of our service. But now we are only going to focus exclusively on the operating system uptime. To know what is the value from our side, these are the steps:

When you have the access to the new server, as soon as posible, install the Tuptime package:

# apt-get install tuptime

Increase the sync interval. By default it save the time on disc each 5 minutes, which is ok for a normal user, but to have it as detailed proof of service, it can be done each minute. Change in “/etc/cron.d/tuptime” from:

*/5 * * * * tuptime if [ -x /usr/bin/tuptime ]; then /usr/bin/tuptime -x > /dev/null; fi

To:

* * * * * tuptime if [ -x /usr/bin/tuptime ]; then /usr/bin/tuptime -x > /dev/null; fi

Or more agressive, assure the sync operation to disc too:

* * * * * tuptime if [ -x /usr/bin/tuptime ]; then /usr/bin/tuptime -x && sync > /dev/null; fi

Now it’s done, wait a few days or weeks and check how are things going.

Check the uptime for the last month. As one month (30 days) are 2592000 seconds, get the last n seconds from date:

# tuptime --tsince -2592000
System startups: 3 since 15:17:42 14/12/17
System shutdowns: 1 ok - 1 bad
System uptime: 97.3 % - 29 days, 4 hours, 35 minutes and 7 seconds
System downtime: 2.7 % - 19 hours, 24 minutes and 53 seconds
System life: 30 days, 0 hours, 0 minutes and 0 seconds
...

Check the uptime for the last year. As a year have 31536000 seconds:

# tuptime --tsince -31536000
System startups: 6 since 15:20:03 13/01/17
System shutdowns: 1 ok - 4 bad
System uptime: 94.39 % - 344 days, 12 hours, 33 minutes and 46 seconds
System downtime: 5.61 % - 20 days, 11 hours, 26 minutes and 14 seconds
System life: 1 year, 0 days, 0 hours, 0 minutes and 0 seconds>
...

The output give us a clear report of the uptime percentage. Even, it is possible to see the exact date and time if the “-t” table or “-l” option are passed to the command.

This is a good option to check the garanteed value without using any graph or pannel provided by the server provider. We have a strong view of how good or bad are service, any strange restart, even those that happen at intimely hours, will be registered and counted in the tuptime report.

Note:
If is required in the report an uptime / downtime percentage larger than two decimals, which is the default, use “–decp” option with the desired lenght.

More info:
https://github.com/rfrail3/tuptime/





Test haproxy 1.8 seamless reload

10 01 2018

How to test the seamless reload option in Haproxy 1.8.

Add into the configuration file under global section the following line:
stats socket /var/run/haproxy.sock level admin expose-fd listeners process 1

Create a reload loop for the service:
# while true ; do systemctl reload haproxy ; sleep 3 ; done

Send request while service is reloading:
# ab -r -c 20 -n 100000 http://127.0.0.1/

Check that the report doesn’t cotains any “Failed requests”.

More info:
https://bugs.launchpad.net/ubuntu/+source/haproxy/+bug/1712925





Python script who generates threads

5 01 2018

#!/usr/bin/env python3
import time
from threading import Thread
num_threads = 100
sleep_secs= 60
def create_thread(i):
print "Sleeping "+ str(sleep_secs) +" secs - Thread %d \n" % i
time.sleep(sleep_secs)
for i in range(num_threads):
t = Thread(target=create_thread, args=(i,))
t.start()
print "End"

View threads in top pressing “H”
View threads in ps with “-T”