This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
hashicorp_consul [2026/11/01 14:04] val [Добавление и мониторинг web сервисов] |
hashicorp_consul [2026/11/01 15:14] (current) val |
||
|---|---|---|---|
| Line 82: | Line 82: | ||
| }" \ | }" \ | ||
| http://server:8500/v1/agent/service/register | http://server:8500/v1/agent/service/register | ||
| + | </code> | ||
| + | |||
| + | ==== Пример с windows-exporter ==== | ||
| + | |||
| + | <code> | ||
| + | PS> mkdir C:\Scripts | ||
| + | |||
| + | PS> notepad C:\Scripts\register-in-consul.ps1 | ||
| + | </code><code> | ||
| + | $Hostname = [System.Net.Dns]::GetHostName() | ||
| + | $ServiceId = "windows-exporter-$Hostname" | ||
| + | |||
| + | $IpAddress = (Get-NetIPAddress -AddressFamily IPv4 | | ||
| + | Where-Object { $_.InterfaceAlias -notlike "*Loopback*" -and $_.IPAddress -notlike "169.254.*" } | | ||
| + | Select-Object -First 1).IPAddress | ||
| + | |||
| + | $Body = @{ | ||
| + | ID = $ServiceId | ||
| + | Name = "windows-exporter" | ||
| + | Address = $IpAddress | ||
| + | Port = 9182 | ||
| + | Meta = @{ | ||
| + | hostname = $Hostname | ||
| + | } | ||
| + | } | ConvertTo-Json -Compress | ||
| + | |||
| + | $Uri = "http://server:8500/v1/agent/service/register" | ||
| + | Invoke-RestMethod -Method Put -Uri $Uri -ContentType "application/json" -Body $Body | ||
| + | </code><code> | ||
| + | PS> PowerShell.exe -ExecutionPolicy Bypass -File C:\Scripts\register-in-consul.ps1 | ||
| + | |||
| + | PS Admin> | ||
| + | $Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File C:\Scripts\register-in-consul.ps1" | ||
| + | $Trigger = New-ScheduledTaskTrigger -AtStartup | ||
| + | $Trigger.Delay = "PT10S" | ||
| + | Register-ScheduledTask -TaskName "RegisterInConsul" -Action $Action -Trigger $Trigger -User "NT AUTHORITY\SYSTEM" -Force | ||
| + | |||
| + | PS Admin> Get-ScheduledTask -TaskName "RegisterInConsul" | ||
| </code> | </code> | ||