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
f813b4c5
Commit
f813b4c5
authored
Jan 09, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(plugins): converted graphite plugin to new format
parent
c5635f9c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
68 deletions
+69
-68
public/app/plugins/datasource/elasticsearch/datasource.js
+1
-0
public/app/plugins/datasource/graphite/datasource.d.ts
+3
-0
public/app/plugins/datasource/graphite/datasource.js
+56
-64
public/app/plugins/datasource/graphite/specs/datasource_specs.ts
+9
-4
No files found.
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
f813b4c5
...
@@ -12,6 +12,7 @@ define([
...
@@ -12,6 +12,7 @@ define([
function
(
angular
,
_
,
moment
,
kbn
,
ElasticQueryBuilder
,
IndexPattern
,
ElasticResponse
)
{
function
(
angular
,
_
,
moment
,
kbn
,
ElasticQueryBuilder
,
IndexPattern
,
ElasticResponse
)
{
'use strict'
;
'use strict'
;
/** @ngInject */
function
ElasticDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
,
timeSrv
)
{
function
ElasticDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
,
timeSrv
)
{
this
.
basicAuth
=
instanceSettings
.
basicAuth
;
this
.
basicAuth
=
instanceSettings
.
basicAuth
;
this
.
withCredentials
=
instanceSettings
.
withCredentials
;
this
.
withCredentials
=
instanceSettings
.
withCredentials
;
...
...
public/app/plugins/datasource/graphite/datasource.d.ts
0 → 100644
View file @
f813b4c5
declare
var
Datasource
:
any
;
export
{
Datasource
};
public/app/plugins/datasource/graphite/datasource.js
View file @
f813b4c5
...
@@ -12,20 +12,16 @@ define([
...
@@ -12,20 +12,16 @@ define([
function
(
angular
,
_
,
$
,
config
,
dateMath
)
{
function
(
angular
,
_
,
$
,
config
,
dateMath
)
{
'use strict'
;
'use strict'
;
var
module
=
angular
.
module
(
'grafana.services'
);
/** @ngInject */
function
GraphiteDatasource
(
instanceSettings
,
$q
,
backendSrv
,
templateSrv
)
{
module
.
factory
(
'GraphiteDatasource'
,
function
(
$q
,
backendSrv
,
templateSrv
)
{
this
.
basicAuth
=
instanceSettings
.
basicAuth
;
this
.
url
=
instanceSettings
.
url
;
function
GraphiteDatasource
(
datasource
)
{
this
.
name
=
instanceSettings
.
name
;
this
.
basicAuth
=
datasource
.
basicAuth
;
this
.
cacheTimeout
=
instanceSettings
.
cacheTimeout
;
this
.
url
=
datasource
.
url
;
this
.
withCredentials
=
instanceSettings
.
withCredentials
;
this
.
name
=
datasource
.
name
;
this
.
render_method
=
instanceSettings
.
render_method
||
'POST'
;
this
.
cacheTimeout
=
datasource
.
cacheTimeout
;
this
.
withCredentials
=
datasource
.
withCredentials
;
this
.
query
=
function
(
options
)
{
this
.
render_method
=
datasource
.
render_method
||
'POST'
;
}
GraphiteDatasource
.
prototype
.
query
=
function
(
options
)
{
try
{
try
{
var
graphOptions
=
{
var
graphOptions
=
{
from
:
this
.
translateTime
(
options
.
rangeRaw
.
from
,
false
),
from
:
this
.
translateTime
(
options
.
rangeRaw
.
from
,
false
),
...
@@ -62,7 +58,7 @@ function (angular, _, $, config, dateMath) {
...
@@ -62,7 +58,7 @@ function (angular, _, $, config, dateMath) {
}
}
};
};
GraphiteDatasource
.
prototype
.
convertDataPointsToMs
=
function
(
result
)
{
this
.
convertDataPointsToMs
=
function
(
result
)
{
if
(
!
result
||
!
result
.
data
)
{
return
[];
}
if
(
!
result
||
!
result
.
data
)
{
return
[];
}
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
var
series
=
result
.
data
[
i
];
var
series
=
result
.
data
[
i
];
...
@@ -73,7 +69,7 @@ function (angular, _, $, config, dateMath) {
...
@@ -73,7 +69,7 @@ function (angular, _, $, config, dateMath) {
return
result
;
return
result
;
};
};
GraphiteDatasource
.
prototype
.
annotationQuery
=
function
(
options
)
{
this
.
annotationQuery
=
function
(
options
)
{
// Graphite metric as annotation
// Graphite metric as annotation
if
(
options
.
annotation
.
target
)
{
if
(
options
.
annotation
.
target
)
{
var
target
=
templateSrv
.
replace
(
options
.
annotation
.
target
);
var
target
=
templateSrv
.
replace
(
options
.
annotation
.
target
);
...
@@ -85,50 +81,49 @@ function (angular, _, $, config, dateMath) {
...
@@ -85,50 +81,49 @@ function (angular, _, $, config, dateMath) {
};
};
return
this
.
query
(
graphiteQuery
)
return
this
.
query
(
graphiteQuery
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
var
list
=
[];
var
list
=
[];
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
var
target
=
result
.
data
[
i
];
for
(
var
y
=
0
;
y
<
target
.
datapoints
.
length
;
y
++
)
{
var
datapoint
=
target
.
datapoints
[
y
];
if
(
!
datapoint
[
0
])
{
continue
;
}
list
.
push
({
annotation
:
options
.
annotation
,
time
:
datapoint
[
1
],
title
:
target
.
target
});
}
}
return
list
;
for
(
var
i
=
0
;
i
<
result
.
data
.
length
;
i
++
)
{
});
var
target
=
result
.
data
[
i
];
}
// Graphite event as annotation
for
(
var
y
=
0
;
y
<
target
.
datapoints
.
length
;
y
++
)
{
else
{
var
datapoint
=
target
.
datapoints
[
y
];
var
tags
=
templateSrv
.
replace
(
options
.
annotation
.
tags
);
if
(
!
datapoint
[
0
])
{
continue
;
}
return
this
.
events
({
range
:
options
.
rangeRaw
,
tags
:
tags
})
.
then
(
function
(
results
)
{
var
list
=
[];
for
(
var
i
=
0
;
i
<
results
.
data
.
length
;
i
++
)
{
var
e
=
results
.
data
[
i
];
list
.
push
({
list
.
push
({
annotation
:
options
.
annotation
,
annotation
:
options
.
annotation
,
time
:
e
.
when
*
1000
,
time
:
datapoint
[
1
],
title
:
e
.
what
,
title
:
target
.
target
tags
:
e
.
tags
,
text
:
e
.
data
});
});
}
}
return
list
;
}
});
return
list
;
});
}
// Graphite event as annotation
else
{
var
tags
=
templateSrv
.
replace
(
options
.
annotation
.
tags
);
return
this
.
events
({
range
:
options
.
rangeRaw
,
tags
:
tags
}).
then
(
function
(
results
)
{
var
list
=
[];
for
(
var
i
=
0
;
i
<
results
.
data
.
length
;
i
++
)
{
var
e
=
results
.
data
[
i
];
list
.
push
({
annotation
:
options
.
annotation
,
time
:
e
.
when
*
1000
,
title
:
e
.
what
,
tags
:
e
.
tags
,
text
:
e
.
data
});
}
return
list
;
});
}
}
};
};
GraphiteDatasource
.
prototype
.
events
=
function
(
options
)
{
this
.
events
=
function
(
options
)
{
try
{
try
{
var
tags
=
''
;
var
tags
=
''
;
if
(
options
.
tags
)
{
if
(
options
.
tags
)
{
...
@@ -146,7 +141,7 @@ function (angular, _, $, config, dateMath) {
...
@@ -146,7 +141,7 @@ function (angular, _, $, config, dateMath) {
}
}
};
};
GraphiteDatasource
.
prototype
.
translateTime
=
function
(
date
,
roundUp
)
{
this
.
translateTime
=
function
(
date
,
roundUp
)
{
if
(
_
.
isString
(
date
))
{
if
(
_
.
isString
(
date
))
{
if
(
date
===
'now'
)
{
if
(
date
===
'now'
)
{
return
'now'
;
return
'now'
;
...
@@ -178,7 +173,7 @@ function (angular, _, $, config, dateMath) {
...
@@ -178,7 +173,7 @@ function (angular, _, $, config, dateMath) {
return
date
.
unix
();
return
date
.
unix
();
};
};
GraphiteDatasource
.
prototype
.
metricFindQuery
=
function
(
query
)
{
this
.
metricFindQuery
=
function
(
query
)
{
var
interpolated
;
var
interpolated
;
try
{
try
{
interpolated
=
encodeURIComponent
(
templateSrv
.
replace
(
query
));
interpolated
=
encodeURIComponent
(
templateSrv
.
replace
(
query
));
...
@@ -198,24 +193,24 @@ function (angular, _, $, config, dateMath) {
...
@@ -198,24 +193,24 @@ function (angular, _, $, config, dateMath) {
});
});
};
};
GraphiteDatasource
.
prototype
.
testDatasource
=
function
()
{
this
.
testDatasource
=
function
()
{
return
this
.
metricFindQuery
(
'*'
).
then
(
function
()
{
return
this
.
metricFindQuery
(
'*'
).
then
(
function
()
{
return
{
status
:
"success"
,
message
:
"Data source is working"
,
title
:
"Success"
};
return
{
status
:
"success"
,
message
:
"Data source is working"
,
title
:
"Success"
};
});
});
};
};
GraphiteDatasource
.
prototype
.
listDashboards
=
function
(
query
)
{
this
.
listDashboards
=
function
(
query
)
{
return
this
.
doGraphiteRequest
({
method
:
'GET'
,
url
:
'/dashboard/find/'
,
params
:
{
query
:
query
||
''
}
})
return
this
.
doGraphiteRequest
({
method
:
'GET'
,
url
:
'/dashboard/find/'
,
params
:
{
query
:
query
||
''
}
})
.
then
(
function
(
results
)
{
.
then
(
function
(
results
)
{
return
results
.
data
.
dashboards
;
return
results
.
data
.
dashboards
;
});
});
};
};
GraphiteDatasource
.
prototype
.
loadDashboard
=
function
(
dashName
)
{
this
.
loadDashboard
=
function
(
dashName
)
{
return
this
.
doGraphiteRequest
({
method
:
'GET'
,
url
:
'/dashboard/load/'
+
encodeURIComponent
(
dashName
)
});
return
this
.
doGraphiteRequest
({
method
:
'GET'
,
url
:
'/dashboard/load/'
+
encodeURIComponent
(
dashName
)
});
};
};
GraphiteDatasource
.
prototype
.
doGraphiteRequest
=
function
(
options
)
{
this
.
doGraphiteRequest
=
function
(
options
)
{
if
(
this
.
basicAuth
||
this
.
withCredentials
)
{
if
(
this
.
basicAuth
||
this
.
withCredentials
)
{
options
.
withCredentials
=
true
;
options
.
withCredentials
=
true
;
}
}
...
@@ -230,9 +225,9 @@ function (angular, _, $, config, dateMath) {
...
@@ -230,9 +225,9 @@ function (angular, _, $, config, dateMath) {
return
backendSrv
.
datasourceRequest
(
options
);
return
backendSrv
.
datasourceRequest
(
options
);
};
};
GraphiteDatasource
.
prototype
.
_seriesRefLetters
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
this
.
_seriesRefLetters
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
GraphiteDatasource
.
prototype
.
buildGraphiteParams
=
function
(
options
,
scopedVars
)
{
this
.
buildGraphiteParams
=
function
(
options
,
scopedVars
)
{
var
graphite_options
=
[
'from'
,
'until'
,
'rawData'
,
'format'
,
'maxDataPoints'
,
'cacheTimeout'
];
var
graphite_options
=
[
'from'
,
'until'
,
'rawData'
,
'format'
,
'maxDataPoints'
,
'cacheTimeout'
];
var
clean_options
=
[],
targets
=
{};
var
clean_options
=
[],
targets
=
{};
var
target
,
targetValue
,
i
;
var
target
,
targetValue
,
i
;
...
@@ -296,12 +291,9 @@ function (angular, _, $, config, dateMath) {
...
@@ -296,12 +291,9 @@ function (angular, _, $, config, dateMath) {
return
clean_options
;
return
clean_options
;
};
};
}
return
GraphiteDatasource
;
});
return
{
return
{
serviceName
:
"GraphiteDatasource"
Datasource
:
GraphiteDatasource
};
};
});
});
public/app/plugins/datasource/graphite/specs/datasource_specs.ts
View file @
f813b4c5
import
"../datasource"
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
{
describe
,
beforeEach
,
it
,
sinon
,
expect
,
angularMocks
}
from
'test/lib/common'
;
import
helpers
from
'test/specs/helpers'
;
import
helpers
from
'test/specs/helpers'
;
import
{
Datasource
}
from
"../datasource"
;
describe
(
'graphiteDatasource'
,
function
()
{
describe
(
'graphiteDatasource'
,
function
()
{
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
ctx
=
new
helpers
.
ServiceTestContext
();
var
instanceSettings
:
any
=
{
url
:[
''
]};
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.core'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
angularMocks
.
module
(
'grafana.services'
));
beforeEach
(
ctx
.
providePhase
([
'backendSrv'
]));
beforeEach
(
ctx
.
providePhase
([
'backendSrv'
]));
beforeEach
(
ctx
.
createService
(
'GraphiteDatasource'
));
beforeEach
(
angularMocks
.
inject
(
function
(
$q
,
$rootScope
,
$httpBackend
,
$injector
)
{
ctx
.
$q
=
$q
;
ctx
.
$httpBackend
=
$httpBackend
;
ctx
.
$rootScope
=
$rootScope
;
ctx
.
$injector
=
$injector
;
}));
beforeEach
(
function
()
{
beforeEach
(
function
()
{
ctx
.
ds
=
new
ctx
.
service
({
url
:
[
''
]
});
ctx
.
ds
=
ctx
.
$injector
.
instantiate
(
Datasource
,
{
instanceSettings
:
instanceSettings
});
});
});
describe
(
'When querying influxdb with one target using query editor target spec'
,
function
()
{
describe
(
'When querying influxdb with one target using query editor target spec'
,
function
()
{
...
...
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