Archive | Technical Notes RSS feed for this section

Nagiosgraph for Postgresql replication

5 Jun

To track postgresql replication lag with nagios you need to create a plugin to track nagios replication. I initially tried to read the ‘slave_lag’ directly from Postgresql, but permissions etc were a pain – so i just created a cron that dumped it every 5 mins and this reads that… the command to read the lag from Postgresql itself is commented out:

#!/bin/bash

# too hard with permissions
#delay=$( sudo -u postgresql psql -h127.0.0.1 -p5433 -c "SELECT extract(epoch from now() - pg_last_xact_replay_timestamp()) AS slave_lag;" 2>/dev/null | tail -n 3 | head -n 1 | awk '{$1=$1};1')

delay=`tail -n 1 /tmp/postgres_lag.txt | awk '{print $4}'`
delay_int=`printf "%.0f" $delay`
output="Replication Delay: $delay seconds"

if [ "$delay_int" -le 300 ]
then
 echo "OK- $output"
 exit 0
elif [ $delay_int -le 2000 ]
then
 echo "WARNING- $output"
 exit 1
elif [ $delay_int -gt 2000 ]
then
 echo "CRITICAL- $output"
 exit 2
else
echo "UNKNOWN- $output"
exit 3
fi

You then need to edit your nagiosgraph ‘map’ file (called ‘map’) and add this:

# Replication delay
/output:.*eplication Delay: ([.\d]+)\sseconds/
and push @s, [ 'seconds',
 [ 'data', GAUGE, $1 ] ];

WordPress – Jetpack

17 May
transport error – HTTP status code was not 200 (502) xmlrpc

was getting the above error when trying to activate Jetpack for WordPress

Turns out it was php / nginx config error, added the following to nginx.conf where it was starting the php-fpm:

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

Jquery Dialog slow to open

11 Sep

Here is a good way to speed up jQuery dialogs. This happens when there is a lot of data/html inside the dialog:

http://johnculviner.com/a-jquery-ui-dialog-open-performance-issue-and-how-to-fix-it/

This reduced load time from about 4000ms to about 1100ms.

To summarize (in case the above page changes), you detach the container’s children before you open it, then you re-attach once it is open:

var $dialogContainer = $('#contrib-dialog');
var $detachedChildren = $dialogContainer.children().detach();
$('#contrib-dialog').dialog({
  modal: 1,
  autoOpen: 0,
  height: 'auto',
  width: 985,
  title: "Yup",
 open: function () {
   $detachedChildren.appendTo($dialogContainer);
  }
}).dialog('open');

Javascript timing

10 Sep

Quick/dirty way to time functions in javascript

console.time("hi")
myfunction()
console.timeEnd("hi")

Selenium – change windows

23 Aug

Upgraded capybara to 2.1.x (with Selenium Webdriver) and my switch_to window calls started failing.

This is how i fixed it:

sleep(5)
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
within_window(page.driver.browser.window_handles.last) do
   page.should have_content('My Text on New PopUP')
  page.driver.browser.close
end

Seems to take a lot of trial and error when these things break.

shiny tool tips from codecanyon

2 Jul

I am using Shiny Tooltips from code canyon.

Unfortunately there was no way to position the tooltips to appear UNDER an anchor.

I added this in tooltip.js, around line 157:

if($this.hasClass("effect_under")) {
top = top + $currentTooltip.innerHeight() + 30 + 20 ;
 $currentTooltip.children(".arrow").css({
 "bottom" : bottom + $currentTooltip.innerHeight()+5 ,
 "border-left" : "20px solid transparent",
 "border-right" : "20px solid transparent",
 "border-bottom" : "5px solid #ADDF79",
 "border-top" : "0px",
 "border-bottom-width" : "20px"
 });
}

So now you can just add the class “effect_under” to your tooltip and the tooltip will appear under the element instead of over it.

The ‘border-bottom’ colour controls the colour, could use a class here instead…

To skip WSUS and force computer to get from MS

19 Jun

Delete this entry (the whole folder?)

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate