🔗

Building Cross-Platform Performance Monitoring Through SSH PowerShell Remoting: Collect Windows Metrics Using Linux Infrastructure

· Server Scout

Prerequisites and SSH Configuration

Most Linux administrators prefer to manage all their infrastructure from familiar terminals and dashboards. But mixed environments inevitably include Windows servers that need monitoring alongside Linux systems. Rather than deploying separate Windows-specific tools, you can extend your existing Linux monitoring to collect Windows performance data through SSH and PowerShell.

This approach treats Windows servers as extensions of your Linux-centric infrastructure rather than isolated systems requiring different toolsets.

Installing PowerShell Core on Windows Server

First, install PowerShell Core 6.0 or later on your Windows targets. Unlike Windows PowerShell 5.1, PowerShell Core supports SSH remoting and provides better cross-platform compatibility.

Download the latest PowerShell Core MSI from Microsoft and install with default settings. Verify installation by opening PowerShell and checking $PSVersionTable.PSVersion shows version 6.0 or higher.

Install OpenSSH Server if not already present. On Windows Server 2019 and later, run Add-WindowsCapability -Online -Name OpenSSH.Server from an elevated PowerShell session.

Configuring SSH Key Authentication

Generate SSH keys on your Linux monitoring server using ssh-keygen -t rsa -b 4096. Copy the public key to your Windows server's C:\Users\[username]\.ssh\authorized_keys file.

Test authentication with ssh username@windowsserver 'pwsh -Command "Get-ComputerInfo | Select-Object TotalPhysicalMemory"'. This command should return memory information without prompting for a password.

Essential Performance Counter Commands

Windows performance counters provide equivalent data to Linux's /proc filesystem. The key difference lies in accessing this data through PowerShell cmdlets rather than reading files directly.

Memory Utilization Equivalents

Linux administrators typically read /proc/meminfo for memory statistics. Windows equivalent data comes from Get-Counter cmdlets and WMI queries.

Use Get-Counter "\Memory\Available MBytes" for free memory, similar to reading MemAvailable from /proc/meminfo. For total memory, query Get-CimInstance -ClassName Win32_PhysicalMemory | Measure-Object Capacity -Sum.

Swap usage requires Get-Counter "\Paging File(_Total)\% Usage", which provides similar information to SwapTotal and SwapFree calculations from Linux.

CPU Load and Process Monitoring

Windows doesn't have direct load average equivalents like /proc/loadavg, but you can approximate this with processor queue length and utilisation metrics.

Collect CPU utilisation with Get-Counter "\Processor(_Total)\% Processor Time". For process information equivalent to /proc/stat, use Get-Process | Select-Object Name,CPU,WorkingSet64,Id.

Processor queue length from Get-Counter "\System\Processor Queue Length" indicates system load pressure similar to Linux load averages.

Disk I/O and Storage Metrics

Disk metrics require multiple performance counters to match /proc/diskstats information. Key counters include:

  • Get-Counter "\PhysicalDisk(_Total)\Disk Read Bytes/sec"
  • Get-Counter "\PhysicalDisk(_Total)\Disk Write Bytes/sec"
  • Get-Counter "\PhysicalDisk(_Total)\Current Disk Queue Length"

For filesystem usage equivalent to df output, use Get-CimInstance -ClassName Win32_LogicalDisk | Select-Object DeviceID,Size,FreeSpace.

Building Automated Collection Scripts

Once you understand the individual commands, create wrapper scripts that standardise data collection across your infrastructure.

Bash Wrapper Functions

Create bash functions that execute PowerShell commands via SSH and format output consistently:

get_windows_memory() {
    local host="$1"
    ssh "$host" 'pwsh -Command "Get-Counter \"\\Memory\\Available MBytes\" | Select-Object -ExpandProperty CounterSamples | Select-Object -ExpandProperty CookedValue"'
}

This function returns available memory in megabytes, matching the format your Linux monitoring expects.

Build similar functions for CPU usage, disk space, and process counts. Each function should return data in formats compatible with your existing monitoring thresholds.

Error Handling and Timeouts

SSH connections can fail or timeout, especially in mixed network environments. Add timeout controls and error handling to prevent monitoring delays.

Use ssh -o ConnectTimeout=10 -o ServerAliveInterval=5 to set connection timeouts. Test connectivity before executing complex PowerShell commands.

Implement fallback mechanisms when primary collection methods fail. For example, if Get-Counter fails, fall back to basic WMI queries that work on older Windows versions.

Data Format Standardisation

Different operating systems report metrics in various units and formats. Your monitoring system needs consistent data regardless of the source platform.

Converting Windows Metrics to Unix Format

Windows reports memory in megabytes while Linux uses kilobytes in /proc/meminfo. Convert Windows values by multiplying by 1024 to match Linux expectations.

CPU percentages work similarly across platforms, but Windows performance counters sometimes return decimal values while Linux reports integers. Round Windows values to maintain consistency.

Disk space calculations differ significantly. Windows reports in bytes while df typically shows 1K blocks. Standardise on bytes for internal calculations, then format for display.

Integration with Existing Monitoring

The goal is seamless integration with your current Linux monitoring infrastructure. Whether you use Server Scout, custom scripts, or other solutions, Windows metrics should appear alongside Linux data without requiring separate dashboards.

Server Scout's plugin architecture naturally accommodates this approach, allowing custom scripts to collect Windows data and present it through the same interface as Linux metrics.

For custom monitoring solutions, create unified configuration files that specify collection methods per server type. Your alerting rules can then apply consistent thresholds regardless of the underlying operating system.

Store collected metrics in the same format and location as Linux data. This ensures historical analysis and reporting work across your entire infrastructure without platform-specific adjustments.

Mixed environments become significantly more manageable when you can monitor everything through familiar Linux tools and interfaces. This SSH-based approach provides that capability without requiring Windows-specific monitoring products or separate management interfaces.

The Cross-Platform Monitoring Integration approach demonstrates how teams successfully unified monitoring across diverse infrastructures using similar techniques.

By treating Windows servers as remote endpoints accessible through SSH, you maintain the simplicity and consistency of Linux-based monitoring while gaining visibility into your complete infrastructure. The result is unified monitoring that scales with your environment rather than fragmenting across platform-specific tools.

FAQ

Does this approach work with Windows Server Core installations?

Yes, PowerShell Core and OpenSSH Server both support Windows Server Core. The headless nature of Core installations actually makes SSH-based monitoring more appropriate than GUI-dependent tools.

Can I collect Windows Event Log data through SSH PowerShell commands?

Absolutely. Use Get-WinEvent cmdlets to query specific event logs. For example, Get-WinEvent -LogName System -MaxEvents 100 retrieves recent system events that you can parse for monitoring alerts.

How does performance compare to native Windows monitoring agents?

SSH overhead is minimal for periodic metric collection. The trade-off in slight performance cost is usually worth the operational benefits of unified monitoring infrastructure.

Ready to Try Server Scout?

Start monitoring your servers and infrastructure in under 60 seconds. Free for 3 months.

Start Free Trial