chore: replace the Makefile with a minimal one (#2544)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
This commit is contained in:
Jan-Otto Kröpke
2026-10-08 14:42:59 +02:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 96a998772b
commit 48640e0070
3 changed files with 49 additions and 83 deletions
+3
View File
@@ -6,6 +6,9 @@
# This image MUST be built with docker buildx build (buildx) command on a Linux system.
# Ref: https://github.com/microsoft/windows-host-process-containers-base-image
# The build context must contain the amd64 binary, named windows_exporter-<version>-amd64.exe
# like the CI build stages it.
ARG BASE="mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0"
FROM $BASE
+35 -63
View File
@@ -1,77 +1,49 @@
GOOS ?= windows
VERSION ?= $(shell cat VERSION)
DOCKER ?= docker
##
# Console Colors
##
GREEN := $(shell printf "\033[0;32m")
YELLOW := $(shell printf "\033[0;33m")
CYAN := $(shell printf "\033[0;36m")
RESET := $(shell printf "\033[0m")
# DOCKER_REPO is the official image repository name at docker.io, quay.io.
DOCKER_REPO ?= prometheuscommunity
DOCKER_IMAGE_NAME ?= windows-exporter
# ALL_DOCKER_REPOS is the list of repositories to push the image to. ghcr.io requires that org name be the same as the image repo name.
ALL_DOCKER_REPOS ?= docker.io/$(DOCKER_REPO) ghcr.io/prometheus-community # quay.io/$(DOCKER_REPO)
##
# Targets
##
.PHONY: help
help: ## show this help.
@echo 'Usage:'
@echo " ${GREEN}make${RESET} ${YELLOW}<target>${RESET}"
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${GREEN}%-21s${YELLOW}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST) | sort
# Image Variables for host process Container
# Windows image build is heavily influenced by https://github.com/kubernetes/kubernetes/blob/master/cluster/images/etcd/Makefile
OS ?= ltsc2019
ALL_OS ?= ltsc2019 ltsc2022
BASE_IMAGE ?= mcr.microsoft.com/windows/nanoserver
.PHONY: clean
clean: ## clean build output
@rm -rf windows_exporter.exe dist/ output/
.PHONY: build
build: windows_exporter.exe
build: export GOOS := windows
build: ## build windows_exporter.exe
@go build -o windows_exporter.exe ./cmd/windows_exporter
windows_exporter.exe: generate
CGO_ENABLED=0 go build -trimpath -tags=trimpath -o $@ ./cmd/windows_exporter
.PHONY: test
test: ## run the tests
@go test ./...
.PHONY: generate
generate:
go generate ./...
.PHONY: lint
lint: ## run golangci-lint
@go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run ./...
test:
go test -v ./...
bench:
go test -v -bench='benchmarkcollector' ./internal/collectors/{cpu,logical_disk,physical_disk,memory,net,printer,process,service,system,tcp,time}
lint:
golangci-lint -c .golangci.yaml run
.PHONY: e2e-test
e2e-test: windows_exporter.exe
powershell -NonInteractive -ExecutionPolicy Bypass -File .\tools\end-to-end-test.ps1
fmt:
gofmt -l -w -s .
crossbuild: generate
mkdir -p output/amd64 output/arm64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -tags=trimpath -o output/amd64/windows_exporter.exe ./cmd/windows_exporter
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -trimpath -tags=trimpath -o output/arm64/windows_exporter.exe ./cmd/windows_exporter
.PHONY: package
package: crossbuild
powershell -NonInteractive -ExecutionPolicy Bypass -File .\installer\build.ps1 -PathToExecutable .\output\amd64\windows_exporter.exe -Version $(shell git describe --tags --abbrev=0)
build-image: crossbuild
$(DOCKER) build --build-arg=BASE=$(BASE_IMAGE):$(OS) -f Dockerfile -t local/$(DOCKER_IMAGE_NAME):$(VERSION)-$(OS) .
build-hostprocess:
$(DOCKER) buildx build --build-arg=BASE=mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 -f Dockerfile -t local/$(DOCKER_IMAGE_NAME):$(VERSION)-hostprocess .
sub-build-%:
$(MAKE) OS=$* build-image
build-all: crossbuild
@for docker_repo in ${DOCKER_REPO}; do \
echo $(DOCKER) buildx build -f Dockerfile -t $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) .; \
done
push:
@for docker_repo in ${DOCKER_REPO}; do \
echo $(DOCKER) buildx build --push -f Dockerfile -t $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) .; \
done
.PHONY: push-all
push-all: build-all
$(MAKE) DOCKER_REPO="$(ALL_DOCKER_REPOS)" push
.PHONY: fmt
fmt: ## format the code
@go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 fmt
# Mandatory target for container description sync action
.PHONY: docker-repo-name
+11 -20
View File
@@ -12,31 +12,22 @@ Requirements:
## Container Image
The image is multi arch image (WS 2019, WS 2022) built on Windows. To build the images:
The image is a HostProcess container image based on [`mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image`](https://github.com/microsoft/windows-host-process-containers-base-image). One image works on every Windows version that supports HostProcess containers. The released images are listed in the [Docker section](../README.md#docker-implementation) of the readme.
```
DOCKER_REPO=<your repo> make push-all
```
To build your own image, use `docker buildx` on Linux, for example in WSL. The image only copies the binary, so it builds on Linux although it's a Windows image. Put the amd64 binary into an otherwise empty directory as `windows_exporter-<version>-amd64.exe`, the name the CI build uses, and build the image from that directory:
If you don't have a version of `make` on your Windows machine, You can use WSL to build the image with Windows Containers by creating a symbolic link to the docker cli and then override the docker command in the `Makefile`:
On Windows Powershell prompt:
```
New-Item -ItemType SymbolicLink -Path "c:\docker" -Target "C:\Program Files\Docker\Docker\resources\bin\docker.exe"
```
In WSL:
```
DOCKER_REPO=<your repo> DOCKER=/mnt/c/docker make push-all
```bash
GOOS=windows GOARCH=amd64 go build -o output/windows_exporter-dev-amd64.exe ./cmd/windows_exporter
docker buildx build --platform windows/amd64 -f Dockerfile -t <your repository>/windows-exporter:dev --push output
```
## Kubernetes Quick Start
Before beginning you need to deploy the [prometheus operator](https://github.com/prometheus-operator/prometheus-operator) to your cluster. As a quick start, you can use a project like https://github.com/prometheus-operator/kube-prometheus. The export itself doesn't have any dependency on prometheus operator and the exporter image can be used in manual configurations.
Before beginning you need to deploy the [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator) to your cluster. As a quick start, you can use a project like https://github.com/prometheus-operator/kube-prometheus. The export itself doesn't have any dependency on the Prometheus Operator and the exporter image can be used in manual configurations.
### Windows Exporter DaemonSet
This create a deployment on every node. A config map is created for to handle the configuration of the Windows exporter with [configuration file](../README.md#using-a-configuration-file). Adjust the configuration file for the collectors you are interested in.
This creates a pod on every Windows node. A ConfigMap holds the configuration of the Windows exporter with [configuration file](../README.md#using-a-configuration-file). Adjust the configuration file for the collectors you are interested in.
```bash
kubectl apply -f kubernetes/windows-exporter-daemonset.yaml
@@ -45,7 +36,7 @@ kubectl apply -f kubernetes/windows-exporter-daemonset.yaml
> Note: This example manifest deploys the latest bleeding edge image `ghcr.io/prometheus-community/windows-exporter:latest` built from the main branch. You should update this to use a released version which you can find at https://github.com/prometheus-community/windows_exporter/releases
#### Configuring the firewall
The firewall on the node needs to be configured to allow connections on the node: `New-NetFirewallRule -DisplayName 'windows-exporter' -Direction inbound -Profile Any -Action Allow -LocalPort 9182 -Protocol TCP`
The firewall on the node needs to be configured to allow connections on the node: `New-NetFirewallRule -DisplayName 'windows-exporter' -Direction inbound -Profile Any -Action Allow -LocalPort 9182 -Protocol TCP`
You could do this by adding an init container but if you remove the deployment at a later date you will need to remove the firewall rule manually. The following could be added to the `windows-exporter-daemonset.yaml`:
@@ -67,18 +58,18 @@ spec:
Create the [Pod Monitor](https://prometheus-operator.dev/docs/operator/design/#podmonitor) to configure the scraping:
```bash
kubectl apply -f windows-exporter-podmonitor.yaml
kubectl apply -f kubernetes/windows-exporter-podmonitor.yaml
```
### View Metrics
Open Prometheus with
Open Prometheus with
```
kubectl --namespace monitoring port-forward svc/prometheus-k8s 9091:9090
```
Navigate to prometheus UI and add a query to see node cpu (replacing with your ip address)
Navigate to the Prometheus UI and add a query to see the node CPU (replace the IP address with yours)
```
sum by (mode) (irate(windows_cpu_time_total{instance="10.1.0.5:9182"}[5m]))