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
f8b05e0f
Commit
f8b05e0f
authored
Oct 02, 2015
by
Mitsuhiro Tanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add prometheus annotation query
parent
80e15dd7
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
8 deletions
+132
-8
public/app/plugins/datasource/prometheus/datasource.ts
+61
-6
public/app/plugins/datasource/prometheus/module.ts
+6
-1
public/app/plugins/datasource/prometheus/partials/annotations.editor.html
+28
-0
public/app/plugins/datasource/prometheus/plugin.json
+2
-1
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
+35
-0
No files found.
public/app/plugins/datasource/prometheus/datasource.ts
View file @
f8b05e0f
...
@@ -188,6 +188,58 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
...
@@ -188,6 +188,58 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
}
}
};
};
this
.
annotationQuery
=
function
(
options
)
{
var
annotation
=
options
.
annotation
;
var
expr
=
annotation
.
expr
||
''
;
var
tagKeys
=
annotation
.
tagKeys
||
''
;
var
titleFormat
=
annotation
.
titleFormat
||
''
;
var
textFormat
=
annotation
.
textFormat
||
''
;
if
(
!
expr
)
{
return
$q
.
when
([]);
}
var
interpolated
;
try
{
interpolated
=
templateSrv
.
replace
(
expr
);
}
catch
(
err
)
{
return
$q
.
reject
(
err
);
}
var
query
=
{
expr
:
interpolated
,
step
:
'60s'
};
var
start
=
getPrometheusTime
(
options
.
range
.
from
,
false
);
var
end
=
getPrometheusTime
(
options
.
range
.
to
,
true
);
return
this
.
performTimeSeriesQuery
(
query
,
start
,
end
).
then
(
function
(
results
)
{
var
eventList
=
[];
tagKeys
=
tagKeys
.
split
(
','
);
_
.
each
(
results
.
data
.
data
.
result
,
function
(
series
)
{
var
tags
=
_
.
chain
(
series
.
metric
)
.
filter
(
function
(
v
,
k
)
{
return
_
.
contains
(
tagKeys
,
k
);
}).
value
();
_
.
each
(
series
.
values
,
function
(
value
)
{
if
(
value
[
1
]
===
'1'
)
{
var
event
=
{
annotation
:
annotation
,
time
:
Math
.
floor
(
value
[
0
])
*
1000
,
title
:
renderTemplate
(
titleFormat
,
series
.
metric
),
tags
:
tags
,
text
:
renderTemplate
(
textFormat
,
series
.
metric
)
};
eventList
.
push
(
event
);
}
});
});
return
eventList
;
});
};
this
.
testDatasource
=
function
()
{
this
.
testDatasource
=
function
()
{
return
this
.
metricFindQuery
(
'metrics(.*)'
).
then
(
function
()
{
return
this
.
metricFindQuery
(
'metrics(.*)'
).
then
(
function
()
{
return
{
status
:
'success'
,
message
:
'Data source is working'
,
title
:
'Success'
};
return
{
status
:
'success'
,
message
:
'Data source is working'
,
title
:
'Success'
};
...
@@ -240,22 +292,25 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
...
@@ -240,22 +292,25 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return
getOriginalMetricName
(
labelData
);
return
getOriginalMetricName
(
labelData
);
}
}
var
originalSettings
=
_
.
templateSettings
;
return
renderTemplate
(
options
.
legendFormat
,
labelData
)
||
'{}'
;
}
function
renderTemplate
(
format
,
data
)
{
_
.
templateSettings
=
{
_
.
templateSettings
=
{
interpolate
:
/
\{\{(
.+
?)\}\}
/g
interpolate
:
/
\{\{(
.+
?)\}\}
/g
};
};
var
template
=
_
.
template
(
templateSrv
.
replace
(
options
.
legendF
ormat
));
var
template
=
_
.
template
(
templateSrv
.
replace
(
f
ormat
));
var
metricName
;
var
result
;
try
{
try
{
metricName
=
template
(
labelD
ata
);
result
=
template
(
d
ata
);
}
catch
(
e
)
{
}
catch
(
e
)
{
metricName
=
'{}'
;
result
=
null
;
}
}
_
.
templateSettings
=
originalSettings
;
_
.
templateSettings
=
originalSettings
;
return
metricName
;
return
result
;
}
}
function
getOriginalMetricName
(
labelData
)
{
function
getOriginalMetricName
(
labelData
)
{
...
...
public/app/plugins/datasource/prometheus/module.ts
View file @
f8b05e0f
...
@@ -5,8 +5,13 @@ class PrometheusConfigCtrl {
...
@@ -5,8 +5,13 @@ class PrometheusConfigCtrl {
static
templateUrl
=
'public/app/plugins/datasource/prometheus/partials/config.html'
;
static
templateUrl
=
'public/app/plugins/datasource/prometheus/partials/config.html'
;
}
}
class
PrometheusAnnotationsQueryCtrl
{
static
templateUrl
=
'public/app/plugins/datasource/prometheus/partials/annotations.editor.html'
;
}
export
{
export
{
PrometheusDatasource
as
Datasource
,
PrometheusDatasource
as
Datasource
,
PrometheusQueryCtrl
as
QueryCtrl
,
PrometheusQueryCtrl
as
QueryCtrl
,
PrometheusConfigCtrl
as
ConfigCtrl
PrometheusConfigCtrl
as
ConfigCtrl
,
PrometheusAnnotationsQueryCtrl
as
AnnotationsQueryCtrl
,
};
};
public/app/plugins/datasource/prometheus/partials/annotations.editor.html
0 → 100644
View file @
f8b05e0f
<div
class=
"editor-row"
>
<div
class=
"section"
>
<h5>
Search expression
</h5>
<div
class=
"editor-option"
>
<input
type=
"text"
class=
"span6"
ng-model=
'currentAnnotation.expr'
placeholder=
"ALERTS"
></input>
</div>
</div>
</div>
<div
class=
"editor-row"
>
<div
class=
"section"
>
<h5>
Field formats
</h5>
<div
class=
"editor-option"
>
<label
class=
"small"
>
Title
</label>
<input
type=
"text"
class=
"input-small"
ng-model=
'currentAnnotation.titleFormat'
placeholder=
"alertname"
></input>
</div>
<div
class=
"editor-option"
>
<label
class=
"small"
>
Tags
</label>
<input
type=
"text"
class=
"input-small"
ng-model=
'currentAnnotation.tagKeys'
placeholder=
"label1,label2"
></input>
</div>
<div
class=
"editor-option"
>
<label
class=
"small"
>
Text
</label>
<input
type=
"text"
class=
"input-small"
ng-model=
'currentAnnotation.textFormat'
placeholder=
"instance"
></input>
</div>
</div>
</div>
public/app/plugins/datasource/prometheus/plugin.json
View file @
f8b05e0f
...
@@ -3,5 +3,6 @@
...
@@ -3,5 +3,6 @@
"name"
:
"Prometheus"
,
"name"
:
"Prometheus"
,
"id"
:
"prometheus"
,
"id"
:
"prometheus"
,
"metrics"
:
true
"metrics"
:
true
,
"annotations"
:
true
}
}
public/app/plugins/datasource/prometheus/specs/datasource_specs.ts
View file @
f8b05e0f
...
@@ -157,4 +157,39 @@ describe('PrometheusDatasource', function() {
...
@@ -157,4 +157,39 @@ describe('PrometheusDatasource', function() {
expect
(
results
.
length
).
to
.
be
(
3
);
expect
(
results
.
length
).
to
.
be
(
3
);
});
});
});
});
describe
(
'When performing annotationQuery'
,
function
()
{
var
results
;
var
urlExpected
=
'proxied/api/v1/query_range?query='
+
encodeURIComponent
(
'ALERTS{alertstate="firing"}'
)
+
'&start=1443438675&end=1443460275&step=60s'
;
var
annotation
=
{
expr
:
'ALERTS{alertstate="firing"}'
,
tagKeys
:
'job'
,
titleFormat
:
'{{alertname}}'
,
textFormat
:
'{{instance}}'
};
var
response
=
{
status
:
"success"
,
data
:
{
resultType
:
"matrix"
,
result
:
[{
metric
:
{
"__name__"
:
"ALERTS"
,
alertname
:
"InstanceDown"
,
alertstate
:
"firing"
,
instance
:
"testinstance"
,
job
:
"testjob"
},
values
:
[[
1443454528
,
"1"
]]
}]
}
};
beforeEach
(
function
()
{
ctx
.
$httpBackend
.
expect
(
'GET'
,
urlExpected
).
respond
(
response
);
ctx
.
ds
.
annotationQuery
(
annotation
,
{
from
:
moment
(
1443438674760
),
to
:
moment
(
1443460274760
)}).
then
(
function
(
data
)
{
results
=
data
;
});
ctx
.
$httpBackend
.
flush
();
});
it
(
'should return annotation list'
,
function
()
{
ctx
.
$rootScope
.
$apply
();
expect
(
results
.
length
).
to
.
be
(
1
);
expect
(
results
[
0
].
tags
).
to
.
contain
(
'testjob'
);
expect
(
results
[
0
].
title
).
to
.
be
(
'InstanceDown'
);
expect
(
results
[
0
].
text
).
to
.
be
(
'testinstance'
);
expect
(
results
[
0
].
time
).
to
.
be
(
1443454528
*
1000
);
});
});
});
});
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