Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
czerwonk authored Apr 2, 2020
2 parents 76e029b + 5b7578d commit 6cdb7b8
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 6 deletions.
68 changes: 62 additions & 6 deletions system/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var (
mbufAndClustersDeniedDesc *prometheus.Desc
ioInitDesc *prometheus.Desc

hardwareInfoDesc *prometheus.Desc

// regex
regex1Ints *regexp.Regexp = regexp.MustCompile(`^(\d+).*`)
regex2Ints *regexp.Regexp = regexp.MustCompile(`^(\d+)\/(\d+).*`)
Expand Down Expand Up @@ -89,6 +91,9 @@ func init() {

ioInitDesc = prometheus.NewDesc(prefix+"io_requests_count", "Number of I/O requests initiated", l, nil)
mbufAndClustersDeniedDesc = prometheus.NewDesc(prefix+"mbuf_and_clusters_denied_count", "Number of mbuf+cluster requests denied", l, nil)

l = append(l, "model", "os", "os_version", "serial", "hostname", "alias", "slot_id", "state", "satellite")
hardwareInfoDesc = prometheus.NewDesc(prefix+"hardware_info", "Hardware information about this system", l, nil)
}

// NewCollector creates a new collector
Expand Down Expand Up @@ -125,6 +130,7 @@ func (*systemCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- sfbufsDeniedDesc
ch <- sfbufsDelayedDesc
ch <- ioInitDesc
ch <- hardwareInfoDesc
}

// Collect collects metrics from JunOS
Expand All @@ -143,12 +149,15 @@ func (c *systemCollector) Collect(client *rpc.Client, ch chan<- prometheus.Metri

func (c *systemCollector) CollectSystem(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error {
var (
r *BuffersRPC
l []string
err error
lines []string
matches [][]string
i int
r *BuffersRPC
r2 *SystemInformationRPC
r3 *SatelliteChassisRPC
l []string
err error
lines []string
matches [][]string
i int
hardwareLabels = make([]string, 0)
)

r = new(BuffersRPC)
Expand Down Expand Up @@ -263,6 +272,53 @@ func (c *systemCollector) CollectSystem(client *rpc.Client, ch chan<- prometheus
if len(matches) >= 1 {
r.MemoryStatistics.IoInit, _ = strconv.Atoi(matches[0][1])
}

}

// system information
r2 = new(SystemInformationRPC)
err = client.RunCommandAndParse("show system information", r2)
if err != nil {
return err
}

// create LabelSet (target, "model", "os", "os_version", "serial", "hostname", "alias", "slot_id", "state", "satellite")
hardwareLabels = append(labelValues,
r2.SysInfo.Model,
r2.SysInfo.OS,
r2.SysInfo.OSVersion,
r2.SysInfo.Serial,
r2.SysInfo.Hostname,
"", "", "", "")

ch <- prometheus.MustNewConstMetric(hardwareInfoDesc, prometheus.GaugeValue, float64(1), hardwareLabels...)

// gather satellite data
if client.Satellite {

// system information of satellites
r3 = new(SatelliteChassisRPC)
err = client.RunCommandAndParse("show chassis satellite detail", r3)
// there are various error messages when satellite is not enabled; thus here we just ignore the error and continue
if err == nil {
for i = range r3.SatelliteInfo.Satellite {
// reset labels
hardwareLabels = make([]string, 0)
// create LabelSet (target, "model", "os", "os_version", "serial", "hostname", "alias", "slot_id", "state", "satellite")
hardwareLabels = append(labelValues,
r3.SatelliteInfo.Satellite[i].Model,
"",
"",
r3.SatelliteInfo.Satellite[i].Serial,
"",
r3.SatelliteInfo.Satellite[i].Alias,
strconv.Itoa(r3.SatelliteInfo.Satellite[i].SlotId),
r3.SatelliteInfo.Satellite[i].State,
"true")

ch <- prometheus.MustNewConstMetric(hardwareInfoDesc, prometheus.GaugeValue, float64(1), hardwareLabels...)
}
}
}

ch <- prometheus.MustNewConstMetric(mbufsCurrentDesc, prometheus.GaugeValue, float64(r.MemoryStatistics.MbufsCurrent), labelValues...)
Expand Down
22 changes: 22 additions & 0 deletions system/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,25 @@ type BuffersRPC struct {
IoInit int `xml:"io-initiated"`
} `xml:"memory-statistics"`
}

type SystemInformationRPC struct {
SysInfo struct {
Model string `xml:"hardware-model"`
OS string `xml:"os-name"`
OSVersion string `xml:"os-version"`
Serial string `xml:"serial-number"`
Hostname string `xml:"host-name"`
} `xml:"system-information"`
}

type SatelliteChassisRPC struct {
SatelliteInfo struct {
Satellite []struct {
Alias string `xml:"satellite-alias"`
SlotId int `xml:"slot-id"`
State string `xml:"operation-state"`
Model string `xml:"product-model"`
Serial string `xml:"serial-number"`
} `xml:"satellite"`
} `xml:"satellite-information"`
}

0 comments on commit 6cdb7b8

Please sign in to comment.