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
1dbbfbbb
Commit
1dbbfbbb
authored
Jul 02, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhanced InfluxDB series aliasing (legend names) with pattern replacements (Issue #525)
parent
88ab36c4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
170 additions
and
5 deletions
+170
-5
CHANGELOG.md
+1
-0
src/app/services/influxdb/influxSeries.js
+25
-5
src/test/specs/influxSeries-specs.js
+142
-0
src/test/test-main.js
+2
-0
No files found.
CHANGELOG.md
View file @
1dbbfbbb
...
...
@@ -3,6 +3,7 @@ vNext
**New features or improvements**
-
Allow
[
[..
]
] filter notation in all text panels (markdown/html/text) (Issue #511)
-
New legend display option "Align as table" (Issue #136)
-
Enhanced InfluxDB series aliasing (legend names) with pattern replacements (Issue #525)
**Changes**
-
Use unix epoch for Graphite from/to for absolute time ranges (Closes #536)
...
...
src/app/services/influxdb/influxSeries.js
View file @
1dbbfbbb
...
...
@@ -15,6 +15,7 @@ function (_) {
p
.
getTimeSeries
=
function
()
{
var
output
=
[];
var
self
=
this
;
var
i
;
_
.
each
(
self
.
seriesList
,
function
(
series
)
{
var
seriesName
;
...
...
@@ -46,16 +47,15 @@ function (_) {
_
.
each
(
groups
,
function
(
groupPoints
,
key
)
{
var
datapoints
=
[];
for
(
var
i
=
0
;
i
<
groupPoints
.
length
;
i
++
)
{
for
(
i
=
0
;
i
<
groupPoints
.
length
;
i
++
)
{
var
metricValue
=
isNaN
(
groupPoints
[
i
][
valueCol
])
?
null
:
groupPoints
[
i
][
valueCol
];
datapoints
[
i
]
=
[
metricValue
,
groupPoints
[
i
][
timeCol
]];
}
seriesName
=
se
lf
.
alias
?
self
.
alias
:
(
series
.
name
+
'.'
+
key
)
;
seriesName
=
se
ries
.
name
+
'.'
+
key
;
// if mulitple groups append key to alias
if
(
self
.
alias
&&
self
.
groupByField
)
{
seriesName
+=
key
;
if
(
self
.
alias
)
{
seriesName
=
self
.
createNameForSeries
(
series
.
name
,
series
.
columns
[
valueCol
],
key
);
}
output
.
push
({
target
:
seriesName
,
datapoints
:
datapoints
});
...
...
@@ -65,5 +65,24 @@ function (_) {
return
output
;
};
p
.
createNameForSeries
=
function
(
seriesName
,
columnName
,
groupByColValue
)
{
var
name
=
this
.
alias
.
replace
(
'$s'
,
seriesName
)
.
replace
(
'$c'
,
columnName
);
var
segments
=
seriesName
.
split
(
'.'
);
for
(
var
i
=
0
;
i
<
segments
.
length
;
i
++
)
{
if
(
segments
[
i
].
length
>
0
)
{
name
=
name
.
replace
(
'$'
+
i
,
segments
[
i
]);
}
}
if
(
this
.
groupByField
)
{
name
=
name
.
replace
(
'$g'
,
groupByColValue
);
}
return
name
;
};
return
InfluxSeries
;
});
\ No newline at end of file
src/test/specs/influxSeries-specs.js
0 → 100644
View file @
1dbbfbbb
define
([
'services/influxdb/influxSeries'
],
function
(
InfluxSeries
)
{
'use strict'
;
describe
(
'when generating timeseries from influxdb response'
,
function
()
{
describe
(
'given two series'
,
function
()
{
var
series
=
new
InfluxSeries
({
seriesList
:
[
{
columns
:
[
'time'
,
'mean'
,
'sequence_number'
],
name
:
'prod.server1.cpu'
,
points
:
[[
1402596000
,
10
,
1
],
[
1402596001
,
12
,
2
]]
},
{
columns
:
[
'time'
,
'mean'
,
'sequence_number'
],
name
:
'prod.server2.cpu'
,
points
:
[[
1402596000
,
15
,
1
],
[
1402596001
,
16
,
2
]]
}
]
});
var
result
=
series
.
getTimeSeries
();
it
(
'should generate two time series'
,
function
()
{
expect
(
result
.
length
).
to
.
be
(
2
);
expect
(
result
[
0
].
target
).
to
.
be
(
'prod.server1.cpu.mean'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1402596000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
12
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1402596001
);
expect
(
result
[
1
].
target
).
to
.
be
(
'prod.server2.cpu.mean'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
15
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1402596000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
16
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1402596001
);
});
});
describe
(
'given an alias format'
,
function
()
{
var
series
=
new
InfluxSeries
({
seriesList
:
[
{
columns
:
[
'time'
,
'mean'
,
'sequence_number'
],
name
:
'prod.server1.cpu'
,
points
:
[[
1402596000
,
10
,
1
],
[
1402596001
,
12
,
2
]]
}
],
alias
:
'$s.$c'
});
var
result
=
series
.
getTimeSeries
();
it
(
'should generate correct series name'
,
function
()
{
expect
(
result
[
0
].
target
).
to
.
be
(
'prod.server1.cpu.mean'
);
});
});
describe
(
'given an alias format with segment numbers'
,
function
()
{
var
series
=
new
InfluxSeries
({
seriesList
:
[
{
columns
:
[
'time'
,
'mean'
,
'sequence_number'
],
name
:
'prod.server1.cpu'
,
points
:
[[
1402596000
,
10
,
1
],
[
1402596001
,
12
,
2
]]
}
],
alias
:
'$1'
});
var
result
=
series
.
getTimeSeries
();
it
(
'should generate correct series name'
,
function
()
{
expect
(
result
[
0
].
target
).
to
.
be
(
'server1'
);
});
});
describe
(
'given an alias format with group by field'
,
function
()
{
var
series
=
new
InfluxSeries
({
seriesList
:
[
{
columns
:
[
'time'
,
'mean'
,
'host'
],
name
:
'prod.cpu'
,
points
:
[[
1402596000
,
10
,
'A'
]]
}
],
groupByField
:
'host'
,
alias
:
'$g.$1'
});
var
result
=
series
.
getTimeSeries
();
it
(
'should generate correct series name'
,
function
()
{
expect
(
result
[
0
].
target
).
to
.
be
(
'A.cpu'
);
});
});
describe
(
'given group by column'
,
function
()
{
var
series
=
new
InfluxSeries
({
seriesList
:
[
{
columns
:
[
'time'
,
'mean'
,
'host'
],
name
:
'prod.cpu'
,
points
:
[
[
1402596000
,
10
,
'A'
],
[
1402596001
,
11
,
'A'
],
[
1402596000
,
5
,
'B'
],
[
1402596001
,
6
,
'B'
],
]
}
],
groupByField
:
'host'
});
var
result
=
series
.
getTimeSeries
();
it
(
'should generate two time series'
,
function
()
{
expect
(
result
.
length
).
to
.
be
(
2
);
expect
(
result
[
0
].
target
).
to
.
be
(
'prod.cpu.A'
);
expect
(
result
[
0
].
datapoints
[
0
][
0
]).
to
.
be
(
10
);
expect
(
result
[
0
].
datapoints
[
0
][
1
]).
to
.
be
(
1402596000
);
expect
(
result
[
0
].
datapoints
[
1
][
0
]).
to
.
be
(
11
);
expect
(
result
[
0
].
datapoints
[
1
][
1
]).
to
.
be
(
1402596001
);
expect
(
result
[
1
].
target
).
to
.
be
(
'prod.cpu.B'
);
expect
(
result
[
1
].
datapoints
[
0
][
0
]).
to
.
be
(
5
);
expect
(
result
[
1
].
datapoints
[
0
][
1
]).
to
.
be
(
1402596000
);
expect
(
result
[
1
].
datapoints
[
1
][
0
]).
to
.
be
(
6
);
expect
(
result
[
1
].
datapoints
[
1
][
1
]).
to
.
be
(
1402596001
);
});
});
});
});
src/test/test-main.js
View file @
1dbbfbbb
...
...
@@ -128,8 +128,10 @@ require([
'specs/gfunc-specs'
,
'specs/filterSrv-specs'
,
'specs/kbn-format-specs'
,
'specs/influxSeries-specs'
],
function
()
{
window
.
__karma__
.
start
();
});
});
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