Skip to content

Commit

Permalink
Add sel_events_log metric
Browse files Browse the repository at this point in the history
Resolves: PCC-5375
  • Loading branch information
alexlocastro authored and gicamm committed Dec 18, 2024
1 parent 1ae273d commit f807ed9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
37 changes: 32 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
FROM ubuntu:16.04 as buildstage

# Install git, curl and build required packages
RUN apt-get update -y && apt-get install -y git curl make gcc tar rsync wget

# Download Go and install it to /usr/local/go
RUN curl -s https://storage.googleapis.com/golang/go1.19.10.linux-amd64.tar.gz | tar -v -C /usr/local -xz
ENV PATH $PATH:/usr/local/go/bin

# Enable go modules
ENV GO111MODULE on
RUN go env -w GOPRIVATE=github.com/platinasystems/*

# Enable access to private github repositories
# Token must be passed with --build-arg GITHUB_TOKEN=<value>
ARG GITHUB_TOKEN
RUN git config --global url."https://$GITHUB_TOKEN:[email protected]/".insteadOf "https://github.com/"

# Populate the module cache based on the go.{mod,sum} files for ipmi_exporter
COPY go.mod go.mod
RUN go mod download

#Build ipmi_exporter
WORKDIR /$GOPATH/src/github.com/platinasystems/ipmi_exporter
COPY . .
RUN make
RUN mv ipmi_exporter /

#Copy the ipmi_expoter binary
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]>"

ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/ipmi_exporter /bin/ipmi_exporter
WORKDIR /
COPY --from=buildstage /ipmi_exporter /

EXPOSE 9290
USER nobody
ENTRYPOINT [ "/bin/ipmi_exporter" ]
ENTRYPOINT [ "/ipmi_exporter"]
21 changes: 21 additions & 0 deletions collector_sel_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ var (
[]string{"name"},
nil,
)
selEventsLog = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "sel_events", "log"),
"log entries",
[]string{"log"},
nil,
)
)

type SELEventsCollector struct{}
Expand Down Expand Up @@ -145,5 +151,20 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
name,
)
}

log, err := freeipmi.GetStringSELEvents(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL events logs", "target", targetName(target.host), "error", err)

Check failure on line 157 in collector_sel_events.go

View workflow job for this annotation

GitHub Actions / lint

undefined: level
return 0, err
}
level.Info(logger).Log(log)

Check failure on line 160 in collector_sel_events.go

View workflow job for this annotation

GitHub Actions / lint

undefined: level (typecheck)

ch <- prometheus.MustNewConstMetric(
selEventsLog,
prometheus.GaugeValue,
1,
log,
)

return 1, nil
}
8 changes: 8 additions & 0 deletions freeipmi/freeipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,11 @@ func GetSELEvents(ipmiOutput Result) ([]SELEventData, error) {
}
return events, nil
}

func GetStringSELEvents(ipmiOutput Result) (string, error) {
if ipmiOutput.err != nil {
return "", fmt.Errorf("%s: %s", ipmiOutput.err, ipmiOutput.output)
}
events := string(ipmiOutput.output)
return events, nil
}
4 changes: 4 additions & 0 deletions jenkins.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
projectName=ipmi-exporter
version=stable
language=go
dockerfilePath=

0 comments on commit f807ed9

Please sign in to comment.