Skip to content

Commit

Permalink
add multicast/broadcast and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
tombokombo committed Mar 2, 2021
1 parent 936d519 commit 3868bbf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM golang:alpine as builder

ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
GOPATH=/build

WORKDIR /build

COPY . .


RUN apk add git && go get -d -v || true
RUN go build -o cisco_exporter .

FROM scratch

COPY --from=builder /build/cisco_exporter /

EXPOSE 9362

ENTRYPOINT ["/cisco_exporter"]
3 changes: 3 additions & 0 deletions interfaces/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ type Interface struct {
InputBytes float64
OutputBytes float64

InputBroadcast float64
InputMulticast float64

Speed string
}
26 changes: 17 additions & 9 deletions interfaces/interface_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ import (
const prefix string = "cisco_interface_"

var (
receiveBytesDesc *prometheus.Desc
receiveErrorsDesc *prometheus.Desc
receiveDropsDesc *prometheus.Desc
transmitBytesDesc *prometheus.Desc
transmitErrorsDesc *prometheus.Desc
transmitDropsDesc *prometheus.Desc
adminStatusDesc *prometheus.Desc
operStatusDesc *prometheus.Desc
errorStatusDesc *prometheus.Desc
receiveBytesDesc *prometheus.Desc
receiveErrorsDesc *prometheus.Desc
receiveDropsDesc *prometheus.Desc
receiveBroadcastDesc *prometheus.Desc
receiveMulticastDesc *prometheus.Desc
transmitBytesDesc *prometheus.Desc
transmitErrorsDesc *prometheus.Desc
transmitDropsDesc *prometheus.Desc
adminStatusDesc *prometheus.Desc
operStatusDesc *prometheus.Desc
errorStatusDesc *prometheus.Desc
)

func init() {
l := []string{"target", "name", "description", "mac", "speed"}
receiveBytesDesc = prometheus.NewDesc(prefix+"receive_bytes", "Received data in bytes", l, nil)
receiveErrorsDesc = prometheus.NewDesc(prefix+"receive_errors", "Number of errors caused by incoming packets", l, nil)
receiveDropsDesc = prometheus.NewDesc(prefix+"receive_drops", "Number of dropped incoming packets", l, nil)
receiveBroadcastDesc = prometheus.NewDesc(prefix+"receive_broadcast", "Received broadcast packets", l, nil)
receiveMulticastDesc = prometheus.NewDesc(prefix+"receive_multicast", "Received multicast packets", l, nil)
transmitBytesDesc = prometheus.NewDesc(prefix+"transmit_bytes", "Transmitted data in bytes", l, nil)
transmitErrorsDesc = prometheus.NewDesc(prefix+"transmit_errors", "Number of errors caused by outgoing packets", l, nil)
transmitDropsDesc = prometheus.NewDesc(prefix+"transmit_drops", "Number of dropped outgoing packets", l, nil)
Expand All @@ -49,6 +53,8 @@ func (*interfaceCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- receiveBytesDesc
ch <- receiveErrorsDesc
ch <- receiveDropsDesc
ch <- receiveBroadcastDesc
ch <- receiveMulticastDesc
ch <- transmitBytesDesc
ch <- transmitDropsDesc
ch <- transmitErrorsDesc
Expand Down Expand Up @@ -114,6 +120,8 @@ func (c *interfaceCollector) Collect(client *rpc.Client, ch chan<- prometheus.Me
ch <- prometheus.MustNewConstMetric(transmitBytesDesc, prometheus.GaugeValue, item.OutputBytes, l...)
ch <- prometheus.MustNewConstMetric(transmitErrorsDesc, prometheus.GaugeValue, item.OutputErrors, l...)
ch <- prometheus.MustNewConstMetric(transmitDropsDesc, prometheus.GaugeValue, item.OutputDrops, l...)
ch <- prometheus.MustNewConstMetric(receiveBroadcastDesc, prometheus.GaugeValue, item.InputBroadcast, l...)
ch <- prometheus.MustNewConstMetric(receiveMulticastDesc, prometheus.GaugeValue, item.InputMulticast, l...)
ch <- prometheus.MustNewConstMetric(adminStatusDesc, prometheus.GaugeValue, float64(adminStatus), l...)
ch <- prometheus.MustNewConstMetric(operStatusDesc, prometheus.GaugeValue, float64(operStatus), l...)
ch <- prometheus.MustNewConstMetric(errorStatusDesc, prometheus.GaugeValue, float64(errorStatus), l...)
Expand Down
6 changes: 6 additions & 0 deletions interfaces/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (c *interfaceCollector) Parse(ostype string, output string) ([]Interface, e
adminStatusNXOSRegexp := regexp.MustCompile(`^\S+ is (up|down)(?:\s|,)?(\(Administratively down\))?.*$`)
descRegexp := regexp.MustCompile(`^\s+Description: (.*)$`)
dropsRegexp := regexp.MustCompile(`^\s+Input queue: \d+\/\d+\/(\d+)\/\d+ .+ Total output drops: (\d+)$`)
multicastRegexp := regexp.MustCompile(`(\d+)\s(IP\s)?multicast(s)?`)
broadcastRegexp := regexp.MustCompile(`(\d+)\sbroadcasts`)
inputBytesRegexp := regexp.MustCompile(`^\s+\d+ (?:packets input,|input packets)\s+(\d+) bytes.*$`)
outputBytesRegexp := regexp.MustCompile(`^\s+\d+ (?:packets output,|output packets)\s+(\d+) bytes.*$`)
inputErrorsRegexp := regexp.MustCompile(`^\s+(\d+) input error(?:s,)? .*$`)
Expand Down Expand Up @@ -78,6 +80,10 @@ func (c *interfaceCollector) Parse(ostype string, output string) ([]Interface, e
current.OutputErrors = util.Str2float64(matches[1])
} else if matches := speedRegexp.FindStringSubmatch(line); matches != nil {
current.Speed = matches[2] + " " + matches[3]
} else if matches := multicastRegexp.FindStringSubmatch(line); matches != nil {
current.InputMulticast = util.Str2float64(matches[2])
} else if matches := broadcastRegexp.FindStringSubmatch(line); matches != nil {
current.InputBroadcast = util.Str2float64(matches[1])
}
}
return append(items, current), nil
Expand Down

0 comments on commit 3868bbf

Please sign in to comment.