Tikejhya: Ashish Nepal

Knowledgebase

Category: Monitoring Tool (Page 1 of 2)

SysBench on CentOS – HowTo

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

cd /usr/local/src

wget http://sourceforge.net/projects/sysbench/files/latest/download
tar -xvzf sysbench-0.4.xx.tar.gz
cd sysbench-0.4.12
libtoolize --force --copy
./autogen.sh
./configure
make

Problem:

/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
make[2]: *** [sysbench] Error 1
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench’
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench’
make: *** [all-recursive] Error 1

Solution:

Pass linker: LDFLAGS linker flags, e.g. -L

export LDFLAGS='-L/usr/lib/mysql'
./configure
make
make install

Testing Parameter

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

CPU Benchmark

sysbench --test=cpu --cpu-max-prime=20000 run

Fileio

sysbench --num-threads=16 --test=fileio --file-total-size=3G --file-test-mode=rndrw prepare

DB Benchmark

sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=databasename --mysql-user=root --mysql-password=PASSWORD prepare
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=databasename --mysql-user=root --mysql-password=PASSWORD --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run

# Ideally take more than ram size

sysbench --test=fileio --file-total-size=30G prepare

sysbench --test=fileio --file-total-size=30G --file-test-mode=rndrw --init-rng=on --max-time=300 --max-requests=0 run

Ref Doc: http://sysbench.sourceforge.net/docs/

track SSH traffic (bandwidth usage)

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

track SSH traffic (bandwidth usage)

I would use iptables owner module (perhaps together with other quota/reporting modules).
iptables -A OUTPUT -p tcp –dport 22 -m owner –uid someuser -j ACCEPT

iptables -vL

iftop (Bandwith monitoring tool)

wget http://pkgs.repoforge.org/iftop/iftop-0.17-1.el6.rf.x86_64.rpm
yum install -y ncurses-devel
yum install libpcap
rpm -ivh iftop-0.17-1.el6.rf.x86_64.rpm

Installing Skype on Linux (centos 5.6) and sending message using zabbix

Subject itself sounds crazy, yet intresting.

Installing Skype on Linux (centos 5.6) and sending message using zabbix

Installing skype on Linux 5.6
Installing skype 2.2 on linux 6.2 is easy peasy 😀

Download static version of skype for linux, if you are installing skype on linux 5.6 you better pick, older skype version

Download skype of version that suits you.
skype_static-2.1.0.81.tar
skypeAPI (Skype4Py – i have been using 1.0.31.0)

Skype would need to install either GUI or Use vnc server in order to be able to accept terms and condition (checkbox) and to accept skypeAPI integration.

1) If you follow to do with GUI (easiest just install KDE, GNOME according to your suit and install x windows)

2) If you follow to do with VNC (you would need to install Xvfb, fluxbox, x11vnc, dbus and modules according to need all problem i faced during the process is mentioned below).

Simply extract skype_static tarball and cp skype to /usr/bin/skype.

Install skype4Py with following command:

cd Skype4Py-1.0.31.0/
python setup.py install

Implementing skype on zabbix to send message

You will need to setup Media type and user profile.
which is pretty much simple for those user who has used zabbix.
And Action on configuration, which will define how to treat on alert and choose skype and user to alert.

with the given script (sendim.sh and sendim.py)

skype message on the server as skype user: ./sendim.sh ‘tikejhya’ ‘test this’

Script:
Sendim.sh

#!/bin/bash
DISPLAY=localhost:0.0
export DISPLAY
my_arg="${@:2:6}"
python ./sendim.py "$1" "$my_arg"

[Note: I used Display localhost to ensure tranporting display which can be in bash_profile]
[Note: Zabbix sends message as script username message so i wanted to use all message apart from username
this will allow you to send multiple macros.]

./sendim.py

import Skype4Py
import sys

# Create an instance of the Skype class.
skype = Skype4Py.Skype()

# Connect the Skype object to the Skype client.
skype.Attach()
user = sys.argv[1]
msg = ' '.join(sys.argv[2:])
message = skype.SendMessage(user, msg)

[This script imports skype4py which you might have installed already in above given tips.]

./skype_login.sh

#!/bin/bash
echo tikejhya password | skype --pipelogin&

[this is how you can login to skype from CLI]

Did i miss anything?

This link was really helpful to get me going
http://www.qxs.ch/2011/01/07/skype-instant-messages-from-zabbix/

###########################################################
Problem i faced during installation.

Install Skype in EL6

yum install skype

If you do not have my repo installed:

wget http://li.nux.ro/download/nux/dextop/el6/x86_64/skype-2.2.0.35-3.el6.nux.i586.rpm
yum localinstall --nogpgcheck ./skype-2.2.0.35-3.el6.nux.i586.rpm

All of the above needs to be done as root, obviously.

#############################################################

rpm -Uvh http://ftp.ntua.gr/pub/linux/fedora-epel/6/x86_64/epel-release-6-6.noarch.rpm

(if unable to open web, and search for which epel-release version is available)

yum install wine

############################################################

/usr/bin/python2.5: bad interpreter: No such file or directory

To get around this, open skysentials.py with your favourite text editor and change the very first line from:

  #!/usr/bin/python2.5

to:

#!/usr/bin/python

###########################################################

Changing dbus to x11 (BTW you dont need to change build one but compile again)

vi skype4py/build/lib/Skype4Py/api/posix.py	
vi skype4py/Skype4Py/api/posix.py

def SkypeAPI(opts):
trans = opts.pop(‘Transport’, ‘x11’)
if trans == ‘dbus’:
from posix_dbus import SkypeAPI
elif trans == ‘x11’:
from posix_x11 import SkypeAPI
else:
raise SkypeAPIError(‘Unknown transport: %s’ % trans)
############################################################

How to setup Skype headless on centos 5.6

Download Skype Static Package version:
skype_static-2.1.0.81.tar

tar -xvf skype_static-2.1.0.81.tar
cd skype_static-2.1.0.81

############################################################
Problem: libstdc++ GLIBC error
Solution: Older Skype version
############################################################

[root@ashishnepal Skype4Py-1.0.32.0]# Xvfb :1 -screen 0 800x600x24
Couldn’t open RGB_DB ‘/usr/share/X11/rgb’
_XSERVTransSocketOpenCOTSServer: Unable to open socket for inet6
_XSERVTransOpen: transport open failed for inet6/ashishnepal:1
_XSERVTransMakeAllCOTSServerListeners: failed to open listener for inet6
error opening security policy file /usr/lib64/xserver/SecurityPolicy
Could not init font path element unix/:7100, removing from list!
FreeFontPath: FPE “built-ins” refcount is 2, should be 1; fixing.

solution: Comment out ipv6 , disable = 1

[root@ashishnepal Skype4Py]# cat /etc/modprobe.conf
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
alias net-pf-10 off
# alias ipv6 off
# options ipv6 disable=1
# Added by VMware Tools
install pciehp /sbin/modprobe -q --ignore-install acpiphp; /bin/true
install pcnet32 (/sbin/modprobe -q --ignore-install vmxnet || /sbin/modprobe -q --ignore-install pcnet32 $CMDLINE_OPTS);/bin/true
alias eth0 e1000

###########################################################

Xvfb :1 -screen 0 800x600x24

export Display
DISPLAY=localhost:0.0
export DISPLAY

Pipe Login.
echo tikejhya Password | skype --pipelogin

###########################################################
If you are willing to run zabbix in diff server and have centos with skype in diff server this may totally make sense.

sudo: no tty present and no askpass program specified

# %users  localhost=/sbin/shutdown -h now
%tikejhya    ALL=(ALL)      NOPASSWD: ALL

#########################################################
[root@ashishnepal skype4py]# sudo /root/sendim.sh tikejhya “Ok this is it”
Xlib: connection to “localhost:0.0” refused by server
Xlib: No protocol specified

Traceback (most recent call last):
File “/root/sendim.py”, line 4, in ?
skype = Skype4Py.Skype()
File “/usr/lib/python2.4/site-packages/Skype4Py/skype.py”, line 250, in __init__
self._Api = SkypeAPI(Options)
File “/usr/lib/python2.4/site-packages/Skype4Py/api/posix.py”, line 40, in SkypeAPI
return SkypeAPI(opts)
File “/usr/lib/python2.4/site-packages/Skype4Py/api/posix_x11.py”, line 254, in __init__
raise SkypeAPIError(‘Could not open XDisplay’)
Skype4Py.errors.SkypeAPIError: Could not open XDisplay
/root/sendim.sh: line 6: 5816 Segmentation fault python /root/sendim.py “$1” “$2”

Solution:

[root@ashishnepal skype4py]# su -
[root@ashishnepal ~]# /root/sendim.sh tikejhya "Ok this is it"

[environmental variable plus exporting display is sometimes tricky]

Also if you want to make more certain

[root@ashishnepal.com Skype4Py]# echo tikejhya password | skype –pipelogin
Xlib: connection to “localhost:0.0” refused by server
Xlib: No protocol specified

this is becuase of .xauthority file…

su –
and it should be fine…

or need to find way to use .xauthority file..

/usr/bin/mkxauth [-q] [-u ] -m 

-u     create/merge .Xauthority for user 

Best practice: mkxauth -u skype -m root

###############################################################
skype not snyncing

http://www.mydigitallife.info/how-to-disable-upnp-in-skype-to-remove-open-tcp-and-udp-ports-in-firewall/
Its all in all upnp play.
###############################################################

Debugging shell script arguments.

While implementing skype in zabbix we normally dont see any logs so it was important for me to see weather message were being passed or not.

Simple script.

#!/bin/bash
KEY="/home/zabbix/id_rsa"
PORT=2222
USER="skype@ashishnepal.com"
SCRIPT="/home/skype/sendim.sh"
# my_arg="${@:2:6}"

echo "..............">>skypelog.txt

echo "Total Arguments: $#" >> skypelog.txt
i=1;
echo ".........................">>skypelog.txt
for var in "$@"
        do
          echo "Argument $i is $var" >> skypelog.txt
          let i=$i+1;
        done

ssh -p${PORT} -i $KEY $USER "$SCRIPT "$1" "$2""

Delay on message arrival : Firewall
Skype message not delivered yet?

Allways allow from the SKYPEAPI Server IP (from port) 1024 (to port) 65535.

This should solve issue.

##########################################################

GUI for sending skype message

Sending Skype Message from Web:





Total Memory Usage Calculation

Print Total sum of actual Memory Usages

ps aux | awk '{sum +=$4}; END {print sum}'

Check Actual Memory Consumption
free -m

Check total usage of One particular process

ps aux | awk '{print $4,$11}' | sort |tail -n 23 |grep -w 'someprocess' |wc -l

All most consuming process

ps aux | awk '{print $4,$11}' | sort |tail -n 20

use of uninitialized value in subsitution at mytop line xx

use of uninitialized value in subsitution at mytop line xx

Remove this line

$host =~ s/^([^.]+).*/$1/;
$thread->{Host} = $host;

Replace with this

if ($host)
	{
		$host =~ s/^([^.]+).*/$1/;
		$thread->{Host} = $host;
	}

}

Mytop Centos 5.6 Mysql Version : 5.5.16

Mytop

Server Tested : Centos 5.6 64bit
Mysql Version : 5.5.16 (Compile)
Download Package: http://jeremy.zawodny.com/mysql/mytop/
tar -zxvf mytop-.tar.gz
cd mytop-
perl Makefile.PL
make
make install

Possible Errors:
Warning: prerequisite DBD::mysql 1 not found.
Warning: prerequisite DBI 1.13 not found.
Warning: prerequisite Term::ReadKey 2.1 not found.

Solution
perl-Class-Data-Inheritable-0.08-1.el5.rf.noarch.rpm
perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm
perl-DBI-1.616-1.el5.rfx.x86_64.rpm
perl-DBIx-ContextualFetch-1.03-1.el5.rf.noarch.rpm
perl-Ima-DBI-0.35-1.el5.noarch.rpm
perl-Ima-DBI-0.35-1.el5.src.rpm
perl-TermReadKey-2.30-4.el5.x86_64.rpm

Available to download @ http://rpm.pbone.net/

Mytop
mytop is a console-based (non-gui) tool for monitoring the threads
and overall performance of a MySQL server.
It runs on most Unix systems which have Perl,
DBI, and Term::ReadKey installed. And with Term::ANSIColor installed
you even get color.

If you install Time::HiRes, you’ll get good real-time queries/second stats.
As of version 0.7, it even runs on Windows (somewhat).

OSSEC – howto email

Ossec

If you configured ossec to send emails only for alerts with severity level 7 and higher then you will get those alerts.
Beside that you will also get emails for every alert that is triggered with rule that has “alert_by_email
tag specified regardless of rule level.

Add the following statement in your ossec.conf section next to the line:
1
This means that the global e-mail notification system will only send out one e-mail per hour, that means it collects all
alerts that would generate an e-mail until the end of the hour,
compiles them into one e-mail and then sends it.

Host-based intrusion detection system (HIDS)

E.g OSSEC

“OSSEC is an Open Source Host-based Intrusion Detection System. It performs log analysis,
file integrity checking, policy monitoring, rootkit detection, real-time alerting and active response.” (www.ossec.net)

HIDS (OSSEC) is an intrusion detection system that monitors and analyzes the internal computing system.

Never the less in some cases the “Network packets on its network interface”.
Yes, Just like Network-Based Intrusion detection system (NIDS).

Monitors the dynamic behaviour and state of the Machine (Computer System).

e.g. /etc/passwd was modified

suddenly and inexplicably started modifying the system password database.

Can be taken as Monitoring agent, or system’s security Policy.

What has ossec to say about ossec itself:

OSSEC is a scalable, multi-platform, open source Host-based Intrusion Detection System (HIDS).
It has a powerful correlation and analysis engine, integrating log analysis, file integrity checking,
Windows registry monitoring, centralized policy enforcement, rootkit detection, real-time alerting and active response.

How to Install Ossec WUI

::::::::::::::::::::::::::::::::::::::::
OSSECWUI Installation
wget http://www.ossec.net/files/ui/ossec-wui-0.3.tar.gz
Note:
Download latest from
http://www.ossec.net/wiki/OSSECWUI#Download

Logs Monitoring

Logs Monitoring

tail -500 /var/logs/httpd/access.log | cut | sort | and so on and so forth

Cut to view certain
cut -c 14-21

Sort in Numeric Order
sort -n

Count unique
uniq -c

3 From Last
tail -3

first from top
head -1

5th to 8th character
cut -c 5-8

Display Only if its below 10
awk “$NF<=10"

Check Database Size (Mysql, CentOS)

If you want to check the size of the databases available in ur msyql, Paste the below given query.

SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

All size and all tables..

SELECT concat(table_schema,'.',table_name),
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') DATA,
concat(round(index_length/(1024*1024*1024),2),'G') idx,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length+index_length DESC LIMIT 20;

Page 1 of 2

Powered by WordPress & Theme by Anders Norén