Icinga2 HTTPS and ssl key expiration check

Create a host file in /etc/icinga2/conf.d/hosts eg website-ripe.conf

Create the host details
object Host "website-ripe" {
  import "generic-host"
  address = "ripe.net"
  address6 = "::1"
  vars.os = "Linux"
  vars.sla = "24x7"
}


How to monitor a website over SSL (service)
object Service "httpS" {
  host_name = "website-ripe"
  vars.http_vhost = "ripe.net"
  vars.http_address = "193.0.6.139"
  vars.http_ssl = "1"
  vars.http_sni = "1"
  vars.http_warn_time = "5"
  vars.http_critical_time = "10"
  check_command = "http"
}

Monitoring the SSL key expiration date, give warning 30 before and alert at 14 days before. (service)
object Service "website-ripe-key-expire"{
  host_name = "website-ripe"
  check_command = "check-ssl-exp"
  vars.days = 30,14
  vars.url = "ripe.net"
}
Because it's not a default check -the -C (certificate) parameter is not available in Icinga- we need to create a custom checkCommand
object CheckCommand "check-ssl-exp" {
import "plugin-check-command"
command = PluginDir + "/check_http -H $url$ -C$daysquot;
}



Error:
[2014-07-30 12:58:00 +0200] critical/config:
Config error: Invalid value for attribute: Object 'check_ssl' (Type: 'CheckCommand') at /etc/icinga2/conf.d/hosts/website-ripe.conf:28 -> Attribute 'methods'
[2014-07-30 12:58:00 +0200] critical/config: 1 errors, 0 warnings.

Solution:
add   import "plugin-check-command" ot the oject checkcommand section.

unmount busy device

df -a

umount -l /mount/point

Icinga2 disable ping checks on specific hosts

Problem:

You have a server which does not answer ping etc.
Icinga2 marks the host as critical and you want to get rid of it.
Solution

By default, Icinga2 applies to every host the service ping4 or ping6 (depending on the address). This is done with an apply rule in
 /etc/icinga2/conf.d/services.conf:
apply Service "ping4" {
import "generic-service"
check_command = "ping4"
assign where host.address
}

To disable it for two specific host you only have to add an ignore rule (ping4):

ignore where match("x.x.x.x", host.address) || match("y.y.y.y", host.address)

example:-

ignore where match("1.2.3.4", host.address) || match("5.6.7.8", host.address)

remotedesktop using linux tool called rdesktop

rdesktop -k en-us -a 16 -g 90% -u Administrator -p 'P@ss#4dD'   192.168.1.100

mysql lock query timeout

show open tables where in_use>0;
SHOW VARIABLES LIKE 'tx_isolation';
or if you have MySQL 5.1+
SELECT * FROM information_schema.session_variables
WHERE variable_name = 'tx_isolation';
If you want to know what the server has configured globally, change the above to the following:
SHOW GLOBAL VARIABLES LIKE 'tx_isolation';
or if you have MySQL 5.1+
SELECT * FROM information_schema.global_variables
WHERE variable_name = 'tx_isolation';
If you want to make the query reveal what transaction isolation is being used, run this:
SELECT variable_value IsolationLevel
FROM information_schema.session_variables
WHERE variable_name = 'tx_isolation';**

mysql explain

https://mariadb.com/kb/en/mariadb/explain/

The columns in EXPLAIN ... SELECT

Column nameDescription
idSequence number that shows in which order tables are joined.
select_typeWhat kind of SELECT the table comes from.
tableAlias name of table. Materialized temporary tables for sub queries are named <subquery#>
typeHow rows are found from the table (join type).
possible_keyskeys in table that could be used to find rows in the table
keyThe name of the key that is used to retrieve rows. NULL is no key was used.
key_lenHow many bytes of the key that was used (shows if we are using only parts of the multi-column key).
refThe reference that is used to as the key value.
rowsAn estimate of how many rows we will find in the table for each key lookup.
ExtraExtra information about this join.
Here are descriptions of the values for some of the more complex columns in EXPLAIN ... SELECT:

"select_type" column

The select_type column can have the following values:
ValueDescription
PRIMARYThe SELECT is a PRIMARY one.
SIMPLEThe SELECT is a SIMPLE one.
DERIVEDThe SELECT is DERIVED from the PRIMARY.
SUBQUERYThe SELECT is a SUBQUERY of the PRIMARY.
DEPENDENT SUBQUERYThe SUBQUERY is DEPENDENT.
UNCACHEABLE SUBQUERYThe SUBQUERY is UNCACHEABLE.
UNIONThe SELECT is a UNION of the PRIMARY.
UNION RESULTThe result of the UNION.
DEPENDENT UNIONThe UNION is DEPENDENT.
UNCACHEABLE UNIONThe UNION is UNCACHEABLE.

"Type" column

This column contains information on how the table is accessed.
ValueDescription
ALLA full table scan is done for the table (all rows are read). This is bad if the table is large and the table is joined against a previous table! This happens when the optimizer could not find any usable index to access rows.
constThere is only one possibly matching row in the table. The row is read before the optimization phase and all columns in the table are treated as constants.
eq_refA unique index is used to find the rows. This is the best possible plan to find the row.
fulltextA fulltext index is used to access the rows.
index_mergeA 'range' access is done for for several index and the found rows are merged. The key column shows which keys are used.
index_subqueryThis is similar as ref, but used for sub queries that are transformed to key lookups.
indexA full scan over the used index. Better than ALL but still bad if index is large and the table is joined against a previous table.
rangeThe table will be accessed with a key over one or more value ranges.
ref_or_nullLike 'ref' but in addition another search for the 'null' value is done if the first value was not found. This happens usually with sub queries.
refA non unique index or prefix of an unique index is used to find the rows. Good if the prefix doesn't match many rows.
systemThe table has 0 or 1 rows.
unique_subqueryThis is similar as eq_ref, but used for sub queries that are transformed to key lookups

"Extra" column

This column consists of one or more of the following values, separated by ';'
Note that some of these values are detected after the optimization phase.
The optimization phase can do the following changes to the WHERE clause:
  • Add the expressions from the ON and USING clauses to the WHERE clause.
  • Constant propagation: If there is column=constant, replace all column instances with this constant.
  • Replace all columns from 'const' tables with their values.
  • Remove the used key columns from the WHERE (as this will be tested as part of the key lookup).
  • Remove impossible constant sub expressions. For example WHERE '(a=1 and a=2) OR b=1' becomes 'b=1'.
  • Replace columns with other columns that has identical values: Example: WHERE a=b and a=c may be treated as'WHERE a=b and a=c and b=c'.
  • Add extra conditions to detect impossible row conditions earlier. This happens mainly with OUTER JOIN where we in some cases add detection of NULL values in the WHERE (Part of 'Not exists' optimization). This can cause an unexpected 'Using where' in the Extra column.
  • For each table level we remove expressions that have already been tested when we read the previous row. Example: When joining tables t1 with t2 using the following WHERE 't1.a=1 and t1.a=t2.b', we don't have to test 't1.a=1' when checking rows in t2 as we already know that this expression is true.
ValueDescription
const row not foundThe table was a system table (a table with should exactly one row), but no row was found.
DistinctIf distinct optimization (remove duplicates) was used. This is marked only for the last table in the SELECT.
Full scan on NULL keyThe table is a part of the sub query and if the value that is used to match the sub query will be NULL, we will do a full table scan.
Impossible HAVINGThe used HAVING clause is always false so the SELECT will return no rows.
Impossible WHERE noticedafter reading consttables.The used WHERE clause is always false so the SELECT will return no rows. This case was detected after we had read all 'const' tables and used the column values as constant in the WHERE clause. For example: WHERE const_column=5 and const_column had a value of 4.
Impossible WHEREThe used WHERE clause is always false so the SELECT will return no rows. For example: WHERE 1=2
No matching min/max rowDuring early optimization of MIN()/MAX() values it was detected that no row could match the WHERE clause. The MIN()/MAX() function will return NULL.
no matching row in consttableThe table was a const table (a table with only one possible matching row), but no row was found.
No tables usedThe SELECT was a sub query that did not use any tables. For example a there was no FROM clause or a FROM DUAL clause.
Not existsStop searching after more row if we find one single matching row. This optimization is used with LEFT JOIN where one is explicitly searching for rows that doesn't exists in the LEFT JOIN TABLE. Example: SELECT * FROM t1 LEFT JOIN t2 on (...) WHERE t2.not_null_column IS NULL. As t2.not_null_column can only be NULL if there was no matching row for on condition, we can stop searching if we find a single matching row.
Open_frm_onlyFor INFORMATION_SCHEMA tables. Only the frm (table definition file was opened) was opened for each matching row.
Open_full_tableFor INFORMATION_SCHEMA tables. A full table open for each matching row is done to retrieve the requested information. (Slow)
Open_trigger_onlyFor INFORMATION_SCHEMA tables. Only the trigger file definition was opened for each matching row.
Range checked for eachrecord (index map: ...)This only happens when there was no good default index to use but there may some index that could be used when we can treat all columns from previous table as constants. For each row combination the optimizer will decide which index to use (if any) to fetch a row from this table. This is not fast, but faster than a full table scan that is the only other choice. The index map is a bitmask that shows which index are considered for each row condition.
Scanned 0/1/all databasesFor INFORMATION_SCHEMA tables. Shows how many times we had to do a directory scan.
Select tables optimizedawayAll tables in the join was optimized away. This happens when we are only using COUNT(*), MIN() and MAX() functions in the SELECT and we where able to replace all of these with constants.
Skip_open_tableFor INFORMATION_SCHEMA tables. The queried table didn't need to be opened.
unique row not foundThe table was detected to be a const table (a table with only one possible matching row) during the early optimization phase, but no row was found.
Using filesortFilesort is needed to resolve the query. This means an extra phase where we first collect all columns to sort, sort them with a disk based merge sort and then use the sorted set to retrieve the rows in sorted order. If the column set is small, we store all the columns in the sort file to not have to go to the database to retrieve them again.
Using indexOnly the index is used to retrieve the needed information from the table. There is no need to perform an extra seek to retrieve the actual record.
Using index conditionLike 'Using where' but the where condition is pushed down to the table engine for internal optimization at the index level.
Using index condition(BKA)Like 'Using index condition' but in addition we use batch key access to retrieve rows.
Using index for group-byThe index is being used to resolve a GROUP BY or DISTINCT query. The rows are not read. This is very efficient if the table has a lot of identical index entries as duplicates are quickly jumped over.
Using intersect(...)For index_merge joins. Shows which index are part of the intersect.
Using join bufferWe store previous row combinations in a row buffer to be able to match each row against all of the rows combinations in the join buffer at one go.
Using sort_union(...)For index_merge joins. Shows which index are part of the union.
Using temporaryA temporary table is created to hold the result. This typically happens if you are using GROUP BY, DISTINCT or ORDER BY.
Using whereA WHERE expression (in additional to the possible key lookup) is used to check if the row should be accepted. If you don't have 'Using where' together with a join type of ALL, you are probably doing something wrong!
Using where with pushedconditionLike 'Using where' but the where condition is pushed down to the table engine for internal optimization at the row level.
Using bufferThe UPDATE statement will first buffer the rows, and then run the updates, rather than do updates on the fly. See Using Buffer UPDATE Algorithm for a detailed explanation.

EXPLAIN EXTENDED

The EXTENDED keyword adds another column, filtered, to the output. This is a percentage estimate of the table rows that will be filtered by the condition.
An EXPLAIN EXTENDED will always throw a warning, as it adds extra Message information to a subsequent SHOW WARNINGSstatement. This includes what the SELECT query would look like after optimizing and rewriting rules are applied and how the optimizer qualifies columns and tables.

php opcache

With the release of Ubuntu 14.04 and the proliferation of PHP 5.5, there is going to be a migration away from Alternative Performance Cache (APC) and toward PHP’s new built-in OPcache.

This is a logical move that seems destined for any interpreted language.  As websites have become more and more complicated with many processes running, opcode caching has become a necessity – fortunately, it’s simple to implement.

The php.net site has a nice page of all the runtime options available, but we will cover the basics here to get you started quickly.

All you need to do to get OPcache set up is to make changes in the php.ini file on your server.

Open php.ini In Your Favorite Text Editor
To get started open your php.ini file.

Apache web-servers

/etc/php5/apache2/php.ini
Nginx web-servers with PHP-FPM

/etc/php5/fpm/php.ini
Enable the OPcache
To enable the OPcache, change to the following lines — easy enough!


;opcache.enable=0
Change to:


opcache.enable=1
Note: you have to uncomment this line as well as change the “0″ to “1″.

Modify the Amount of RAM the OPcache Will Use
With OPcache, there is a trade-off between speed and the amount of RAM used. The more RAM you are willing to dedicate to storing opcode, the more opcode that can be stored. There is a diminishing return at some point, because some code will execute rarely, or your code base might not be that big. It is worth playing with this setting to see where you get the best performance-versus-RAM trade-off.  This setting is in megabytes.


;opcache.memory_consumption=64
Change to:


opcache.memory_consumption=128
Boost the Number of Scripts that Can Be Cached
OPcache has a strange setting that requires you to not only adjust the amount of RAM, but also define the number of scripts that can be cached. You have the option of tuning this parameter for your own application too, especially if you find that your hit rate is not close to 100 percent.


;opcache.max_accelerated_files=2000
Change to:


opcache.max_accelerated_files=4000
Change the Revalidate Frequency
To make sure that the OPcache notices when you change your PHP code, you can set the revalidate frequency. Basically, this will tell the cache how often to check the timestamp on the files. This is measured in seconds.


;opcache_revalidate_freq = 2
Change to:


opcache_revalidate_freq = 240
Verify that the PHP OPcache Mod is Enabled
Believe it or not, that converts most of the settings you will need to get started. PHP5 has its own module system (since 5.4), so make sure that OPcache is enabled.


sudo php5enmod opcache
Restart PHP and Your Server
You should now be all set to start using PHP 5.5’s OPcache. You just need to restart your server to get it going.

Apache Web-Servers

sudo service apache2 restart
Nginx Web-Servers

sudo service nginx restart

mysql isolation level

https://www.facebook.com/note.php?note_id=244956410932
There is a lot of documentation available on transaction isolation levels for InnoDB includingthe InnoDB transaction model, a description of the isolation levels, notes on locks, locks set by statements and notes on consistent non-locking reads.

There is another issue that has not been documented. The code that creates a read view(snapshot) for InnoDB transactions is a source of mutex contention on kernel_mutex. This code is run once per statement for read-committed and once per transaction for repeatable-read.

The function read_view_open_now is run to create a snapshot. It copies the list of uncommitted transactions into a per-transaction data structure. Memory is allocated from the per-transaction heap to store the copied data and that allocation might require a call to malloc. All of this work is done while holding kernel_mutex and other threads are unlikely to get much work done in InnoDB when kernel_mutex is locked.

Subscribe to feature request 49169 if you are interested in this. I am not sure if there is an easy fix. Work can be done to reduce the chance of allocating memory while copying the open transaction list. But splitting kernel_mutex into several locks might be hard.

When repeatable-read is used there are fewer calls to read_view_open_now and there is less contention on kernel_mutex. I ran sysbench to measure the difference in performance.

http://dev.mysql.com/doc/refman/5.5/en/innodb-transaction-isolation-levels.html#isolevel_read-committed
https://easyengine.io/tutorials/mysql/enable-innodb-file-per-table/
https://www.brightbox.com/blog/2013/10/31/on-mysql-locks/
http://stackoverflow.com/questions/20321407/mysql-table-lock-instead-of-row-locks
https://www.percona.com/blog/2015/01/14/mysql-performance-implications-of-innodb-isolation-modes/
https://www.percona.com/blog/2012/08/28/differences-between-read-committed-and-repeatable-read-transaction-isolation-levels/

https://www.simple-talk.com/sql/t-sql-programming/questions-about-t-sql-transaction-isolation-levels-you-were-too-shy-to-ask/

https://www.percona.com/blog/2012/07/31/innodb-table-locks/


http://stackoverflow.com/questions/20173670/clarifying-the-difference-between-row-level-lock-in-innodb-engine-and-table-leve


change isolation level:-
SELECT @@GLOBAL.tx_isolation, @@tx_isolation; 

SET global TRANSACTION ISOLATION LEVEL READ COMMITTED; 
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;

SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
SET global TRANSACTION ISOLATION LEVEL REPEATABLE READ; 

SET GLOBAL tx_isolation='READ-COMMITTED';

SET SESSION tx_isolation='READ-COMMITTED';

]# mysql -e "show variables" | grep isolation

tx_isolation    READ-COMMITTED

## disable binlog  OR
SET GLOBAL binlog_format = 'ROW';  

error: rlm_sql_mysql: MySQL error 'Binary logging not possible. Message: Transaction level 'READ-COMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT''

SET GLOBAL binlog_format = 'ROW';  


If you are not planning to use your MySQL server for the replication consider turning the binary logging off by removing the option --log-bin from the command options for the mysqld utility starting the MySQL server.