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
35cc3837
Commit
35cc3837
authored
Sep 08, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(elasticsearch): more work on alias pattern, #1034
parent
572a80d1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
37 deletions
+66
-37
public/app/plugins/datasource/elasticsearch/elasticResponse.js
+41
-16
public/app/plugins/datasource/elasticsearch/metricAgg.js
+5
-0
public/app/plugins/datasource/elasticsearch/partials/query.editor.html
+1
-1
public/app/plugins/datasource/elasticsearch/partials/query.options.html
+4
-5
public/app/plugins/datasource/elasticsearch/queryDef.js
+4
-4
public/test/specs/elasticsearch-response-specs.js
+11
-11
No files found.
public/app/plugins/datasource/elasticsearch/elasticResponse.js
View file @
35cc3837
define
([
define
([
"lodash"
"lodash"
,
"./queryDef"
],
],
function
(
_
)
{
function
(
_
,
queryDef
)
{
'use strict'
;
'use strict'
;
function
ElasticResponse
(
targets
,
response
)
{
function
ElasticResponse
(
targets
,
response
)
{
...
@@ -87,7 +88,7 @@ function (_) {
...
@@ -87,7 +88,7 @@ function (_) {
break
;
break
;
}
}
default
:
{
default
:
{
newSeries
=
{
datapoints
:
[],
metric
:
metric
.
type
+
' '
+
metric
.
field
,
props
:
props
};
newSeries
=
{
datapoints
:
[],
metric
:
metric
.
type
,
field
:
metric
.
field
,
props
:
props
};
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
esAgg
.
buckets
.
length
;
i
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
bucket
=
esAgg
.
buckets
[
i
];
value
=
bucket
[
metric
.
id
].
value
;
value
=
bucket
[
metric
.
id
].
value
;
...
@@ -100,35 +101,62 @@ function (_) {
...
@@ -100,35 +101,62 @@ function (_) {
}
}
};
};
ElasticResponse
.
prototype
.
_getSeriesName
=
function
(
props
,
metric
,
target
,
metricTypeCount
)
{
ElasticResponse
.
prototype
.
_getMetricName
=
function
(
metric
)
{
var
metricDef
=
_
.
findWhere
(
queryDef
.
metricAggTypes
,
{
value
:
metric
});
if
(
!
metricDef
)
{
metricDef
=
_
.
findWhere
(
queryDef
.
extendedStats
,
{
value
:
metric
});
}
return
metricDef
?
metricDef
.
text
:
metric
;
};
ElasticResponse
.
prototype
.
_getSeriesName
=
function
(
series
,
target
,
metricTypeCount
)
{
var
metricName
=
this
.
_getMetricName
(
series
.
metric
);
if
(
target
.
alias
)
{
if
(
target
.
alias
)
{
var
regex
=
/
\{\{([\s\S]
+
?)\}\}
/g
;
var
regex
=
/
\{\{([\s\S]
+
?)\}\}
/g
;
return
target
.
alias
.
replace
(
regex
,
function
(
match
,
g1
,
g2
)
{
return
target
.
alias
.
replace
(
regex
,
function
(
match
,
g1
,
g2
)
{
var
group
=
g1
||
g2
;
var
group
=
g1
||
g2
;
if
(
props
[
group
])
{
return
props
[
group
];
}
if
(
group
.
indexOf
(
'term '
)
===
0
)
{
return
series
.
props
[
group
.
substring
(
5
)];
}
if
(
group
===
'metric'
)
{
return
metric
;
}
if
(
series
.
props
[
group
])
{
return
series
.
props
[
group
];
}
if
(
group
===
'metric'
)
{
return
metricName
;
}
if
(
group
===
'field'
)
{
return
series
.
field
;
}
return
match
;
return
match
;
});
});
}
}
var
propKeys
=
_
.
keys
(
props
);
if
(
series
.
field
)
{
metricName
+=
' '
+
series
.
field
;
}
var
propKeys
=
_
.
keys
(
series
.
props
);
if
(
propKeys
.
length
===
0
)
{
if
(
propKeys
.
length
===
0
)
{
return
metric
;
return
metric
Name
;
}
}
var
name
=
''
;
var
name
=
''
;
for
(
var
propName
in
props
)
{
for
(
var
propName
in
series
.
props
)
{
name
+=
props
[
propName
]
+
' '
;
name
+=
series
.
props
[
propName
]
+
' '
;
}
}
if
(
metricTypeCount
===
1
)
{
if
(
metricTypeCount
===
1
)
{
return
name
.
trim
();
return
name
.
trim
();
}
}
return
name
.
trim
()
+
' '
+
metric
;
return
name
.
trim
()
+
' '
+
metricName
;
};
ElasticResponse
.
prototype
.
nameSeries
=
function
(
seriesList
,
target
)
{
var
metricTypeCount
=
_
.
uniq
(
_
.
pluck
(
seriesList
,
'metric'
)).
length
;
var
fieldNameCount
=
_
.
uniq
(
_
.
pluck
(
seriesList
,
'field'
)).
length
;
for
(
var
i
=
0
;
i
<
seriesList
.
length
;
i
++
)
{
var
series
=
seriesList
[
i
];
series
.
target
=
this
.
_getSeriesName
(
series
,
target
,
metricTypeCount
,
fieldNameCount
);
}
};
};
ElasticResponse
.
prototype
.
getTimeSeries
=
function
()
{
ElasticResponse
.
prototype
.
getTimeSeries
=
function
()
{
...
@@ -145,13 +173,10 @@ function (_) {
...
@@ -145,13 +173,10 @@ function (_) {
var
tmpSeriesList
=
[];
var
tmpSeriesList
=
[];
this
.
processBuckets
(
aggregations
,
target
,
tmpSeriesList
,
0
,
{});
this
.
processBuckets
(
aggregations
,
target
,
tmpSeriesList
,
0
,
{});
this
.
nameSeries
(
tmpSeriesList
,
target
);
var
metricTypeCount
=
_
.
uniq
(
_
.
pluck
(
tmpSeriesList
,
'metric'
)).
length
;
for
(
var
y
=
0
;
y
<
tmpSeriesList
.
length
;
y
++
)
{
for
(
var
y
=
0
;
y
<
tmpSeriesList
.
length
;
y
++
)
{
var
series
=
tmpSeriesList
[
y
];
seriesList
.
push
(
tmpSeriesList
[
y
]);
series
.
target
=
this
.
_getSeriesName
(
series
.
props
,
series
.
metric
,
target
,
metricTypeCount
);
seriesList
.
push
(
series
);
}
}
}
}
...
...
public/app/plugins/datasource/elasticsearch/metricAgg.js
View file @
35cc3837
...
@@ -48,6 +48,11 @@ function (angular, _, queryDef) {
...
@@ -48,6 +48,11 @@ function (angular, _, queryDef) {
return
memo
;
return
memo
;
},
[]);
},
[]);
$scope
.
settingsLinkText
=
'Stats: '
+
stats
.
join
(
', '
);
$scope
.
settingsLinkText
=
'Stats: '
+
stats
.
join
(
', '
);
if
(
stats
.
length
===
0
)
{
$scope
.
agg
.
meta
.
std_deviation_bounds_lower
=
true
;
$scope
.
agg
.
meta
.
std_deviation_bounds_upper
=
true
;
}
}
}
}
}
};
};
...
...
public/app/plugins/datasource/elasticsearch/partials/query.editor.html
View file @
35cc3837
...
@@ -51,7 +51,7 @@
...
@@ -51,7 +51,7 @@
Alias
Alias
</li>
</li>
<li>
<li>
<input
type=
"text"
class=
"tight-form-input"
style=
"width: 2
45
px;"
ng-model=
"target.alias"
spellcheck=
'false'
placeholder=
"alias patterns (empty = auto)"
ng-blur=
"get_data()"
>
<input
type=
"text"
class=
"tight-form-input"
style=
"width: 2
60
px;"
ng-model=
"target.alias"
spellcheck=
'false'
placeholder=
"alias patterns (empty = auto)"
ng-blur=
"get_data()"
>
</li>
</li>
</ul>
</ul>
<div
class=
"clearfix"
></div>
<div
class=
"clearfix"
></div>
...
...
public/app/plugins/datasource/elasticsearch/partials/query.options.html
View file @
35cc3837
...
@@ -19,11 +19,10 @@
...
@@ -19,11 +19,10 @@
<div
class=
"grafana-info-box span6"
ng-if=
"editorHelpIndex === 1"
>
<div
class=
"grafana-info-box span6"
ng-if=
"editorHelpIndex === 1"
>
<h5>
Alias patterns
</h5>
<h5>
Alias patterns
</h5>
<ul>
<ul
ng-non-bindable
>
<li>
$m = replaced with measurement name
</li>
<li>
{{term fieldname}} = replaced with value of term group by
</li>
<li>
$measurement = replaced with measurement name
</li>
<li>
{{metric}} = replaced with metric name (ex. Average, Min, Max)
</li>
<li>
$tag_hostname = replaced with the value of the hostname tag
</li>
<li>
{{field}} = replaced with the metric field name
</li>
<li>
You can also use [[tag_hostname]] pattern replacement syntax
</li>
</ul>
</ul>
</div>
</div>
...
...
public/app/plugins/datasource/elasticsearch/queryDef.js
View file @
35cc3837
...
@@ -7,10 +7,10 @@ function (_) {
...
@@ -7,10 +7,10 @@ function (_) {
return
{
return
{
metricAggTypes
:
[
metricAggTypes
:
[
{
text
:
"Count"
,
value
:
'count'
},
{
text
:
"Count"
,
value
:
'count'
},
{
text
:
"Average
of
"
,
value
:
'avg'
},
{
text
:
"Average"
,
value
:
'avg'
},
{
text
:
"Sum
of
"
,
value
:
'sum'
},
{
text
:
"Sum"
,
value
:
'sum'
},
{
text
:
"Max
of
"
,
value
:
'max'
},
{
text
:
"Max"
,
value
:
'max'
},
{
text
:
"Min
of
"
,
value
:
'min'
},
{
text
:
"Min"
,
value
:
'min'
},
{
text
:
"Extended Stats"
,
value
:
'extended_stats'
},
{
text
:
"Extended Stats"
,
value
:
'extended_stats'
},
{
text
:
"Percentiles"
,
value
:
'percentiles'
},
{
text
:
"Percentiles"
,
value
:
'percentiles'
},
{
text
:
"Unique Count"
,
value
:
"cardinality"
}
{
text
:
"Unique Count"
,
value
:
"cardinality"
}
...
...
public/test/specs/elasticsearch-response-specs.js
View file @
35cc3837
...
@@ -40,7 +40,7 @@ define([
...
@@ -40,7 +40,7 @@ define([
it
(
'should return 1 series'
,
function
()
{
it
(
'should return 1 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
1
);
expect
(
result
.
data
.
length
).
to
.
be
(
1
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'
c
ount'
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'
C
ount'
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1000
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1000
);
...
@@ -87,7 +87,7 @@ define([
...
@@ -87,7 +87,7 @@ define([
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1000
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1000
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
"
avg
value"
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
"
Average
value"
);
expect
(
result
.
data
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
88
);
expect
(
result
.
data
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
88
);
expect
(
result
.
data
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
99
);
expect
(
result
.
data
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
99
);
});
});
...
@@ -191,10 +191,10 @@ define([
...
@@ -191,10 +191,10 @@ define([
it
(
'should return 2 series'
,
function
()
{
it
(
'should return 2 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
c
ount'
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
C
ount'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
avg
@value'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
Average
@value'
);
expect
(
result
.
data
[
2
].
target
).
to
.
be
(
'server2
c
ount'
);
expect
(
result
.
data
[
2
].
target
).
to
.
be
(
'server2
C
ount'
);
expect
(
result
.
data
[
3
].
target
).
to
.
be
(
'server2
avg
@value'
);
expect
(
result
.
data
[
3
].
target
).
to
.
be
(
'server2
Average
@value'
);
});
});
});
});
...
@@ -288,8 +288,8 @@ define([
...
@@ -288,8 +288,8 @@ define([
it
(
'should return 4 series'
,
function
()
{
it
(
'should return 4 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
1
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
1
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
m
ax'
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
M
ax'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
std_deviation_bounds_u
pper'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
Std Dev U
pper'
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10.2
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10.2
);
expect
(
result
.
data
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
3
);
expect
(
result
.
data
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
3
);
...
@@ -303,7 +303,7 @@ define([
...
@@ -303,7 +303,7 @@ define([
targets
=
[{
targets
=
[{
refId
:
'A'
,
refId
:
'A'
,
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
alias
:
'{{@host}} {{metric}} and!'
,
alias
:
'{{
term
@host}} {{metric}} and!'
,
bucketAggs
:
[
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
id
:
'2'
},
{
type
:
'terms'
,
field
:
'@host'
,
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
...
@@ -346,8 +346,8 @@ define([
...
@@ -346,8 +346,8 @@ define([
it
(
'should return 2 series'
,
function
()
{
it
(
'should return 2 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
c
ount and!'
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
C
ount and!'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server2
c
ount and!'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server2
C
ount and!'
);
});
});
});
});
...
...
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