Add a simple Dockerfile. Add retry for hddtemp connection. Tolerate devices with a unit of '*', treat them as having a temperature of -1.
parent
cdeb6e943c
commit
4f6d95f55f
|
@ -0,0 +1,19 @@
|
|||
# Start from a Debian image with the latest version of Go installed
|
||||
# and a workspace (GOPATH) configured at /go.
|
||||
FROM golang
|
||||
|
||||
# Copy the local package files to the container's workspace.
|
||||
ADD sensor-exporter /go/src/github.com/ncabatoff/sensor-exporter
|
||||
|
||||
# Build the outyet command inside the container.
|
||||
# (You may fetch or manage dependencies here,
|
||||
# either manually or with a tool like "godep".)
|
||||
RUN apt-get update
|
||||
RUN apt-get --yes install libsensors4-dev
|
||||
RUN go get github.com/ncabatoff/gosensors github.com/prometheus/client_golang/prometheus && go install github.com/ncabatoff/sensor-exporter
|
||||
|
||||
# Run the outyet command by default when the container starts.
|
||||
ENTRYPOINT /go/bin/sensor-exporter
|
||||
|
||||
# Document that the service listens on port 9255.
|
||||
EXPOSE 9255
|
|
@ -163,6 +163,12 @@ func (h *HddCollector) Init() error {
|
|||
}
|
||||
|
||||
func (h *HddCollector) readTempsFromConn() (string, error) {
|
||||
if h.conn == nil {
|
||||
if err := h.Init(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
_, err := io.Copy(&h.buf, h.conn)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Error reading from hddtemp socket: %v", err)
|
||||
|
@ -198,11 +204,16 @@ func parseHddTemp(s string) (HddTemperature, error) {
|
|||
if len(pieces) != 4 {
|
||||
return HddTemperature{}, fmt.Errorf("error parsing item from hddtemp, expected 4 tokens: %s", s)
|
||||
}
|
||||
if pieces[3] != "C" {
|
||||
dev, id, temp, unit := pieces[0], pieces[1], pieces[2], pieces[3]
|
||||
|
||||
if unit == "*" {
|
||||
return HddTemperature{Device: dev, Id: id, TemperatureCelsius: -1}, nil
|
||||
}
|
||||
|
||||
if unit != "C" {
|
||||
return HddTemperature{}, fmt.Errorf("error parsing item from hddtemp, I only speak Celsius", s)
|
||||
}
|
||||
|
||||
dev, id, temp := pieces[0], pieces[1], pieces[2]
|
||||
ftemp, err := strconv.ParseFloat(temp, 64)
|
||||
if err != nil {
|
||||
return HddTemperature{}, fmt.Errorf("Error parsing temperature as float: %s", temp)
|
||||
|
|
Loading…
Reference in New Issue