@ -6,6 +6,7 @@ import (
"path"
"strconv"
"strings"
"time"
"golang.org/x/net/context/ctxhttp"
@ -14,7 +15,7 @@ import (
"net/http"
"net/url"
"github.com/grafana/grafana/pkg/components/null "
"github.com/grafana/grafana-plugin-sdk-go/data "
"github.com/grafana/grafana/pkg/infra/httpclient"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
@ -130,32 +131,33 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
return nil , fmt . Errorf ( "request failed, status: %s" , res . Status )
}
var d ata [ ] OpenTsdbResponse
err = json . Unmarshal ( body , & d ata)
var responseD ata [ ] OpenTsdbResponse
err = json . Unmarshal ( body , & responseD ata)
if err != nil {
plog . Info ( "Failed to unmarshal opentsdb response" , "error" , err , "status" , res . Status , "body" , string ( body ) )
return nil , err
}
for _ , val := range data {
series := plugins . DataTimeSeries {
Name : val . Metric ,
}
frames := data . Frames { }
for _ , val := range responseData {
timeVector := make ( [ ] time . Time , 0 , len ( val . DataPoints ) )
values := make ( [ ] float64 , 0 , len ( val . DataPoints ) )
name := val . Metric
for timeString , value := range val . DataPoints {
timestamp , err := strconv . ParseFloa t ( timeString , 64 )
timestamp , err := strconv . ParseIn t ( timeString , 10 , 64 )
if err != nil {
plog . Info ( "Failed to unmarshal opentsdb timestamp" , "timestamp" , timeString )
return nil , err
}
series . Points = append ( series . Points , plugins . DataTimePoint {
null . FloatFrom ( value ) , null . FloatFrom ( timestamp ) ,
} )
timeVector = append ( timeVector , time . Unix ( timestamp , 0 ) . UTC ( ) )
values = append ( values , value )
}
queryRes . Series = append ( queryRes . Series , series )
frames = append ( frames , data . NewFrame ( name ,
data . NewField ( "time" , nil , timeVector ) ,
data . NewField ( "value" , nil , values ) ) )
}
queryRes . Dataframes = plugins . NewDecodedDataFrames ( frames )
queryResults [ "A" ] = queryRes
return queryResults , nil
}