forked from czerwonk/junos_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request czerwonk#97 from R4scal/master
Add support for real-time performance monitoring (RPM)
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package rpm | ||
|
||
import ( | ||
"github.com/czerwonk/junos_exporter/collector" | ||
"github.com/czerwonk/junos_exporter/rpc" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
const prefix string = "junos_rpm_probe_results_" | ||
|
||
var ( | ||
currRTTMinDesc *prometheus.Desc | ||
currRTTMaxDesc *prometheus.Desc | ||
currRTTAvgDesc *prometheus.Desc | ||
currRTTJitterDesc *prometheus.Desc | ||
currRTTStddevDesc *prometheus.Desc | ||
currRTTSumDesc *prometheus.Desc | ||
totalSentDesc *prometheus.Desc | ||
totalReceivedDesc *prometheus.Desc | ||
) | ||
|
||
func init() { | ||
l := []string{"target", "owner", "name", "address", "type", "interface"} | ||
totalSentDesc = prometheus.NewDesc(prefix+"sent_total", "Number of probes sent within the current test", l, nil) | ||
totalReceivedDesc = prometheus.NewDesc(prefix+"received_total", "Number of probe responses received within the current test", l, nil) | ||
currRTTMinDesc = prometheus.NewDesc(prefix+"rtt_min_current", "Minimum RTT for the most recently completed test, in microseconds", l, nil) | ||
currRTTMaxDesc = prometheus.NewDesc(prefix+"rtt_max_current", "Maximum RTT for the most recently completed test, in microseconds", l, nil) | ||
currRTTAvgDesc = prometheus.NewDesc(prefix+"rtt_avg_current", "Average RTT for the most recently completed test, in microseconds", l, nil) | ||
currRTTJitterDesc = prometheus.NewDesc(prefix+"rtt_jitter_current", "Peak-to-peak difference, in microseconds", l, nil) | ||
currRTTStddevDesc = prometheus.NewDesc(prefix+"rtt_stddev_current", "Standard deviation, in microseconds", l, nil) | ||
currRTTSumDesc = prometheus.NewDesc(prefix+"rtt_sum_current", "Statistical sum", l, nil) | ||
} | ||
|
||
type rpmCollector struct{} | ||
|
||
// NewCollector creates a new collector | ||
func NewCollector() collector.RPCCollector { | ||
return &rpmCollector{} | ||
} | ||
|
||
// Name returns the name of the collector | ||
func (*rpmCollector) Name() string { | ||
return "RPM" | ||
} | ||
|
||
// Describe describes the metrics | ||
func (*rpmCollector) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- totalSentDesc | ||
ch <- totalReceivedDesc | ||
ch <- currRTTMinDesc | ||
ch <- currRTTMaxDesc | ||
ch <- currRTTAvgDesc | ||
ch <- currRTTJitterDesc | ||
ch <- currRTTStddevDesc | ||
ch <- currRTTSumDesc | ||
} | ||
|
||
// Collect collects metrics from JunOS | ||
func (c *rpmCollector) Collect(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error { | ||
err := c.collect(client, ch, labelValues) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *rpmCollector) collect(client *rpc.Client, ch chan<- prometheus.Metric, labelValues []string) error { | ||
var x = RPMRPC{} | ||
|
||
err := client.RunCommandAndParse("show services rpm probe-results", &x) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, probe := range x.Results.Probes { | ||
c.collectForProbe(probe, ch, labelValues) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (c *rpmCollector) collectForProbe(p RPMProbe, ch chan<- prometheus.Metric, labelValues []string) { | ||
l := append(labelValues, []string{p.Owner, p.Name, p.Address, p.Type, p.Interface}...) | ||
|
||
ch <- prometheus.MustNewConstMetric(totalSentDesc, prometheus.GaugeValue, float64(p.Global.Results.Sent), l...) | ||
ch <- prometheus.MustNewConstMetric(totalReceivedDesc, prometheus.GaugeValue, float64(p.Global.Results.Responses), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTMinDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Min), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTMaxDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Max), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTAvgDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Avg), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTJitterDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Jitter), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTStddevDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Stddev), l...) | ||
ch <- prometheus.MustNewConstMetric(currRTTSumDesc, prometheus.GaugeValue, float64(p.Last.Results.RTT.Summary.Sum), l...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rpm | ||
|
||
type RPMRPC struct { | ||
Results struct { | ||
Probes []RPMProbe `xml:"probe-test-results"` | ||
} `xml:"probe-results"` | ||
} | ||
|
||
type RPMProbe struct { | ||
Owner string `xml:"owner"` | ||
Name string `xml:"test-name"` | ||
Address string `xml:"target-address"` | ||
Type string `xml:"probe-type"` | ||
Interface string `xml:"destination-interface"` | ||
Size int64 `xml:"test-size"` | ||
Last struct { | ||
Results RPMGenericResults `xml:"probe-test-generic-results"` | ||
} `xml:"probe-last-test-results"` | ||
Global struct { | ||
Results RPMGenericResults `xml:"probe-test-generic-results"` | ||
} `xml:"probe-test-global-results"` | ||
} | ||
|
||
type RPMGenericResults struct { | ||
Scope string `xml:"results-scope"` | ||
Sent int64 `xml:"probes-sent"` | ||
Responses int64 `xml:"probe-responses"` | ||
LossPercent float64 `xml:"loss-percentage"` | ||
RTT struct { | ||
Summary struct { | ||
Samples int64 `xml:"samples"` | ||
Min int64 `xml:"min-delay"` | ||
Max int64 `xml:"max-delay"` | ||
Avg int64 `xml:"avg-delay"` | ||
Jitter int64 `xml:"jitter-delay"` | ||
Stddev int64 `xml:"stddev-delay"` | ||
Sum int64 `xml:"sum-delay"` | ||
} `xml:"probe-summary-results"` | ||
} `xml:"probe-test-rtt"` | ||
} |