Monthly Archives: March 2014

http responsetime

Munin plugin:

#!/usr/bin/python
”’
Plugin to measure response times for urls.
This is useful as a sort of final availability measurement.

How to configure:
[httpresponsetime]
env.urls http://www.google.com, http://www.yahoo.com/something

Put the urls you’d like to check, separated by commas in your conf file.

Requires httplib2 for python (easy_install httplib2, or http://code.google.com/p/httplib2/ )
Graphs the time (in milliseconds) for the response of the url(s) provided.
If the http request fails (4XX, 5XX) will output -1, which is marked as
critical.

Arthur Debert
http://www.stimuli.com.br
FreeBSD licensed
”’
import sys, os

# the main configuration node
config = {
“master” : {
“graph_title” : ‘Http Response Times’,
“graph_args” : ‘–base 1000 -l 0’,
“graph_vlabel” : ‘Time (in milliseconds)’,
“graph_category” : ‘Http Monitoring’,
“graph_scale” : ‘no’,
“label” : ‘Response times’,

},
“url_to_check” : {
“label” : ‘%(url)s’,
“type” : ‘GAUGE’,
“min” : ‘-1’,
“max” : ‘2000’,
“draw” : ‘LINE2’,
“info” : ‘Time (in milliseconds) for response’,
“warning”: “0:1500”,
“critical”: “0:2000”,
},
}

def get_config(urls):
for key,value in config[‘master’].items():
print “%s %s” % (key, value)
for url in urls:
for key, value in config[“url_to_check”].items():
value = value % ({“url”:url})
printable_url = get_printable_url(url)
print “%s.%s %s” % (printable_url, key, value)

def get_printable_url(url):
”’
Makes a field name friendly version of the url, as the rdd config commands
will not allow slashes, dots and other characters.
”’
import urlparse
parsed = urlparse.urlsplit (url)
return (“%s_%s_%s” % (parsed[1] , parsed[2], parsed[3])).replace(“/”, “_”).replace(“.”, “_”).replace(‘-‘,’_’)

def get_request_time(url):
”’
Returns the time, in millseconds, for the request to be fetched.
Returns -1 on failuer (Http status code other that 200 > x > 400
”’
import httplib2, time
fetcher = httplib2.Http()
initial = time.time()
resp, content = fetcher.request(url)
duration = int((time.time() – initial) * 1000)
resp_code = int(resp[“status”])
if 200 <= resp_code < 400: return duration return -1 def get_urls(): try: return os.environ["urls"].split(",") except KeyError: print "You needto specify which URLS to monitor by setting the 'urls' env variable in your munin-conf." sys.exit(1) def run(): urls = get_urls() for url in urls: printable_url = get_printable_url(url) url_time = get_request_time(url) print "%s.value %s" % (printable_url, url_time) sys.exit(0) def exit_with_failure(msg): print msg sys.exit(1) def exit_with_success(): sys.exit(0) if __name__ == "__main__": try: import httplib2 except ImportError: exit_with_failure("This plugin requires the httplib2 (easy_install httplib2, or http://code.google.com/p/httplib2/ ) library for python, aborting.") if len(sys.argv) > 1:
cmd_name = sys.argv[1]
else:
cmd_name = None
if cmd_name and cmd_name == “autoconf”:
exit_with_failure(‘no’)
elif cmd_name and cmd_name == “suggest”:
print “”
exit_with_success()
elif cmd_name == “config”:
get_config(get_urls())
exit_with_success()
else:
run()
sys.exit(0)
exit_with_failure(“Unsupported command”)

mysql InnoDB doublewrite buffer

InnoDB uses a novel file flush technique called doublewrite. Before writing pages to a data file, InnoDB first writes them to a contiguous area called the doublewrite buffer. Only after the write and the flush to the doublewrite buffer have completed does InnoDB write the pages to their proper positions in the data file. If the operating system crashes in the middle of a page write, InnoDB can later find a good copy of the page from the doublewrite buffer during recovery.

The doublewrite buffer may also contain compressed pages. However, the built-in InnoDB in MySQL cannot recognize such pages, and it assumes that compressed pages in the doublewrite buffer are corrupted. It also wrongly assumes that the tablespace (the .ibd file) consists of 16K byte pages. Thus, you may find InnoDB warnings in the error log of the form “a page in the doublewrite buffer is not within space bounds”.

The doublewrite buffer is not scanned after a clean shutdown. In an emergency, you may prevent crash recovery by setting innodb_force_recovery=6. However, this is strongly discouraged, because it may lead into severe corruption.

zabbix monitor mysql server

mysql -e”GRANT USAGE ON *.* TO ‘zabbix’@’127.0.0.1’ IDENTIFIED BY ‘123456’”;
mysql -e”GRANT USAGE ON *.* TO ‘zabbix’@’localhost’ IDENTIFIED BY ‘123456’”;
mysql -e”flush privileges”
mysql -uzabbix -p123456 -e”status”

Include=/etc/zabbix/zabbix_agentd
vi /etc/zabbix/zabbix_agentd/mysql.conf
UserParameter=mysql.ping[*],(test -f /usr/bin/mysqladmin && mysqladmin -u zabbix -p123456 ping | grep alive | wc -l)

service zabbix-agent restart

manually change domain in magento

Update your core_config_data table to edit the two records for web/unsecure/base_url and web/secure/base_url
Delete the contents of WEBROOT/var/cache
Update / edit any .htaccess domain redirects you may have added
Restart Apache
Make sure Apache has write permissions to WEBROOT/var
If you created a new DB, ensure that the WEBROOT/app/etc/local.xml is pointing to it.
If you’re using Chrome, clear your browser cache! (Chrome caches 301s)

directadmin install Zend Optimizer/Guard, and/or Ioncube

For Zend, type:
cd /usr/local/directadmin/custombuild
./build set zend yes
./build zend

after changing php versions, it’s recommended you install zend again.
Note that Zend Guard is the new name for Zend Optimizer, and is used for newer versions of php. Custombuild will install the correct one for your system.

For Ioncube, type:
cd /usr/local/directadmin/custombuild
./build set ioncube yes
./build ioncube