Skip to content

Commit

Permalink
Address Matt's comments - remove double pointers, use range
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Safar committed May 13, 2019
1 parent c0ea881 commit 956bc40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
8 changes: 2 additions & 6 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ var (
labelNames = []string{"ip", "host"}
)

func init() {
}

func newPingResponseHistogram(buckets []float64) **prometheus.HistogramVec {
pingResponseSeconds := prometheus.NewHistogramVec(
func newPingResponseHistogram(buckets []float64) *prometheus.HistogramVec {
return prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "response_duration_seconds",
Expand All @@ -42,7 +39,6 @@ func newPingResponseHistogram(buckets []float64) **prometheus.HistogramVec {
},
labelNames,
)
return &pingResponseSeconds
}

// SmokepingCollector collects metrics from the pinger.
Expand Down
16 changes: 8 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func init() {
prometheus.MustRegister(version.NewCollector("smokeping_prober"))
}

func parseBuckets(buckets *string) ([]float64, error) {
bucketstrings := strings.Split(*buckets, ",")
func parseBuckets(buckets string) ([]float64, error) {
bucketstrings := strings.Split(buckets, ",")
bucketlist := make([]float64, len(bucketstrings))
for n := 0; n < len(bucketstrings); n++ {
value, err := strconv.ParseFloat(bucketstrings[n], 64)
for i := range bucketstrings {
value, err := strconv.ParseFloat(bucketstrings[i], 64)
if err != nil {
return nil, err
}
bucketlist[n] = value
bucketlist[i] = value
}
return bucketlist, nil
}
Expand Down Expand Up @@ -98,14 +98,14 @@ func main() {
bucketlist = prometheus.ExponentialBuckets(0.00005, 2, 20)
} else {
var err error
bucketlist, err = parseBuckets(buckets)
bucketlist, err = parseBuckets(*buckets)
if err != nil {
log.Errorf("ERROR: %s\n", err.Error())
return
}
}
pingResponseSeconds := newPingResponseHistogram(bucketlist)
prometheus.MustRegister(*pingResponseSeconds)
prometheus.MustRegister(pingResponseSeconds)

pingers := make([]*ping.Pinger, len(*hosts))
for i, host := range *hosts {
Expand All @@ -124,7 +124,7 @@ func main() {
pingers[i] = pinger
}

prometheus.MustRegister(NewSmokepingCollector(&pingers, **pingResponseSeconds))
prometheus.MustRegister(NewSmokepingCollector(&pingers, *pingResponseSeconds))

http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 956bc40

Please sign in to comment.