-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


Zabbix

, 22 2017 . 23:57 +
jobgemws 23:57

Zabbix

  • Tutorial


, ( ).

, Zabbix MS SQL Server.

, , , .
.


( Zabbix), :
  1. Logical Disk
    1. Avg Disc sec/Read
      . Avg. Disk sec/Read 10 . Avg. Disk sec/Read 50 .
      Zabbix: perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Read], , : perf_counter[\LogicalDisk(C:)\Avg. Disk sec/Read]
      :
      {_:perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Read].last()}>0.005, -

      {_:perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Read].last()}>0.0025, -
    2. Avg Disc sec/Write
      . Avg. Disk sec/Write 10 . Avg. Disk sec/Write 50 .
      Zabbix: perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Write], , : perf_counter[\LogicalDisk(C:)\Avg. Disk sec/Write]
      :
      {_:perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Write].last()}>0.005, -

      {_:perf_counter[\LogicalDisk(_Total)\Avg. Disk sec/Write].last()}>0.0025, -
    3. Avg Disk Queue Length
      C . , . 2 . , . , , Avg. Disk Read Queue Length ( ) Avg. Disk Wright Queue Length ( ).
      Avg. Disk Queue Length , . , , , , . .. Avg. Disk Queue Length = (Disk Transfers/sec) * (Avg. Disk sec/Transfer).
      Avg. Disk Queue Length , . , 2, RAID- 4- , 4*2=8.
      Zabbix: perf_counter[\LogicalDisk(_Total)\Avg. Disk Queue Length], , : perf_counter[\LogicalDisk(C:)\Avg. Disk Queue Length]

  2. Memory
    1. Pages/sec
      , SQL Server , , . Pages Input/sec Pages Output/sec, (/) - . , , . , , . ( ) . .
      Zabbix: perf_counter[\Memory\Pages/sec]
      :
      {_:perf_counter[\Memory\Pages/sec].min(5m)}>1000, -
    2. Page Faults/sec
      . , , . , , , . . , , , .
      Zabbix: perf_counter[\Memory\Page Faults/sec]
      :
      {_:perf_counter[\Memory\Page Faults/sec].min(5m)}>1000, -
    3. Available Bytes
      . . . 5000 .
      Available Mbytes :
      50% =
      25% =
      10% =
      5% = , .
      Zabbix: perf_counter[\Memory\Available Bytes]

  3. Processor (Total): % Processor Time
    , (non-Idle thread). , . , , . , 100 . , , 80 , .
    Zabbix: perf_counter[\Processor(_Total)\% Processor Time],
    :
    {_:perf_counter[\Processor(_Total)\% Processor Time].min(5m)}>80, -
  4. Network Interface (*): % Bytes Total/sec
    . ( ). . , 50% .
    Zabbix: perf_counter[\Network Interface(*)\Bytes Sent/sec]
  5. MS SQL Server: Access Methods
    Access Methods ( ) SQL Server , . . , , , , . , Access Methods , , . .
    1. Page Splits/sec
      , . , SQL Server . . :
      . , , ;
      , Fillfactor. , , .
      Zabbix: perf_counter["\MSSQL$_:Access Methods\Page Splits/sec",30]
      : {_:perf_counter["\MSSQL$_:Access Methods\Page Splits/sec",30].last()}>{_:perf_counter["\MSSQL$_:SQL Statistics\Batch Requests/sec",30].last()}/5, -
    2. Full Scans/sec
      . . ( , , , ). , , , , . . OLTP-. OLAP- - .
      Zabbix: perf_counter["\MSSQL$_:Access Methods\Full Scans/sec",30]

  6. MS SQL Server: Buffer Manager
    Buffer Manager ( ) , , SQL Server :
    ;
    , -, SQL Server ;
    , (SSD);
    , SQL Server, ;
    , . , SQL Server ;
    , SQL Server;
    SQL Server . , , - . - .
    1. Buffer Cache hit radio
      , SQL Server . , , .. SQL , , - (I/O) . , . 90% OLTP- 50% OLAP-.
      Zabbix: perf_counter["\MSSQL$_:Buffer Manager\Buffer cache hit ratio",30]
      : {_:perf_counter["\MSSQL$_:Buffer Manager\Buffer cache hit ratio",30].last()}<70, -

      {_:perf_counter["\MSSQL$_:Buffer Manager\Buffer cache hit ratio",30].last()}<80, -
    2. Page life expectancy
      , . , , . , , . , , , ( 300 MS SQL Server 2012).
      Zabbix: perf_counter["\MSSQL$_:Buffer Manager\Page life expectancy",30]
      : {_:perf_counter["\MSSQL$_:Buffer Manager\Page life expectancy",30].last()}<5, -

  7. MS SQL Server: General Statistics
    General Statistics ( ) SQL Server , , , , SQL Server. (OLTP), SQL Server.
    1. Process blocked
      .
      Zabbix: perf_counter["\MSSQL$_:General Statistics\Processes blocked",30]
      : ({_:perf_counter["\MSSQL$_:General Statistics\Processes blocked",30].min(2m,0)}>=0)
      and ({_:perf_counter["\MSSQL$_:General Statistics\Processes blocked",30].time(0)}>=50000)
      and ({_:perf_counter["\MSSQL$_:General Statistics\Processes blocked",30].time(0)}<=230000), - ( 05:00 23:00)
    2. User Connections
      , SQL Server.
      Zabbix: perf_counter["\MSSQL$_:General Statistics\User Connections",30]

  8. MS SQL Server: Locks
    Locks () Microsoft SQL Server SQL Server, . SQL Server, , . , (X) , , . , . Locks, .
    1. Average Wait Time (ms)
      ( ) , . , , . , - . .
      Zabbix: perf_counter["\MSSQL$_:Locks(_Total)\Average Wait Time (ms)",30]
      : {_:perf_counter["\MSSQL$_:Locks(_Total)\Average Wait Time (ms)",30].last()}>=500, -
    2. Lock Wait Time (ms)
      ( ) .
      Zabbix: perf_counter["\MSSQL$_:Locks(_Total)\Lock Wait Time (ms)",30]
    3. Lock Waits/sec
      , .
      Zabbix: perf_counter["\MSSQL$_:Locks(_Total)\Lock Wait Time (ms)",30]
    4. Lock Timeouts/sec
      , . SQL Server spin counter (spins), - .
      Zabbix: perf_counter["\MSSQL$_:Lock Timeouts/sec",30]
      : {_:perf_counter["\MSSQL$_:Locks(_Total)\Lock Timeouts/sec",30].last()}>1000, -
    5. Lock Requests/sec
      .
      Zabbix: perf_counter["\MSSQL$_:Lock Requests/sec",30]
      : {_:perf_counter["\MSSQL$_:Locks(_Total)\Lock Requests/sec",30].last()}>500000, -
    6. Lock Number of Deadlocks/sec
      , . , .
      Zabbix: perf_counter["\MSSQL$_:Number of Deadlocks/sec",30]
      : {_:perf_counter["\MSSQL$_:Locks(_Total)\Number of Deadlocks/sec",30].last()}>1, -

  9. MS SQL Server: Memory Manager
    Memory Manager ( ) Microsoft SQL Server . . , SQL Server, :
    . , SQL Server ;
    , SQL Server.
    1. Memory Grants Outstending
      , . , .
      Zabbix: perf_counter["\MSSQL$_:Memory Manager\Memory Grants Outstanding",30]
    2. Memory Grants Pending
      , . , .
      Zabbix: perf_counter["\MSSQL$_:Memory Manager\Memory Grants Pending",30]

  10. MS SQL Server: Statistics
    Statistics () Microsoft SQL Server , SQL Server. , SQL Server, , SQL Server .
    1. Butch Requests/sec
      Transact-SQL, . (-, , , . .). .
      Zabbix: perf_counter["\MSSQL$_:SQL Statistics\Batch Requests/sec",30]


( ).:
1)
2) -
. .
, .
.
- , . , . , 1, NAV CRM .
, ( ) .
:
USE [__]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [nav].[ZabbixGetCountRequestStatus]
	@Status nvarchar(255)
AS
BEGIN
	/*
		 -    
	*/
	SET NOCOUNT ON;

	select count(*) as [Count]
	from sys.dm_exec_requests ER with(readuncommitted)
	where [status]=@Status
END


, Zabbix (zabbix\conf\userparams.d) 2 ps1 (PowerShell) :
$SQLServer = "_";
$uid = ""; 
$pwd = "";
$Status="running";

$connectionString = "Server = $SQLServer; Database=_; Integrated Security = False; User ID = $uid; Password = $pwd;";

$connection = New-Object System.Data.SqlClient.SqlConnection;
$connection.ConnectionString = $connectionString;

#    MSSQL / Create a request directly to MSSQL
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
$SqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure;  
$SqlCmd.CommandText = "nav.ZabbixGetCountRequestStatus";
$SqlCmd.Connection = $Connection;

$paramStatus=$SqlCmd.Parameters.Add("@Status" , [System.Data.SqlDbType]::VarChar);
$paramStatus.Value = $Status;

$connection.Open();
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
$SqlAdapter.SelectCommand = $SqlCmd;
$DataSet = New-Object System.Data.DataSet;
$SqlAdapter.Fill($DataSet) > $null;
$connection.Close();

$result = $DataSet.Tables[0].Rows[0]["Count"];

write-host $result;


$SQLServer = "_";
$uid = ""; 
$pwd = "";
$Status="suspended";

$connectionString = "Server = $SQLServer; Database=_; Integrated Security = False; User ID = $uid; Password = $pwd;";

$connection = New-Object System.Data.SqlClient.SqlConnection;
$connection.ConnectionString = $connectionString;

#    MSSQL / Create a request directly to MSSQL
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand;
$SqlCmd.CommandType = [System.Data.CommandType]::StoredProcedure;  
$SqlCmd.CommandText = "nav.ZabbixGetCountRequestStatus";
$SqlCmd.Connection = $Connection;

$paramStatus=$SqlCmd.Parameters.Add("@Status" , [System.Data.SqlDbType]::VarChar);
$paramStatus.Value = $Status;

$connection.Open();
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter;
$SqlAdapter.SelectCommand = $SqlCmd;
$DataSet = New-Object System.Data.DataSet;
$SqlAdapter.Fill($DataSet) > $null;
$connection.Close();

$result = $DataSet.Tables[0].Rows[0]["Count"];

write-host $result;


.conf ( , ) :
UserParameter=____,powershell -NoProfile -ExecutionPolicy Bypass -File _\zabbix\conf\userparams.d\____.ps1
UserParameter=____,powershell -NoProfile -ExecutionPolicy Bypass -File _\zabbix\conf\userparams.d\____.ps1
.conf Zabbix.
Zabbix ( ):
____
____
.

- , , , :
select ER.[session_id]
      ,ER.[request_id]
      ,ER.[start_time]
      ,ER.[status]
      ,ER.[command]
      ,ER.[sql_handle]
      ,ER.[statement_start_offset]
      ,ER.[statement_end_offset]
      ,ER.[plan_handle]
      ,coalesce(ER.[database_id], ES.[database_id]) as [database_id]
	  ,DB_Name(coalesce(ER.[database_id], ES.[database_id])) as [DBName]
      ,(select top(1) text from sys.dm_exec_sql_text(ER.[sql_handle])) as [TSQL]
	  ,(select top(1) [query_plan] from sys.dm_exec_query_plan(ER.[plan_handle])) as [QueryPlan]
      ,ER.[user_id]
      ,ER.[connection_id]
      ,ER.[blocking_session_id]
      ,ER.[wait_type]
      ,ER.[wait_time]
      ,ER.[last_wait_type]
      ,ER.[wait_resource]
      ,ER.[open_transaction_count]
      ,ER.[open_resultset_count]
      ,ER.[transaction_id]
      ,ER.[context_info]
      ,ER.[percent_complete]
      ,ER.[estimated_completion_time]
      ,ER.[cpu_time]
      ,ER.[total_elapsed_time]
      ,ER.[scheduler_id]
      ,ER.[task_address]
      ,ER.[reads]
      ,ER.[writes]
      ,ER.[logical_reads]
      ,ER.[text_size]
      ,ER.[language]
      ,ER.[date_format]
      ,ER.[date_first]
      ,ER.[quoted_identifier]
      ,ER.[arithabort]
      ,ER.[ansi_null_dflt_on]
      ,ER.[ansi_defaults]
      ,ER.[ansi_warnings]
      ,ER.[ansi_padding]
      ,ER.[ansi_nulls]
      ,ER.[concat_null_yields_null]
      ,ER.[transaction_isolation_level]
      ,ER.[lock_timeout]
      ,ER.[deadlock_priority]
      ,ER.[row_count]
      ,ER.[prev_error]
      ,ER.[nest_level]
      ,ER.[granted_query_memory]
      ,ER.[executing_managed_code]
      ,ER.[group_id]
      ,ER.[query_hash]
      ,ER.[query_plan_hash]
	  ,EC.[most_recent_session_id]
      ,EC.[connect_time]
      ,EC.[net_transport]
      ,EC.[protocol_type]
      ,EC.[protocol_version]
      ,EC.[endpoint_id]
      ,EC.[encrypt_option]
      ,EC.[auth_scheme]
      ,EC.[node_affinity]
      ,EC.[num_reads]
      ,EC.[num_writes]
      ,EC.[last_read]
      ,EC.[last_write]
      ,EC.[net_packet_size]
      ,EC.[client_net_address]
      ,EC.[client_tcp_port]
      ,EC.[local_net_address]
      ,EC.[local_tcp_port]
      ,EC.[parent_connection_id]
      ,EC.[most_recent_sql_handle]
	  ,ES.[login_time]
	  ,ES.[host_name]
	  ,ES.[program_name]
	  ,ES.[host_process_id]
	  ,ES.[client_version]
	  ,ES.[client_interface_name]
	  ,ES.[security_id]
	  ,ES.[login_name]
	  ,ES.[nt_domain]
	  ,ES.[nt_user_name]
	  ,ES.[memory_usage]
	  ,ES.[total_scheduled_time]
	  ,ES.[last_request_start_time]
	  ,ES.[last_request_end_time]
	  ,ES.[is_user_process]
	  ,ES.[original_security_id]
	  ,ES.[original_login_name]
	  ,ES.[last_successful_logon]
	  ,ES.[last_unsuccessful_logon]
	  ,ES.[unsuccessful_logons]
	  ,ES.[authenticating_database_id]
from sys.dm_exec_requests ER with(readuncommitted)
left join sys.dm_exec_sessions ES with(readuncommitted)
on ES.session_id = ER.session_id 
left join sys.dm_exec_connections EC  with(readuncommitted)
on EC.session_id = ER.session_id
where ER.status in ('suspended', 'running')


, :
/*
creation_time - ,    .      ,         .  ,     ,   (  ),    ,         .
last_execution_time -     .
execution_count -        
       -       ,    -          . ,  -    ,    .
CPU -      .    ,         ,       .          ,      - .
,      ,    .
AvgCPUTime -      . 
TotDuration -    ,  .
        , ,     " ".         CPU (   ) -    ,       - .          ,          . 
         sys.dm_os_wait_stats.
AvgDur -      .
Reads -   .
    ,      .
  -      ,    .
    ,          .
    ,     ,  ,      ,       .
Writes -     .
 ,   ""    .
 ,       0     ,    ,     ,      tempdb.
AggIO -     - ()
 ,         ,            .
AvgIO -         .
       :
   -  8192 .      , ""  .       ,    (       ),    ,             .
  ,      ,    5,          300,     ,      10.
         -         .
         ,            .  ,          ,           ,         ,           . ,          -             .    ...   ,    ,        .
  -       .  ,    ,       .               .
query_text -   
database_name -   ,   ,  . NULL   
object_name -   (  ),  .
*/
with s as (
	select  creation_time,
			last_execution_time,
			execution_count,
			total_worker_time/1000 as CPU,
			convert(money, (total_worker_time))/(execution_count*1000)as [AvgCPUTime],
			qs.total_elapsed_time/1000 as TotDuration,
			convert(money, (qs.total_elapsed_time))/(execution_count*1000)as [AvgDur],
			total_logical_reads as [Reads],
			total_logical_writes as [Writes],
			total_logical_reads+total_logical_writes as [AggIO],
			convert(money, (total_logical_reads+total_logical_writes)/(execution_count + 0.0))as [AvgIO],
			[sql_handle],
			plan_handle,
			statement_start_offset,
			statement_end_offset
	from sys.dm_exec_query_stats as qs with(readuncommitted)
	where convert(money, (qs.total_elapsed_time))/(execution_count*1000)>=100 --    100 
)
select
	s.creation_time,
	s.last_execution_time,
	s.execution_count,
	s.CPU,
	s.[AvgCPUTime],
	s.TotDuration,
	s.[AvgDur],
	s.[Reads],
	s.[Writes],
	s.[AggIO],
	s.[AvgIO],
	--st.text as query_text,
	case 
		when sql_handle IS NULL then ' '
		else(substring(st.text,(s.statement_start_offset+2)/2,(
			case
				when s.statement_end_offset =-1 then len(convert(nvarchar(MAX),st.text))*2      
				else s.statement_end_offset    
			end - s.statement_start_offset)/2  ))
	end as query_text,
	db_name(st.dbid) as database_name,
	object_schema_name(st.objectid, st.dbid)+'.'+object_name(st.objectid, st.dbid) as [object_name],
	sp.[query_plan],
	s.[sql_handle],
	s.plan_handle
from s
cross apply sys.dm_exec_sql_text(s.[sql_handle]) as st
cross apply sys.dm_exec_query_plan(s.[plan_handle]) as sp



( ) Zabbix. - . , , .
: 24x7 MS SQL Server

:


Zabbix 3.4

Azure SQL SQL Server Database Engine
SQL
SQLSkills
TechNet Microsoft


SQL
Windows
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/338498/

:  

: [1] []
 

:
: 

: ( )

:

  URL