Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
d4bc92b2
Commit
d4bc92b2
authored
Nov 02, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(tsdb): default tsdb httpclient
parent
9b28bf25
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
81 deletions
+81
-81
pkg/tsdb/graphite/graphite.go
+1
-10
pkg/tsdb/http.go
+29
-0
pkg/tsdb/influxdb/influxdb.go
+1
-10
pkg/tsdb/opentsdb/opentsdb.go
+49
-58
pkg/tsdb/prometheus/prometheus.go
+1
-3
No files found.
pkg/tsdb/graphite/graphite.go
View file @
d4bc92b2
...
@@ -2,7 +2,6 @@ package graphite
...
@@ -2,7 +2,6 @@ package graphite
import
(
import
(
"context"
"context"
"crypto/tls"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
...
@@ -10,7 +9,6 @@ import (
...
@@ -10,7 +9,6 @@ import (
"net/url"
"net/url"
"path"
"path"
"strings"
"strings"
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
...
@@ -36,14 +34,7 @@ func init() {
...
@@ -36,14 +34,7 @@ func init() {
glog
=
log
.
New
(
"tsdb.graphite"
)
glog
=
log
.
New
(
"tsdb.graphite"
)
tsdb
.
RegisterExecutor
(
"graphite"
,
NewGraphiteExecutor
)
tsdb
.
RegisterExecutor
(
"graphite"
,
NewGraphiteExecutor
)
tr
:=
&
http
.
Transport
{
HttpClient
=
tsdb
.
GetDefaultClient
()
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
}
HttpClient
=
&
http
.
Client
{
Timeout
:
time
.
Duration
(
15
*
time
.
Second
),
Transport
:
tr
,
}
}
}
func
(
e
*
GraphiteExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
context
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
func
(
e
*
GraphiteExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
context
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
...
...
pkg/tsdb/http.go
0 → 100644
View file @
d4bc92b2
package
tsdb
import
(
"crypto/tls"
"net"
"net/http"
"time"
)
func
GetDefaultClient
()
*
http
.
Client
{
tr
:=
&
http
.
Transport
{
Proxy
:
http
.
ProxyFromEnvironment
,
DialContext
:
(
&
net
.
Dialer
{
Timeout
:
30
*
time
.
Second
,
KeepAlive
:
30
*
time
.
Second
,
})
.
DialContext
,
MaxIdleConns
:
100
,
IdleConnTimeout
:
90
*
time
.
Second
,
TLSHandshakeTimeout
:
10
*
time
.
Second
,
ExpectContinueTimeout
:
1
*
time
.
Second
,
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
}
return
&
http
.
Client
{
Timeout
:
time
.
Duration
(
30
*
time
.
Second
),
Transport
:
tr
,
}
}
pkg/tsdb/influxdb/influxdb.go
View file @
d4bc92b2
...
@@ -2,13 +2,11 @@ package influxdb
...
@@ -2,13 +2,11 @@ package influxdb
import
(
import
(
"context"
"context"
"crypto/tls"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"net/http"
"net/http"
"net/url"
"net/url"
"path"
"path"
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
...
@@ -41,14 +39,7 @@ func init() {
...
@@ -41,14 +39,7 @@ func init() {
glog
=
log
.
New
(
"tsdb.influxdb"
)
glog
=
log
.
New
(
"tsdb.influxdb"
)
tsdb
.
RegisterExecutor
(
"influxdb"
,
NewInfluxDBExecutor
)
tsdb
.
RegisterExecutor
(
"influxdb"
,
NewInfluxDBExecutor
)
tr
:=
&
http
.
Transport
{
HttpClient
=
tsdb
.
GetDefaultClient
()
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
}
HttpClient
=
&
http
.
Client
{
Timeout
:
time
.
Duration
(
15
*
time
.
Second
),
Transport
:
tr
,
}
}
}
func
(
e
*
InfluxDBExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
context
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
func
(
e
*
InfluxDBExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
context
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
...
...
pkg/tsdb/opentsdb/opentsdb.go
View file @
d4bc92b2
...
@@ -2,19 +2,17 @@ package opentsdb
...
@@ -2,19 +2,17 @@ package opentsdb
import
(
import
(
"context"
"context"
"crypto/tls"
"fmt"
"fmt"
"path"
"path"
"strconv"
"strconv"
"strings"
"strings"
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/net/context/ctxhttp"
"encoding/json"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"net/url"
"net/url"
"encoding/json"
"gopkg.in/guregu/null.v3"
"gopkg.in/guregu/null.v3"
...
@@ -40,14 +38,7 @@ func init() {
...
@@ -40,14 +38,7 @@ func init() {
plog
=
log
.
New
(
"tsdb.opentsdb"
)
plog
=
log
.
New
(
"tsdb.opentsdb"
)
tsdb
.
RegisterExecutor
(
"opentsdb"
,
NewOpenTsdbExecutor
)
tsdb
.
RegisterExecutor
(
"opentsdb"
,
NewOpenTsdbExecutor
)
tr
:=
&
http
.
Transport
{
HttpClient
=
tsdb
.
GetDefaultClient
()
TLSClientConfig
:
&
tls
.
Config
{
InsecureSkipVerify
:
true
},
}
HttpClient
=
&
http
.
Client
{
Timeout
:
time
.
Duration
(
15
*
time
.
Second
),
Transport
:
tr
,
}
}
}
func
(
e
*
OpenTsdbExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
queryContext
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
func
(
e
*
OpenTsdbExecutor
)
Execute
(
ctx
context
.
Context
,
queries
tsdb
.
QuerySlice
,
queryContext
*
tsdb
.
QueryContext
)
*
tsdb
.
BatchResult
{
...
@@ -58,9 +49,9 @@ func (e *OpenTsdbExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
...
@@ -58,9 +49,9 @@ func (e *OpenTsdbExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
tsdbQuery
.
Start
=
queryContext
.
TimeRange
.
GetFromAsMsEpoch
()
tsdbQuery
.
Start
=
queryContext
.
TimeRange
.
GetFromAsMsEpoch
()
tsdbQuery
.
End
=
queryContext
.
TimeRange
.
GetToAsMsEpoch
()
tsdbQuery
.
End
=
queryContext
.
TimeRange
.
GetToAsMsEpoch
()
for
_
,
query
:=
range
queries
{
for
_
,
query
:=
range
queries
{
metric
:=
e
.
buildMetric
(
query
)
metric
:=
e
.
buildMetric
(
query
)
tsdbQuery
.
Queries
=
append
(
tsdbQuery
.
Queries
,
metric
)
tsdbQuery
.
Queries
=
append
(
tsdbQuery
.
Queries
,
metric
)
}
}
if
setting
.
Env
==
setting
.
DEV
{
if
setting
.
Env
==
setting
.
DEV
{
...
@@ -104,7 +95,7 @@ func (e *OpenTsdbExecutor) createRequest(data OpenTsdbQuery) (*http.Request, err
...
@@ -104,7 +95,7 @@ func (e *OpenTsdbExecutor) createRequest(data OpenTsdbQuery) (*http.Request, err
if
e
.
BasicAuth
{
if
e
.
BasicAuth
{
req
.
SetBasicAuth
(
e
.
BasicAuthUser
,
e
.
BasicAuthPassword
)
req
.
SetBasicAuth
(
e
.
BasicAuthUser
,
e
.
BasicAuthPassword
)
}
}
return
req
,
err
return
req
,
err
}
}
...
@@ -152,61 +143,61 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
...
@@ -152,61 +143,61 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
return
queryResults
,
nil
return
queryResults
,
nil
}
}
func
(
e
*
OpenTsdbExecutor
)
buildMetric
(
query
*
tsdb
.
Query
)
(
map
[
string
]
interface
{})
{
func
(
e
*
OpenTsdbExecutor
)
buildMetric
(
query
*
tsdb
.
Query
)
map
[
string
]
interface
{}
{
metric
:=
make
(
map
[
string
]
interface
{})
metric
:=
make
(
map
[
string
]
interface
{})
// Setting metric and aggregator
// Setting metric and aggregator
metric
[
"metric"
]
=
query
.
Model
.
Get
(
"metric"
)
.
MustString
()
metric
[
"metric"
]
=
query
.
Model
.
Get
(
"metric"
)
.
MustString
()
metric
[
"aggregator"
]
=
query
.
Model
.
Get
(
"aggregator"
)
.
MustString
()
metric
[
"aggregator"
]
=
query
.
Model
.
Get
(
"aggregator"
)
.
MustString
()
// Setting downsampling options
// Setting downsampling options
disableDownsampling
:=
query
.
Model
.
Get
(
"disableDownsampling"
)
.
MustBool
()
disableDownsampling
:=
query
.
Model
.
Get
(
"disableDownsampling"
)
.
MustBool
()
if
!
disableDownsampling
{
if
!
disableDownsampling
{
downsampleInterval
:=
query
.
Model
.
Get
(
"downsampleInterval"
)
.
MustString
()
downsampleInterval
:=
query
.
Model
.
Get
(
"downsampleInterval"
)
.
MustString
()
if
downsampleInterval
==
""
{
if
downsampleInterval
==
""
{
downsampleInterval
=
"1m"
//default value for blank
downsampleInterval
=
"1m"
//default value for blank
}
}
downsample
:=
downsampleInterval
+
"-"
+
query
.
Model
.
Get
(
"downsampleAggregator"
)
.
MustString
()
downsample
:=
downsampleInterval
+
"-"
+
query
.
Model
.
Get
(
"downsampleAggregator"
)
.
MustString
()
if
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
!=
"none"
{
if
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
!=
"none"
{
metric
[
"downsample"
]
=
downsample
+
"-"
+
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
metric
[
"downsample"
]
=
downsample
+
"-"
+
query
.
Model
.
Get
(
"downsampleFillPolicy"
)
.
MustString
()
}
else
{
}
else
{
metric
[
"downsample"
]
=
downsample
metric
[
"downsample"
]
=
downsample
}
}
}
}
// Setting rate options
// Setting rate options
if
query
.
Model
.
Get
(
"shouldComputeRate"
)
.
MustBool
()
{
if
query
.
Model
.
Get
(
"shouldComputeRate"
)
.
MustBool
()
{
metric
[
"rate"
]
=
true
rateOptions
:=
make
(
map
[
string
]
interface
{})
rateOptions
[
"counter"
]
=
query
.
Model
.
Get
(
"isCounter"
)
.
MustBool
()
counterMax
,
counterMaxCheck
:=
query
.
Model
.
CheckGet
(
"counterMax"
)
metric
[
"rate"
]
=
true
if
counterMaxCheck
{
rateOptions
:=
make
(
map
[
string
]
interface
{})
rateOptions
[
"counterMax"
]
=
counterMax
.
MustFloat64
()
rateOptions
[
"counter"
]
=
query
.
Model
.
Get
(
"isCounter"
)
.
MustBool
()
}
resetValue
,
resetValueCheck
:=
query
.
Model
.
CheckGet
(
"counterResetValue"
)
if
resetValueCheck
{
rateOptions
[
"resetValue"
]
=
resetValue
.
MustFloat64
()
}
metric
[
"rateOptions"
]
=
rateOptions
counterMax
,
counterMaxCheck
:=
query
.
Model
.
CheckGet
(
"counterMax"
)
if
counterMaxCheck
{
rateOptions
[
"counterMax"
]
=
counterMax
.
MustFloat64
()
}
}
// Setting tags
resetValue
,
resetValueCheck
:=
query
.
Model
.
CheckGet
(
"counterResetValue"
)
tags
,
tagsCheck
:=
query
.
Model
.
CheckGet
(
"tags"
)
if
resetValueCheck
{
if
tagsCheck
&&
len
(
tags
.
MustMap
())
>
0
{
rateOptions
[
"resetValue"
]
=
resetValue
.
MustFloat64
()
metric
[
"tags"
]
=
tags
.
MustMap
()
}
}
// Setting filters
metric
[
"rateOptions"
]
=
rateOptions
filters
,
filtersCheck
:=
query
.
Model
.
CheckGet
(
"filters"
)
}
if
filtersCheck
&&
len
(
filters
.
MustArray
())
>
0
{
metric
[
"filters"
]
=
filters
.
MustArray
()
// Setting tags
}
tags
,
tagsCheck
:=
query
.
Model
.
CheckGet
(
"tags"
)
if
tagsCheck
&&
len
(
tags
.
MustMap
())
>
0
{
metric
[
"tags"
]
=
tags
.
MustMap
()
}
// Setting filters
filters
,
filtersCheck
:=
query
.
Model
.
CheckGet
(
"filters"
)
if
filtersCheck
&&
len
(
filters
.
MustArray
())
>
0
{
metric
[
"filters"
]
=
filters
.
MustArray
()
}
return
metric
return
metric
}
}
pkg/tsdb/prometheus/prometheus.go
View file @
d4bc92b2
...
@@ -3,7 +3,6 @@ package prometheus
...
@@ -3,7 +3,6 @@ package prometheus
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"net/http"
"regexp"
"regexp"
"strings"
"strings"
"time"
"time"
...
@@ -25,8 +24,7 @@ func NewPrometheusExecutor(dsInfo *tsdb.DataSourceInfo) tsdb.Executor {
...
@@ -25,8 +24,7 @@ func NewPrometheusExecutor(dsInfo *tsdb.DataSourceInfo) tsdb.Executor {
}
}
var
(
var
(
plog
log
.
Logger
plog
log
.
Logger
HttpClient
http
.
Client
)
)
func
init
()
{
func
init
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment