metrics: golint updates for this or self warning (#16635)
* metrics/*: golint updates for this or self warning * metrics/*: golint updates for this or self warning, updated pr from feedback
This commit is contained in:
parent
2ad511ce09
commit
cd9a1d5b37
@ -65,7 +65,7 @@ type Batch struct {
|
|||||||
Source string `json:"source"`
|
Source string `json:"source"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LibratoClient) PostMetrics(batch Batch) (err error) {
|
func (c *LibratoClient) PostMetrics(batch Batch) (err error) {
|
||||||
var (
|
var (
|
||||||
js []byte
|
js []byte
|
||||||
req *http.Request
|
req *http.Request
|
||||||
@ -85,7 +85,7 @@ func (self *LibratoClient) PostMetrics(batch Batch) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.SetBasicAuth(self.Email, self.Token)
|
req.SetBasicAuth(c.Email, c.Token)
|
||||||
|
|
||||||
if resp, err = http.DefaultClient.Do(req); err != nil {
|
if resp, err = http.DefaultClient.Do(req); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -40,14 +40,14 @@ func Librato(r metrics.Registry, d time.Duration, e string, t string, s string,
|
|||||||
NewReporter(r, d, e, t, s, p, u).Run()
|
NewReporter(r, d, e, t, s, p, u).Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Reporter) Run() {
|
func (rep *Reporter) Run() {
|
||||||
log.Printf("WARNING: This client has been DEPRECATED! It has been moved to https://github.com/mihasya/go-metrics-librato and will be removed from rcrowley/go-metrics on August 5th 2015")
|
log.Printf("WARNING: This client has been DEPRECATED! It has been moved to https://github.com/mihasya/go-metrics-librato and will be removed from rcrowley/go-metrics on August 5th 2015")
|
||||||
ticker := time.Tick(self.Interval)
|
ticker := time.Tick(rep.Interval)
|
||||||
metricsApi := &LibratoClient{self.Email, self.Token}
|
metricsApi := &LibratoClient{rep.Email, rep.Token}
|
||||||
for now := range ticker {
|
for now := range ticker {
|
||||||
var metrics Batch
|
var metrics Batch
|
||||||
var err error
|
var err error
|
||||||
if metrics, err = self.BuildRequest(now, self.Registry); err != nil {
|
if metrics, err = rep.BuildRequest(now, rep.Registry); err != nil {
|
||||||
log.Printf("ERROR constructing librato request body %s", err)
|
log.Printf("ERROR constructing librato request body %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -79,21 +79,21 @@ func sumSquaresTimer(t metrics.Timer) float64 {
|
|||||||
return sumSquares
|
return sumSquares
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot Batch, err error) {
|
func (rep *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot Batch, err error) {
|
||||||
snapshot = Batch{
|
snapshot = Batch{
|
||||||
// coerce timestamps to a stepping fn so that they line up in Librato graphs
|
// coerce timestamps to a stepping fn so that they line up in Librato graphs
|
||||||
MeasureTime: (now.Unix() / self.intervalSec) * self.intervalSec,
|
MeasureTime: (now.Unix() / rep.intervalSec) * rep.intervalSec,
|
||||||
Source: self.Source,
|
Source: rep.Source,
|
||||||
}
|
}
|
||||||
snapshot.Gauges = make([]Measurement, 0)
|
snapshot.Gauges = make([]Measurement, 0)
|
||||||
snapshot.Counters = make([]Measurement, 0)
|
snapshot.Counters = make([]Measurement, 0)
|
||||||
histogramGaugeCount := 1 + len(self.Percentiles)
|
histogramGaugeCount := 1 + len(rep.Percentiles)
|
||||||
r.Each(func(name string, metric interface{}) {
|
r.Each(func(name string, metric interface{}) {
|
||||||
if self.Namespace != "" {
|
if rep.Namespace != "" {
|
||||||
name = fmt.Sprintf("%s.%s", self.Namespace, name)
|
name = fmt.Sprintf("%s.%s", rep.Namespace, name)
|
||||||
}
|
}
|
||||||
measurement := Measurement{}
|
measurement := Measurement{}
|
||||||
measurement[Period] = self.Interval.Seconds()
|
measurement[Period] = rep.Interval.Seconds()
|
||||||
switch m := metric.(type) {
|
switch m := metric.(type) {
|
||||||
case metrics.Counter:
|
case metrics.Counter:
|
||||||
if m.Count() > 0 {
|
if m.Count() > 0 {
|
||||||
@ -125,7 +125,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
measurement[Sum] = float64(s.Sum())
|
measurement[Sum] = float64(s.Sum())
|
||||||
measurement[SumSquares] = sumSquares(s)
|
measurement[SumSquares] = sumSquares(s)
|
||||||
gauges[0] = measurement
|
gauges[0] = measurement
|
||||||
for i, p := range self.Percentiles {
|
for i, p := range rep.Percentiles {
|
||||||
gauges[i+1] = Measurement{
|
gauges[i+1] = Measurement{
|
||||||
Name: fmt.Sprintf("%s.%.2f", measurement[Name], p),
|
Name: fmt.Sprintf("%s.%.2f", measurement[Name], p),
|
||||||
Value: s.Percentile(p),
|
Value: s.Percentile(p),
|
||||||
@ -142,7 +142,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "1min"),
|
Name: fmt.Sprintf("%s.%s", name, "1min"),
|
||||||
Value: m.Rate1(),
|
Value: m.Rate1(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
@ -152,7 +152,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "5min"),
|
Name: fmt.Sprintf("%s.%s", name, "5min"),
|
||||||
Value: m.Rate5(),
|
Value: m.Rate5(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
@ -162,7 +162,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "15min"),
|
Name: fmt.Sprintf("%s.%s", name, "15min"),
|
||||||
Value: m.Rate15(),
|
Value: m.Rate15(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
@ -184,15 +184,15 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Max: float64(m.Max()),
|
Max: float64(m.Max()),
|
||||||
Min: float64(m.Min()),
|
Min: float64(m.Min()),
|
||||||
SumSquares: sumSquaresTimer(m),
|
SumSquares: sumSquaresTimer(m),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: self.TimerAttributes,
|
Attributes: rep.TimerAttributes,
|
||||||
}
|
}
|
||||||
for i, p := range self.Percentiles {
|
for i, p := range rep.Percentiles {
|
||||||
gauges[i+1] = Measurement{
|
gauges[i+1] = Measurement{
|
||||||
Name: fmt.Sprintf("%s.timer.%2.0f", name, p*100),
|
Name: fmt.Sprintf("%s.timer.%2.0f", name, p*100),
|
||||||
Value: m.Percentile(p),
|
Value: m.Percentile(p),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: self.TimerAttributes,
|
Attributes: rep.TimerAttributes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
snapshot.Gauges = append(snapshot.Gauges, gauges...)
|
snapshot.Gauges = append(snapshot.Gauges, gauges...)
|
||||||
@ -200,7 +200,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "rate.1min"),
|
Name: fmt.Sprintf("%s.%s", name, "rate.1min"),
|
||||||
Value: m.Rate1(),
|
Value: m.Rate1(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
@ -210,7 +210,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "rate.5min"),
|
Name: fmt.Sprintf("%s.%s", name, "rate.5min"),
|
||||||
Value: m.Rate5(),
|
Value: m.Rate5(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
@ -220,7 +220,7 @@ func (self *Reporter) BuildRequest(now time.Time, r metrics.Registry) (snapshot
|
|||||||
Measurement{
|
Measurement{
|
||||||
Name: fmt.Sprintf("%s.%s", name, "rate.15min"),
|
Name: fmt.Sprintf("%s.%s", name, "rate.15min"),
|
||||||
Value: m.Rate15(),
|
Value: m.Rate15(),
|
||||||
Period: int64(self.Interval.Seconds()),
|
Period: int64(rep.Interval.Seconds()),
|
||||||
Attributes: map[string]interface{}{
|
Attributes: map[string]interface{}{
|
||||||
DisplayUnitsLong: Operations,
|
DisplayUnitsLong: Operations,
|
||||||
DisplayUnitsShort: OperationsShort,
|
DisplayUnitsShort: OperationsShort,
|
||||||
|
Loading…
Reference in New Issue
Block a user