refactoring

This commit is contained in:
Matej Kramny
2016-05-19 12:20:56 +01:00
parent dfad6f0906
commit 2d62fc7443
9 changed files with 242 additions and 229 deletions

View File

@@ -2,22 +2,24 @@ package cachet
import (
"encoding/json"
"fmt"
"strconv"
)
// SendMetric sends lag metric point
func SendMetric(metricID int, delay int64) {
func (monitor *CachetMonitor) SendMetric(metricID int, delay int64) error {
if metricID <= 0 {
return
return nil
}
jsonBytes, _ := json.Marshal(&map[string]interface{}{
"value": delay,
})
resp, _, err := makeRequest("POST", "/metrics/"+strconv.Itoa(metricID)+"/points", jsonBytes)
resp, _, err := monitor.makeRequest("POST", "/metrics/"+strconv.Itoa(metricID)+"/points", jsonBytes)
if err != nil || resp.StatusCode != 200 {
Logger.Printf("Could not log data point!\n%v\n", err)
return
return fmt.Errorf("Could not log data point!\n%v\n", err)
}
return nil
}