Skip to content

Commit

Permalink
Simple Monitor の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
MasayukiOzawa committed Sep 26, 2018
1 parent 716e886 commit d02c22a
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 40 deletions.
10 changes: 8 additions & 2 deletions Simple Monitor/02.データアクセス状況の取得.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
SET NOCOUNT ON

-- データアクセス状況の取得
DROP TABLE IF EXISTS #T1
DROP TABLE IF EXISTS #T2
-- DROP TABLE IF EXISTS #T1
-- DROP TABLE IF EXISTS #T2

IF (OBJECT_ID('tempdb..#T1') IS NOT NULL)
DROP TABLE #T1
IF (OBJECT_ID('tempdb..#T2') IS NOT NULL)
DROP TABLE #T2


SELECT
GETDATE() counter_date,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
SET NOCOUNT ON

-- トランザクションログの書き込み状況
DROP TABLE IF EXISTS #T1
DROP TABLE IF EXISTS #T2
-- DROP TABLE IF EXISTS #T1
-- DROP TABLE IF EXISTS #T2
IF (OBJECT_ID('tempdb..#T1') IS NOT NULL)
DROP TABLE #T1
IF (OBJECT_ID('tempdb..#T2') IS NOT NULL)
DROP TABLE #T2

SELECT
GETDATE() counter_date,
Expand Down
87 changes: 61 additions & 26 deletions Simple Monitor/07.待ち事象の情報の取得.sql
Original file line number Diff line number Diff line change
@@ -1,32 +1,67 @@
SET NOCOUNT ON

SELECT
GETDATE() as counter_date,
counter_name,
[Average wait time (ms)],
[Waits in progress],
[Waits started per second],
[Cumulative wait time (ms) per second]
FROM
(
IF (SERVERPROPERTY('ProductMajorVersion') IS NOT NULL)
BEGIN
SELECT
RTRIM(instance_name) AS instance_name,
RTRIM(counter_name) AS counter_name,
cntr_value
FROM
sys.dm_os_performance_counters
WHERE
object_name like '%Wait Statistics%'
) AS T
PIVOT
(
SUM(cntr_value)
FOR instance_name
IN(
GETDATE() as counter_date,
counter_name,
[Average wait time (ms)],
[Waits in progress],
[Waits started per second],
[Cumulative wait time (ms) per second]
)
) AS PVT
ORDER BY counter_name
FROM
(
SELECT
RTRIM(instance_name) AS instance_name,
RTRIM(counter_name) AS counter_name,
cntr_value
FROM
sys.dm_os_performance_counters
WHERE
object_name like '%Wait Statistics%'
) AS T
PIVOT
(
SUM(cntr_value)
FOR instance_name
IN(
[Average wait time (ms)],
[Waits in progress],
[Waits started per second],
[Cumulative wait time (ms) per second]
)
) AS PVT
ORDER BY counter_name
END
ELSE
BEGIN
SELECT
GETDATE() as counter_date,
counter_name,
[平均待機時間 (ミリ秒)] AS [Average wait time (ms)],
[待機中] AS [Waits in progress],
[1 秒あたりに開始された待機回数] AS [Waits started per second],
[1 秒あたりの累積待機時間 (ミリ秒)] AS [Cumulative wait time (ms) per second]
FROM
(
SELECT
RTRIM(instance_name) AS instance_name,
RTRIM(counter_name) AS counter_name,
cntr_value
FROM
sys.dm_os_performance_counters
WHERE
object_name like '%Wait Statistics%'
) AS T
PIVOT
(
SUM(cntr_value)
FOR instance_name
IN(
[平均待機時間 (ミリ秒)],
[待機中],
[1 秒あたりに開始された待機回数],
[1 秒あたりの累積待機時間 (ミリ秒)]
)
) AS PVT
ORDER BY counter_name
END
8 changes: 6 additions & 2 deletions Simple Monitor/08.ファイル IO の取得_Box.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
SET NOCOUNT ON

-- ファイル I/O の取得
DROP TABLE IF EXISTS #T1
DROP TABLE IF EXISTS #T2
-- DROP TABLE IF EXISTS #T1
-- DROP TABLE IF EXISTS #T2
IF (OBJECT_ID('tempdb..#T1') IS NOT NULL)
DROP TABLE #T1
IF (OBJECT_ID('tempdb..#T2') IS NOT NULL)
DROP TABLE #T2

SELECT
GETDATE() AS counter_date,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
DROP TABLE IF EXISTS #T1
DROP TABLE IF EXISTS #T2
-- DROP TABLE IF EXISTS #T1
-- DROP TABLE IF EXISTS #T2
IF (OBJECT_ID('tempdb..#T1') IS NOT NULL)
DROP TABLE #T1
IF (OBJECT_ID('tempdb..#T2') IS NOT NULL)
DROP TABLE #T2


SELECT
GETDATE() AS counter_date,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
DROP TABLE IF EXISTS #T1
DROP TABLE IF EXISTS #T2
-- DROP TABLE IF EXISTS #T1
-- DROP TABLE IF EXISTS #T2
IF (OBJECT_ID('tempdb..#T1') IS NOT NULL)
DROP TABLE #T1
IF (OBJECT_ID('tempdb..#T2') IS NOT NULL)
DROP TABLE #T2

SELECT
GETDATE() AS counter_date,
Expand Down
8 changes: 4 additions & 4 deletions Simple Monitor/Simple Monitor.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[CmdletBinding()]
param(
$server = "",
$server = "localhost",
$user = "",
$password = "",
$outputdir = "C:\Simple Monitor",
$database = "",
$database = "master",
$interval = 5,
$isAzure = $false,
$isPDW = $false
Expand All @@ -16,7 +16,7 @@ Clear-Host
Write-Output "Press Ctrl+C to exit."

# PS1 と同じディレクトリ内の SQL ファイルを実行する
# Box と SQL Database でし応するクエリが異なる場合、Box or Azure のファイル名で使い分ける
# Box と SQL Database で使用するクエリが異なる場合、Box or Azure のファイル名で使い分ける
if ($isPDW){
$sqllist = Get-ChildItem -Path (Split-Path $MyInvocation.MyCommand.Path -Parent) | ? Name -Match "^[0-9].*sql" | ? Name -Like "*PDW*"
}elseif($isAzure){
Expand Down Expand Up @@ -50,7 +50,7 @@ while($true){
# PBI Desktop でオリジナルのファイルを読み込むと、ファイルロックしてしまうことがあるので、二次ディレクトリに退避し、PBI Desktop ではそちらにアクセス
Copy-Item (Join-Path $outfilepath $outfile) (Join-Path $outputdir "Results") -Force
}catch{
Write-Host ("{0}:{1}"-f (Get-Date),$Error[0].Exception.Message)
Write-Host ("{0}:[{1}]:{2}"-f (Get-Date), $sqlfile, $Error[0].Exception.Message)
}
}

Expand Down

0 comments on commit d02c22a

Please sign in to comment.