最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Azure實(shí)踐之如何批量為資源組虛擬機(jī)創(chuàng)建alert

2021-10-19 14:07 作者:Vecloud_  | 我要投稿


通過上一篇的簡(jiǎn)介,相信各位對(duì)于簡(jiǎn)單的創(chuàng)建alert,以及Azure monitor使用以及大概有個(gè)印象了?;A(chǔ)的使用總是非常簡(jiǎn)單的,這里再分享一個(gè)常用的alert使用方法?
??
實(shí)際工作中,不管是日常運(yùn)維還是做項(xiàng)目,我們都需要知道VM的實(shí)際性能情況,避免出現(xiàn)性能瓶頸,因此創(chuàng)建alert是一種非常方便的方式,我們可以通過alert第一時(shí)間知道系統(tǒng)出現(xiàn)了性能的瓶頸,以便盡快采取解決措施。?


因此,也衍生了一個(gè)實(shí)際的問題,單獨(dú)為一臺(tái)VM開啟alert很簡(jiǎn)單,但是如果我們需要為一個(gè)資源組內(nèi)十幾甚至幾十上百臺(tái)VM統(tǒng)一創(chuàng)建alert,則會(huì)非常麻煩?


在這里分享一個(gè)自己寫的簡(jiǎn)單腳本,可以通過批量的方式為一個(gè)資源組內(nèi)的所有VM,或者是某個(gè)單獨(dú)的VM創(chuàng)建alert,省去很多不必要的重復(fù)性工作,以下是代碼的內(nèi)容?


<#.NOTES===========================================================================Createdwith:SAPIENTechnologies,Inc.,PowerShellStudio2017v5.4.134Createdon:2019/1/1013:19Createdby:mxyOrganization:Filename:===========================================================================.DESCRIPTIONAdescriptionofthefile.#>param([parameter(Mandatory=$true)][string]$RGName,#資源組名稱[parameter(Mandatory=$false)][string]$VmName,#VM名稱[parameter(Mandatory=$true)][string]$MailAddress,#郵件地址[parameter(Mandatory=$false)][ValidateSet("CPU","Memory")][string]$Metric="CPU",#需要針對(duì)哪個(gè)metric創(chuàng)建alert,方便起見這里目前只是設(shè)置了CPU和內(nèi)存兩種[parameter(Mandatory=$false)][ValidateSet("GreaterThan","GreaterThanOrEqual","LessThan","LessThanOrEqual")][string]$Operation="GreaterThan",#操作條件[parameter(Mandatory=$false)][int]$Threshold=50,#閾值[parameter(Mandatory=$false)][ValidateSet("Average","Last","Maximum","Minimum","Total")]#計(jì)算方式,是平均還是最大等[string]$TimeAggregationOperator="Average",[parameter(Mandatory=$false)][TimeSpan]$WindowSize="00:05:00"#時(shí)間戳)functionWrite-DateTimeMessage{param([parameter(Mandatory=$false)][switch]$Warning,[parameter(Mandatory=$true)][string]$Message,[parameter(Mandatory=$false)][string]$ForegroundColor)if($Warning){Write-Warning($(Get-Date-UFormat'%Y/%m/%d%H:%M:%S')+"*"+$Message)}else{if($ForegroundColor){Write-Host($(Get-Date-UFormat'%Y/%m/%d%H:%M:%S')+"*"+$Message)-ForegroundColor$ForegroundColor}else{Write-Host($(Get-Date-UFormat'%Y/%m/%d%H:%M:%S')+"*"+$Message)}}}#Getmetricnameswitch($Metric){Memory{$MetricName="\Memory\%CommittedBytesInUse"}CPU{$MetricName="\ProcessorInformation(_Total)\%ProcessorTime"}default{#<code>}}#Findthevmifvmnameparameterspecifiedtry{$Error.Clear()if($VmName){Write-DateTimeMessage"Tryingtofindvm$VmNameinresourcegroup$RGName"$vms=Get-AzureRmVM-ResourceGroupName$RGName-Name$VmName-ErrorActionStopWrite-DateTimeMessage"vm$VmNameFoundinresourcegroup$RGName"}else{$vms=Get-AzureRmVM-ResourceGroupName$RGName-ErrorActionStop}#Createactionemail$actionEmail=New-AzureRmAlertRuleEmail-CustomEmail$MailAddress-WarningActionSilentlyContinue#Getresourceidandaddalertif($vms-ne$null){foreach($vmin$vms){$vmID=$vm.id$AlertName=$vm.Name+"_Alert_"+$Metric+"_"+$Operation+"_"+$Threshold+"_"+$actionEmail.CustomEmails$Error.Clear()Write-DateTimeMessage"Tryingtoaddalertforvm$($vm.Name)..."Add-AzureRmMetricAlertRule-Name$AlertName-Location"ChinaEast"-ResourceGroup$RGName-TargetResourceId$vmID-MetricName$MetricName-Operator$Operation-Threshold$Threshold-WindowSize$WindowSize-TimeAggregationOperator$TimeAggregationOperator-Action$actionEmail-ErrorAction'Stop'-WarningAction'SilentlyContinue'|Out-NullWrite-DateTimeMessage"Addalertforvm$($vm.Name)successfully!"}}else{Write-DateTimeMessage"Novminresourcegroup$RGName"}}catch{Write-DateTimeMessage$Error[0].Exception.Message}?

可以看到腳本很簡(jiǎn)單,運(yùn)行方法這里舉個(gè)例子,比如要為mxytest這個(gè)資源組下的所有VM創(chuàng)建CPU10分鐘之內(nèi)大于80便發(fā)郵件給abc@abc.com的alert,則可以按照以下方式運(yùn)行?

.\Create-AzureAlert.ps1 -RGName mxytest -MailAddress "abc@abc.com" -Metric CPU -Operation GreaterThan -Threshold 80 -TimeAggregationOperator Average -WindowSize "00:10:00"?

創(chuàng)建完成后即可在alert中國看到對(duì)應(yīng)的內(nèi)容
Get-AzureRmAlertRule -ResourceGroupName mxytest -WarningAction SilentlyContinue?

也可以通過PowerShell獲取到信息

了解更多網(wǎng)絡(luò)知識(shí)關(guān)注:http://www.vecloud.com/

Azure實(shí)踐之如何批量為資源組虛擬機(jī)創(chuàng)建alert的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
岫岩| 诸城市| 商南县| 潞城市| 镇康县| 剑河县| 公主岭市| 陈巴尔虎旗| 建平县| 曲沃县| 北宁市| 东丽区| 河南省| 宾阳县| 平舆县| 徐州市| 扶沟县| 宁化县| 廊坊市| 河北区| 靖安县| 松江区| 阿瓦提县| 湟中县| 出国| 清远市| 安吉县| 泽州县| 丰都县| 丹江口市| 白沙| 兴宁市| 怀柔区| 班玛县| 安阳县| 久治县| 荣成市| 夏津县| 麦盖提县| 贵南县| 邻水|