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
Hide 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
([
"lodash"
"lodash"
,
"./queryDef"
],
function
(
_
)
{
function
(
_
,
queryDef
)
{
'use strict'
;
function
ElasticResponse
(
targets
,
response
)
{
...
...
@@ -87,7 +88,7 @@ function (_) {
break
;
}
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
++
)
{
bucket
=
esAgg
.
buckets
[
i
];
value
=
bucket
[
metric
.
id
].
value
;
...
...
@@ -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
)
{
var
regex
=
/
\{\{([\s\S]
+
?)\}\}
/g
;
return
target
.
alias
.
replace
(
regex
,
function
(
match
,
g1
,
g2
)
{
var
group
=
g1
||
g2
;
if
(
props
[
group
])
{
return
props
[
group
];
}
if
(
group
===
'metric'
)
{
return
metric
;
}
if
(
group
.
indexOf
(
'term '
)
===
0
)
{
return
series
.
props
[
group
.
substring
(
5
)];
}
if
(
series
.
props
[
group
])
{
return
series
.
props
[
group
];
}
if
(
group
===
'metric'
)
{
return
metricName
;
}
if
(
group
===
'field'
)
{
return
series
.
field
;
}
return
match
;
});
}
var
propKeys
=
_
.
keys
(
props
);
if
(
series
.
field
)
{
metricName
+=
' '
+
series
.
field
;
}
var
propKeys
=
_
.
keys
(
series
.
props
);
if
(
propKeys
.
length
===
0
)
{
return
metric
;
return
metric
Name
;
}
var
name
=
''
;
for
(
var
propName
in
props
)
{
name
+=
props
[
propName
]
+
' '
;
for
(
var
propName
in
series
.
props
)
{
name
+=
series
.
props
[
propName
]
+
' '
;
}
if
(
metricTypeCount
===
1
)
{
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
()
{
...
...
@@ -145,13 +173,10 @@ function (_) {
var
tmpSeriesList
=
[];
this
.
processBuckets
(
aggregations
,
target
,
tmpSeriesList
,
0
,
{});
var
metricTypeCount
=
_
.
uniq
(
_
.
pluck
(
tmpSeriesList
,
'metric'
)).
length
;
this
.
nameSeries
(
tmpSeriesList
,
target
);
for
(
var
y
=
0
;
y
<
tmpSeriesList
.
length
;
y
++
)
{
var
series
=
tmpSeriesList
[
y
];
series
.
target
=
this
.
_getSeriesName
(
series
.
props
,
series
.
metric
,
target
,
metricTypeCount
);
seriesList
.
push
(
series
);
seriesList
.
push
(
tmpSeriesList
[
y
]);
}
}
...
...
public/app/plugins/datasource/elasticsearch/metricAgg.js
View file @
35cc3837
...
...
@@ -48,6 +48,11 @@ function (angular, _, queryDef) {
return
memo
;
},
[]);
$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 @@
Alias
</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>
</ul>
<div
class=
"clearfix"
></div>
...
...
public/app/plugins/datasource/elasticsearch/partials/query.options.html
View file @
35cc3837
...
...
@@ -19,11 +19,10 @@
<div
class=
"grafana-info-box span6"
ng-if=
"editorHelpIndex === 1"
>
<h5>
Alias patterns
</h5>
<ul>
<li>
$m = replaced with measurement name
</li>
<li>
$measurement = replaced with measurement name
</li>
<li>
$tag_hostname = replaced with the value of the hostname tag
</li>
<li>
You can also use [[tag_hostname]] pattern replacement syntax
</li>
<ul
ng-non-bindable
>
<li>
{{term fieldname}} = replaced with value of term group by
</li>
<li>
{{metric}} = replaced with metric name (ex. Average, Min, Max)
</li>
<li>
{{field}} = replaced with the metric field name
</li>
</ul>
</div>
...
...
public/app/plugins/datasource/elasticsearch/queryDef.js
View file @
35cc3837
...
...
@@ -7,10 +7,10 @@ function (_) {
return
{
metricAggTypes
:
[
{
text
:
"Count"
,
value
:
'count'
},
{
text
:
"Average
of
"
,
value
:
'avg'
},
{
text
:
"Sum
of
"
,
value
:
'sum'
},
{
text
:
"Max
of
"
,
value
:
'max'
},
{
text
:
"Min
of
"
,
value
:
'min'
},
{
text
:
"Average"
,
value
:
'avg'
},
{
text
:
"Sum"
,
value
:
'sum'
},
{
text
:
"Max"
,
value
:
'max'
},
{
text
:
"Min"
,
value
:
'min'
},
{
text
:
"Extended Stats"
,
value
:
'extended_stats'
},
{
text
:
"Percentiles"
,
value
:
'percentiles'
},
{
text
:
"Unique Count"
,
value
:
"cardinality"
}
...
...
public/test/specs/elasticsearch-response-specs.js
View file @
35cc3837
...
...
@@ -40,7 +40,7 @@ define([
it
(
'should return 1 series'
,
function
()
{
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
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
.
data
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1000
);
...
...
@@ -87,7 +87,7 @@ define([
expect
(
result
.
data
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
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
[
1
][
0
]).
to
.
be
(
99
);
});
...
...
@@ -191,10 +191,10 @@ define([
it
(
'should return 2 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
2
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
c
ount'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
avg
@value'
);
expect
(
result
.
data
[
2
].
target
).
to
.
be
(
'server2
c
ount'
);
expect
(
result
.
data
[
3
].
target
).
to
.
be
(
'server2
avg
@value'
);
expect
(
result
.
data
[
0
].
target
).
to
.
be
(
'server1
C
ount'
);
expect
(
result
.
data
[
1
].
target
).
to
.
be
(
'server1
Average
@value'
);
expect
(
result
.
data
[
2
].
target
).
to
.
be
(
'server2
C
ount'
);
expect
(
result
.
data
[
3
].
target
).
to
.
be
(
'server2
Average
@value'
);
});
});
...
...
@@ -288,8 +288,8 @@ define([
it
(
'should return 4 series'
,
function
()
{
expect
(
result
.
data
.
length
).
to
.
be
(
4
);
expect
(
result
.
data
[
0
].
datapoints
.
length
).
to
.
be
(
1
);
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
[
0
].
target
).
to
.
be
(
'server1
M
ax'
);
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
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
3
);
...
...
@@ -303,7 +303,7 @@ define([
targets
=
[{
refId
:
'A'
,
metrics
:
[{
type
:
'count'
,
id
:
'1'
}],
alias
:
'{{@host}} {{metric}} and!'
,
alias
:
'{{
term
@host}} {{metric}} and!'
,
bucketAggs
:
[
{
type
:
'terms'
,
field
:
'@host'
,
id
:
'2'
},
{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'3'
}
...
...
@@ -346,8 +346,8 @@ define([
it
(
'should return 2 series'
,
function
()
{
expect
(
result
.
data
.
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
[
1
].
target
).
to
.
be
(
'server2
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!'
);
});
});
...
...
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