Skip to content

Commit

Permalink
Merge pull request #3 from platinasystems/prometheus-community-master
Browse files Browse the repository at this point in the history
Align the repo
  • Loading branch information
gicamm authored Dec 18, 2024
2 parents 43e0e3d + f44c46c commit d9cf9e6
Show file tree
Hide file tree
Showing 31 changed files with 383 additions and 261 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executors:
# also be updated.
golang:
docker:
- image: cimg/go:1.21
- image: cimg/go:1.23
jobs:
test:
executor: golang
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/container_description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: Push README to Docker Hub
on:
push:
paths:
- "README.md"
- "README-containers.md"
- ".github/workflows/container_description.yml"
branches: [ main, master ]

permissions:
contents: read

jobs:
PushDockerHubReadme:
runs-on: ubuntu-latest
name: Push README to Docker Hub
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Set docker hub repo name
run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV
- name: Push README to Dockerhub
uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1
env:
DOCKER_USER: ${{ secrets.DOCKER_HUB_LOGIN }}
DOCKER_PASS: ${{ secrets.DOCKER_HUB_PASSWORD }}
with:
destination_container_repo: ${{ env.DOCKER_REPO_NAME }}
provider: dockerhub
short_description: ${{ env.DOCKER_REPO_NAME }}
# Empty string results in README-containers.md being pushed if it
# exists. Otherwise, README.md is pushed.
readme_file: ''

PushQuayIoReadme:
runs-on: ubuntu-latest
name: Push README to quay.io
if: github.repository_owner == 'prometheus' || github.repository_owner == 'prometheus-community' # Don't run this workflow on forks.
steps:
- name: git checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Set quay.io org name
run: echo "DOCKER_REPO=$(echo quay.io/${GITHUB_REPOSITORY_OWNER} | tr -d '-')" >> $GITHUB_ENV
- name: Set quay.io repo name
run: echo "DOCKER_REPO_NAME=$(make docker-repo-name)" >> $GITHUB_ENV
- name: Push README to quay.io
uses: christian-korneck/update-container-description-action@d36005551adeaba9698d8d67a296bd16fa91f8e8 # v1
env:
DOCKER_APIKEY: ${{ secrets.QUAY_IO_API_TOKEN }}
with:
destination_container_repo: ${{ env.DOCKER_REPO_NAME }}
provider: quay
# Empty string results in README-containers.md being pushed if it
# exists. Otherwise, README.md is pushed.
readme_file: ''
19 changes: 13 additions & 6 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ on:
- ".golangci.yml"
pull_request:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
golangci:
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
name: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: install Go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Install Go
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version: 1.20.x
go-version: 1.23.x
- name: Install snmp_exporter/generator dependencies
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
if: github.repository == 'prometheus/snmp_exporter'
- name: Lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
version: v1.54.2
args: --verbose
version: v1.60.2
10 changes: 4 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
linters:
enable:
- sloglint

issues:
exclude-rules:
- path: _test.go
linters:
- errcheck

linters-settings:
errcheck:
exclude-functions:
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here,
# .circleci/config.yml should also be updated.
version: 1.21
version: 1.23

repository:
path: github.com/prometheus-community/ipmi_exporter
Expand Down
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
extends: default
ignore: |
ui/react-app/node_modules

rules:
braces:
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## next

## 1.8.0 / 2024-10-23
## 1.9.0 / 2024-10-17

* Bring back aarch64 builds (#186)
* Ignore time parse error in SEL events (#198)
* Don't prepend to already absolute path from config (#199)
* Various dependency updates

## 1.8.0 / 2024-01-23

* Added BMC watchdog collector (#176)
* Added SEL event metrics collector (#179)
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ RUN make
RUN mv ipmi_exporter /

#Copy the ipmi_expoter binary
FROM alpine:3
ARG ARCH="amd64"
ARG OS="linux"
FROM --platform=${OS}/${ARCH} alpine:3
RUN apk --no-cache add freeipmi
LABEL maintainer="The Prometheus Authors <[email protected]>"
WORKDIR /
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
.PHONY: all
all: precheck style unused build test

#DOCKER_ARCHS ?= amd64 arm64
DOCKER_ARCHS ?= amd64
DOCKER_ARCHS ?= amd64 arm64
DOCKER_IMAGE_NAME ?= ipmi-exporter
DOCKER_REPO ?= prometheuscommunity

Expand Down
32 changes: 23 additions & 9 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ endif
GOTEST := $(GO) test
GOTEST_DIR :=
ifneq ($(CIRCLE_JOB),)
ifneq ($(shell command -v gotestsum > /dev/null),)
ifneq ($(shell command -v gotestsum 2> /dev/null),)
GOTEST_DIR := test-results
GOTEST := gotestsum --junitfile $(GOTEST_DIR)/unit-tests.xml --
endif
endif

PROMU_VERSION ?= 0.15.0
PROMU_VERSION ?= 0.17.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz

SKIP_GOLANGCI_LINT :=
GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.54.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
GOLANGCI_LINT_VERSION ?= v1.60.2
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386 arm64))
# If we're in CI and there is an Actions file, that means the linter
# is being run in Actions, so we don't need to run it here.
ifneq (,$(SKIP_GOLANGCI_LINT))
Expand Down Expand Up @@ -169,16 +169,20 @@ common-vet:
common-lint: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint"
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
# Otherwise staticcheck might fail randomly for some reason not yet explained.
$(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
endif

.PHONY: common-lint-fix
common-lint-fix: $(GOLANGCI_LINT)
ifdef GOLANGCI_LINT
@echo ">> running golangci-lint fix"
$(GOLANGCI_LINT) run --fix $(GOLANGCI_LINT_OPTS) $(pkgs)
endif

.PHONY: common-yamllint
common-yamllint:
@echo ">> running yamllint on all YAML files in the repository"
ifeq (, $(shell command -v yamllint > /dev/null))
ifeq (, $(shell command -v yamllint 2> /dev/null))
@echo "yamllint not installed so skipping"
else
yamllint .
Expand All @@ -204,6 +208,10 @@ common-tarball: promu
@echo ">> building release tarball"
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

.PHONY: common-docker-repo-name
common-docker-repo-name:
@echo "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"

.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
common-docker: $(BUILD_DOCKER_ARCHS)
$(BUILD_DOCKER_ARCHS): common-docker-%:
Expand Down Expand Up @@ -267,3 +275,9 @@ $(1)_precheck:
exit 1; \
fi
endef

govulncheck: install-govulncheck
govulncheck ./...

install-govulncheck:
command -v govulncheck > /dev/null || go install golang.org/x/vuln/cmd/govulncheck@latest
80 changes: 28 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ This is an IPMI exporter for [Prometheus][prometheus].

It supports both the regular `/metrics` endpoint, exposing metrics from the
host that the exporter is running on, as well as an `/ipmi` endpoint that
supports IPMI over RMCP - one exporter running on one host can be used to
monitor a large number of IPMI interfaces by passing the `target` parameter to
a scrape.
supports IPMI over RMCP, implementing the multi-target exporter pattern. If you
plan to use the latter, please read the guide [Understanding and using the
multi-target exporter pattern][multi-target] to get the general idea about the
configuration.

[multi-target]: https://prometheus.io/docs/guides/multi-target-exporter/

The exporter relies on tools from the [FreeIPMI][freeipmi] suite for the actual
IPMI implementation.
Expand All @@ -28,6 +31,12 @@ For Kubernets, you can use the community-maintained [Helm chart][helm].

[helm]: https://github.com/prometheus-community/helm-charts/tree/main/charts/prometheus-ipmi-exporter "IPMI exporter Helm chart in the helm-charts Github repo"

Pre-built container images are available on [dockerhub][dockerhub] and
[quay.io][quay.io].

[dockerhub]: https://hub.docker.com/r/prometheuscommunity/ipmi-exporter
[quay.io]: https://quay.io/repository/prometheuscommunity/ipmi-exporter

### Building from source

You need a Go development environment. Then, simply run `make` to build the
Expand All @@ -40,23 +49,16 @@ This uses the common prometheus tooling to build and run some tests.
Alternatively, you can use the standard Go tooling, which will install the
executable in `$GOPATH/bin`:

go get github.com/prometheus-community/ipmi_exporter
go install github.com/prometheus-community/ipmi_exporter@latest

### Building a Docker container
### Building a container image

You can build a Docker container with the included `docker` make target:
You can build a container image with the included `docker` make target:

make promu
promu crossbuild -p linux/amd64
promu crossbuild -p linux/amd64 -p linux/arm64
make docker

This will not even require Go tooling on the host. See the included [docker
compose example](docker-compose.yml) for how to use the resulting container.

### Building a RPM Package

See [how to build a RPM package](contrib/rpm/README.md).

## Running

A minimal invocation looks like this:
Expand All @@ -83,44 +85,12 @@ installed:
- `ipmi-sel`
- `ipmi-chassis`

### Running as unprivileged user

If you are running the exporter as unprivileged user, but need to execute the
FreeIPMI tools as root, you can do the following:

1. Add sudoers files to permit the following commands
```
ipmi-exporter ALL = NOPASSWD: /usr/sbin/ipmimonitoring,\
/usr/sbin/ipmi-sensors,\
/usr/sbin/ipmi-dcmi,\
/usr/sbin/ipmi-raw,\
/usr/sbin/bmc-info,\
/usr/sbin/ipmi-chassis,\
/usr/sbin/ipmi-sel
```
2. In your module config, override the collector command with `sudo` for
every collector you are using and add the actual command as custom
argument. Example for the "ipmi" collector:
```yaml
collector_cmd:
ipmi: sudo
custom_args:
ipmi:
- "ipmimonitoring"
```
See the last module in the [example config](ipmi_remote.yml).
### Running in Docker
**NOTE:** you should only use Docker for remote metrics.
See [Building a Docker container](#building-a-docker-container) and the example
`docker-compose.yml`. Edit the `ipmi_remote.yml` file to configure IPMI
credentials, then run with:
sudo docker-compose up -d
By default, the server will bind on `0.0.0.0:9290`.
When running a container image, make sure to:

- set `config.file` to where the config file is mounted
- expose the default port (9290) or set `web.listen-address` accordingly

**NOTE:** you should only use containers for collecting remote metrics.

## Configuration

Expand All @@ -142,3 +112,9 @@ using the `--web.config.file` parameter. The format of the file is described

For a description of the metrics that this exporter provides, see the
[metrics](docs/metrics.md) document.

## Privileges

Collecting host-local IPMI metrics requires root privileges. See
[privileges](docs/privileges.md) document for how to avoid running the exporter
as root.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.0
1.9.0
10 changes: 6 additions & 4 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"path"
"time"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
defer func() {
duration := time.Since(start).Seconds()
level.Debug(logger).Log("msg", "Scrape duration", "target", targetName(c.target), "duration", duration)
logger.Debug("Scrape duration", "target", targetName(c.target), "duration", duration)
ch <- prometheus.MustNewConstMetric(
durationDesc,
prometheus.GaugeValue,
Expand All @@ -97,9 +96,12 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {

for _, collector := range config.GetCollectors() {
var up int
level.Debug(logger).Log("msg", "Running collector", "target", target.host, "collector", collector.Name())
logger.Debug("Running collector", "target", target.host, "collector", collector.Name())

fqcmd := path.Join(*executablesPath, collector.Cmd())
fqcmd := collector.Cmd()
if !path.IsAbs(fqcmd) {
fqcmd = path.Join(*executablesPath, collector.Cmd())
}
args := collector.Args()
cfg := config.GetFreeipmiConfig()

Expand Down
Loading

0 comments on commit d9cf9e6

Please sign in to comment.