Stato di un servizio

Mostra stato, tipo di avvio e dipendenze di un servizio.

PowerShell (Windows)

Get-Service Integrato

Get-Service postfix | Format-List Name, Status, StartType, DependentServices

sc.exe Integrato

sc.exe qc postfix
sc.exe queryex postfix

Shell Unix (bash)

systemctl Integrato

systemctl status postfix --no-pager
systemctl is-enabled postfix

service Strumento aggiuntivo

service postfix status

Riavviare un servizio

Riavvia un servizio e ne mostra poi lo stato.

PowerShell (Windows)

Restart-Service Integrato

Restart-Service postfix -Force
Get-Service postfix | Select-Object Name, Status

sc.exe Integrato

sc.exe stop postfix
sc.exe start postfix

Shell Unix (bash)

systemctl Integrato

sudo systemctl restart postfix
systemctl status postfix --no-pager | head -10

service Strumento aggiuntivo

sudo service postfix restart

Interrompe le connessioni in corso. Su un server di posta significa che gli invii vengono rifiutati per qualche secondo e ritentati in seguito.

Seguire un log

Segue in tempo reale un file di log o il journal del servizio mentre riproducete un errore.

Postfix

PowerShell (Windows)

Get-Content -Wait Integrato

Get-Content "/var/log/mail.log" -Tail 50 -Wait

Get-WinEvent Integrato

Get-WinEvent -LogName Application -MaxEvents 50 | Where-Object { $_.ProviderName -like "*postfix*" } | Format-Table TimeCreated, Id, LevelDisplayName, Message -AutoSize

Shell Unix (bash)

journalctl Integrato

journalctl -u postfix -f -n 50

tail Integrato

tail -f -n 50 /var/log/mail.log

Cercare in un log

Cerca un termine o un codice di risposta in un file di log e mostra le ultime occorrenze.

PowerShell (Windows)

Select-String Integrato

Select-String -Path "/var/log/mail.log" -Pattern "550" | Select-Object -Last 40

Get-WinEvent Integrato

Get-WinEvent -FilterHashtable @{LogName="Application"; Level=2; StartTime=(Get-Date).AddHours(-24)} | Format-Table TimeCreated, ProviderName, Message -AutoSize

Shell Unix (bash)

grep Integrato

grep -i "550" /var/log/mail.log | tail -40

journalctl Strumento aggiuntivo

journalctl --since "24 hours ago" | grep -i "550" | tail -40

Contare i codici di errore SMTP

Conta i codici di risposta 4xx e 5xx nel log di posta, ordinati per frequenza: mostra subito se la causa è una destinazione o uno schema.

Mail-Log

PowerShell (Windows)

Select-String Integrato

Select-String -Path "/var/log/mail.log" -Pattern "\b(4\d\d|5\d\d)\b" |
  Group-Object { ($_.Line -split "\s+" | Select-String "^[45]\d\d$").Matches.Value } -NoElement |
  Sort-Object Count -Descending | Select-Object -First 15

Get-MessageTrackingLog Strumento aggiuntivo

Get-MessageTrackingLog -EventId FAIL -Start (Get-Date).AddHours(-24) | Group-Object RecipientStatus -NoElement | Sort-Object Count -Descending

Shell Unix (bash)

grep / awk Integrato

grep -oE "\b[45][0-9][0-9] [0-9]\.[0-9]\.[0-9]" /var/log/mail.log | sort | uniq -c | sort -rn | head -15

journalctl Strumento aggiuntivo

journalctl -u postfix --since today | grep -oE "status=(bounced|deferred|sent)" | sort | uniq -c

Spazio su disco

Mostra lo spazio libero e le directory più grandi: un disco pieno blocca la coda e i log.

PowerShell (Windows)

Get-PSDrive / Get-Volume Integrato

Get-Volume | Where-Object DriveLetter | Format-Table DriveLetter, FileSystemLabel, @{N="Frei(GB)";E={[math]::Round($_.SizeRemaining/1GB,1)}}, @{N="Gesamt(GB)";E={[math]::Round($_.Size/1GB,1)}}

Get-ChildItem Integrato

Get-ChildItem C:\ -Recurse -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 10 FullName, @{N="MB";E={[math]::Round($_.Length/1MB,1)}}

Shell Unix (bash)

df / du Integrato

df -h
du -xh --max-depth=1 /var | sort -h | tail -15

ncdu Strumento aggiuntivo

ncdu /var

Carico e processi

Mostra i processi con il carico CPU più alto e il loro uso di memoria.

PowerShell (Windows)

Get-Process Integrato

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 Name, Id, CPU, @{N="MB";E={[math]::Round($_.WorkingSet64/1MB)}}

Get-Counter Integrato

Get-Counter "\Processor(_Total)\% Processor Time", "\Memory\Available MBytes" -SampleInterval 2 -MaxSamples 3

Shell Unix (bash)

ps / top Integrato

ps aux --sort=-%cpu | head -11
top -b -n 1 | head -15

htop Strumento aggiuntivo

htop -d 10

Altre aree