From f807ed9557789745367a3851712fcf5f53875199 Mon Sep 17 00:00:00 2001 From: alexlocastro Date: Tue, 20 Feb 2024 13:30:04 +0100 Subject: [PATCH] Add sel_events_log metric Resolves: PCC-5375 --- Dockerfile | 37 ++++++++++++++++++++++++++++++++----- collector_sel_events.go | 21 +++++++++++++++++++++ freeipmi/freeipmi.go | 8 ++++++++ jenkins.properties | 4 ++++ 4 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 jenkins.properties diff --git a/Dockerfile b/Dockerfile index 2dd6c70..79e4bc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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= +ARG GITHUB_TOKEN +RUN git config --global url."https://$GITHUB_TOKEN:x-oauth-basic@github.com/".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 " - -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"] diff --git a/collector_sel_events.go b/collector_sel_events.go index cb777f6..826fcdd 100644 --- a/collector_sel_events.go +++ b/collector_sel_events.go @@ -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{} @@ -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) + return 0, err + } + level.Info(logger).Log(log) + + ch <- prometheus.MustNewConstMetric( + selEventsLog, + prometheus.GaugeValue, + 1, + log, + ) + return 1, nil } diff --git a/freeipmi/freeipmi.go b/freeipmi/freeipmi.go index cc2987d..9792583 100644 --- a/freeipmi/freeipmi.go +++ b/freeipmi/freeipmi.go @@ -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 +} diff --git a/jenkins.properties b/jenkins.properties new file mode 100644 index 0000000..4909f1b --- /dev/null +++ b/jenkins.properties @@ -0,0 +1,4 @@ +projectName=ipmi-exporter +version=stable +language=go +dockerfilePath= \ No newline at end of file