Closed LLHogia closed 10 months ago
One solution could be to add native support for performance counters in YML.
Something like this:
integrations:
- name: nri-flex
interval: 120s
config:
name: getPerformanceCounter
global:
user: WindowsOrDomainUserWithAdminAccess
pass: password123
apis:
- event_type: getPerformanceCounter
performance_counters:
- \\ServerA\UDPv4\Datagrams No Port/sec
- \\ServerB\UDPv4\Datagrams Sent/sec
Or something like this:
integrations:
- name: nri-flex
interval: 120s
config:
name: getPerformanceCounter
global:
user: WindowsOrDomainUserWithAdminAccess
pass: password123
apis:
- event_type: getPerformanceCounter
performance_counters:
- name: Datagrams No Port/sec
counter: \\ServerA\UDPv4\Datagrams No Port/sec
- name: Datagrams Sent/sec
counter: \\ServerB\UDPv4\Datagrams Sent/sec
The problem with my workaround is the execution time. Getting 20 counters from different machines takes 15-20 seconds. I assume this is a lot faster if not doing it via an external PowerShell file which also invokes a command as another user.
There's no plan to include perfcounters in Flex. An alternative is the OTel collector receiver: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/windowsperfcountersreceiver that can be used to push metrics directly to the OTLP endpoint.
Description
I have tried the below YML to execute a PowerShell script with a specific user and password:
I'm not 100% this is the correct syntax. I have tried putting the globals below "name: nri-flex" as well. Same result!
Error message in New Relic:
No errors in the newrelic-infra.log file. The integrations returns "Integration health check finished with success".
Expected Behavior
Should be possible to pass a username and password to a PowerShell script to invoke that script with the specified credentials.
Steps to Reproduce
\\COMPUTERNAME\PerformanceCounterPath
to the CounterPath attribut. Or just add the computer name as a parameter to the Get-Counter method, like:(Get-Counter -MaxSamples 1 -Counter $c.CounterPath -ComputerName COMPUTERNAME).CounterSamples
Example 1
Example 2
Workaround
I want to be able to get performance counters from different machines. This is because we're using a Windows Failover Cluster. So we don't work with unique server names. All performance counters should be targeted via the cluster node name.
Enable PSRemoting on each machine within the cluster.
Create a TXT file with the below examples:
Create a standard YML file for the integrations and call the PowerShell script. You can use the YML from the description (remove global).
Create the PowerShell script you're calling from the YML file. Since New Relic Infrastructure Agent is running as Local System we need to invoke a command with other credentials. This is why I want to be able to pass the username and password via the YML file so I don't need to invoke from the PowerShell script. See our example below:
Construct the PSCredential object
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Define the path to the folder containing TXT files
$folderPath = "C:\Program Files\New Relic\newrelic-infra\integrations.d\Performance Counters"
Get all TXT files within the folder
$txtFiles = Get-ChildItem $folderPath -Filter *.txt
Initialize the result array
$results = @()
Loop through each TXT file
foreach ($txtFile in $txtFiles) {
Read the content of the file and split it into lines
}
Convert the results array to JSON
$results | ConvertTo-Json