Last active
December 20, 2019 06:53
-
-
Save ryosms/139a167a34c272ac110f27898c75e858 to your computer and use it in GitHub Desktop.
Windowsのバッチ処理の実行結果をmkr wrapとmkr annotationsで確認する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[int]$ExitCode = 0, | |
[int]$WaitSeconds = 60 | |
) | |
Write-Output("Start awesome-batch (WaitSeconds: {0})" -f $WaitSeconds) | |
# wait 1 minute | |
Start-Sleep -Seconds $WaitSeconds | |
Write-Output("Complete awesome-batch (Exit: {0})" -f $ExitCode) | |
exit $ExitCode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[switch]$Critical, | |
[string]$ServieName = "mkr-test", | |
[string]$RoleName = "mkr", | |
[string]$AnnotationTitle = "Awesome Batch Result" | |
) | |
$env:Path="$env:Path;C:\Program Files (x86)\Mackerel\mackerel-agent" | |
$ExitCode = 0 | |
if($Critical) { | |
$ExitCode = 1 | |
} | |
function GetEpoch($date) { | |
return [Math]::Truncate(($date - (Get-Date("1970/01/01 00:00:00 GMT"))).TotalSeconds) | |
} | |
$from = $(GetEpoch(Get-Date)) | |
# Build full path to call batch script | |
$batch = Join-Path $(Split-Path -Parent $($MyInvocation.MyCommand.Path)) "awesome-batch.ps1" | |
$result = $(mkr wrap ` | |
--name "awesome batch" ` | |
--detail ` | |
--auto-close ` | |
-- powershell $batch -ExitCode $ExitCode) | |
$exit_code = $LastExitCode | |
$to = $(GetEpoch(Get-Date)) | |
# post graph annotation | |
mkr annotations create ` | |
--service "$ServieName" ` | |
--from $from ` | |
--to $to ` | |
--title "$AnnotationTitle" ` | |
--description "$result" | |
exit $exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment