Skip to content

Commit

Permalink
Merge pull request prometheus-community#1447 from jkroepke/setup-no-f…
Browse files Browse the repository at this point in the history
…irewall
  • Loading branch information
jkroepke authored Apr 21, 2024
2 parents f23b2f8 + 6d00d4b commit 2001f8c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.wxs]

indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ output/
.vscode
.idea
*.syso
installer/*.msi
installer/*.wixpdb
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,26 @@ Example service collector with a custom query.
msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""
```

On some older versions of Windows you may need to surround parameter values with double quotes to get the install command parsing properly:
On some older versions of Windows,
you may need to surround parameter values with double quotes to get the installation command parsing properly:
```powershell
msiexec /i C:\Users\Administrator\Downloads\windows_exporter.msi ENABLED_COLLECTORS="ad,iis,logon,memory,process,tcp,textfile,thermalzone" TEXTFILE_DIRS="C:\custom_metrics\"
```

To install the exporter with creating a firewall exception, use the following command:

```powershell
msiexec /i <path-to-msi-file> ADD_FIREWALL_EXCEPTION=yes
```


Powershell versions 7.3 and above require [PSNativeCommandArgumentPassing](https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.3) to be set to `Legacy` when using `--% EXTRA_FLAGS`:

```powershell
$PSNativeCommandArgumentPassing = 'Legacy'
msiexec /i <path-to-msi-file> ENABLED_COLLECTORS=os,service --% EXTRA_FLAGS="--collector.service.services-where ""Name LIKE 'sql%'"""
```


## Kubernetes Implementation

See detailed steps to install on Windows Kubernetes [here](./kubernetes/kubernetes.md).
Expand Down
2 changes: 1 addition & 1 deletion installer/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Copy-Item -Force $PathToExecutable Work/windows_exporter.exe

Write-Verbose "Creating windows_exporter-${Version}-${Arch}.msi"
$wixArch = @{"amd64" = "x64"; "arm64" = "arm64"}[$Arch]
$wixOpts = "-ext WixFirewallExtension -ext WixUtilExtension"

Invoke-Expression "wix build -arch $wixArch -o .\windows_exporter-$($Version)-$($Arch).msi .\windows_exporter.wxs -d Version=$($Version) -ext WixToolset.Firewall.wixext -ext WixToolset.Util.wixext"

Write-Verbose "Done!"
Expand Down
24 changes: 17 additions & 7 deletions installer/windows_exporter.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<Property Id="EXTRA_FLAGS" Secure="yes" />
<SetProperty Id="ExtraFlags" After="InstallFiles" Sequence="execute" Value="[EXTRA_FLAGS]" Condition="EXTRA_FLAGS" />

<Property Id="ADD_FIREWALL_EXCEPTION" Secure="yes" />
<SetProperty Id="FirewallException" After="InstallFiles" Sequence="execute" Value="[ADD_FIREWALL_EXCEPTION]" Condition="ADD_FIREWALL_EXCEPTION" />

<Property Id="LISTEN_ADDR" Secure="yes" Value="0.0.0.0" />
<Property Id="LISTEN_PORT" Secure="yes" Value="9182" />

Expand Down Expand Up @@ -49,11 +52,7 @@

<ComponentGroup Id="Files">
<Component Directory="APPLICATIONROOTDIRECTORY">
<File Id="windows_exporter.exe" Name="windows_exporter.exe" Source="Work\windows_exporter.exe" KeyPath="yes">
<fw:FirewallException Id="MetricsEndpoint" Name="windows_exporter (HTTP [LISTEN_PORT])" Description="windows_exporter HTTP endpoint" Port="[LISTEN_PORT]" Protocol="tcp" IgnoreFailure="yes">
<fw:RemoteAddress Value="[REMOTE_ADDR]" />
</fw:FirewallException>
</File>
<File Id="windows_exporter.exe" Name="windows_exporter.exe" Source="Work\windows_exporter.exe" KeyPath="yes" />
<ServiceInstall Id="InstallExporterService" Name="windows_exporter" DisplayName="windows_exporter" Description="Exports Prometheus metrics about the system" ErrorControl="normal" Start="auto" Type="ownProcess" Arguments="--log.file eventlog [CollectorsFlag] --web.listen-address [LISTEN_ADDR]:[LISTEN_PORT] [MetricsPathFlag] [TextfileDirsFlag] [ExtraFlags]">
<util:ServiceConfig FirstFailureActionType="restart" SecondFailureActionType="restart" ThirdFailureActionType="restart" RestartServiceDelayInSeconds="60" />
<ServiceDependency Id="wmiApSrv" />
Expand All @@ -64,15 +63,26 @@
<CreateFolder />
</Component>
</ComponentGroup>
<ComponentGroup Id="CG_FirewallException">
<Component Condition="ADD_FIREWALL_EXCEPTION=&quot;yes&quot;" Directory="APPLICATIONROOTDIRECTORY" Id="C_FirewallException" Guid="9f522655-ac0e-42d2-a512-a7b19ebec7f7">
<fw:FirewallException Id="MetricsEndpoint" Name="windows_exporter (HTTP [LISTEN_PORT])" Description="windows_exporter HTTP endpoint" Port="[LISTEN_PORT]" Protocol="tcp" IgnoreFailure="yes">
<fw:RemoteAddress Value="[REMOTE_ADDR]" />
</fw:FirewallException>
</Component>
</ComponentGroup>

<Feature Id="DefaultFeature" Level="1">
<ComponentGroupRef Id="Files" />
</Feature>

<Directory Id="$(var.PlatformProgramFiles)">
<Feature Id="FirewallException" Level="1">
<ComponentGroupRef Id="CG_FirewallException" />
</Feature>

<StandardDirectory Id="ProgramFiles64Folder">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="windows_exporter">
<Directory Id="textfile_inputs" Name="textfile_inputs" />
</Directory>
</Directory>
</StandardDirectory>
</Package>
</Wix>

0 comments on commit 2001f8c

Please sign in to comment.