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
7b906aa2
Commit
7b906aa2
authored
Feb 21, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotations refactoring
parent
f0f4c8cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
43 deletions
+58
-43
src/app/services/annotationsSrv.js
+58
-43
No files found.
src/app/services/annotationsSrv.js
View file @
7b906aa2
...
...
@@ -10,6 +10,7 @@ define([
module
.
service
(
'annotationsSrv'
,
function
(
dashboard
,
datasourceSrv
,
$q
,
alertSrv
,
$rootScope
)
{
var
promiseCached
;
var
annotationPanel
;
var
list
=
[];
this
.
init
=
function
()
{
$rootScope
.
$on
(
'refresh'
,
this
.
clearCache
);
...
...
@@ -24,11 +25,12 @@ define([
this
.
clearCache
=
function
()
{
promiseCached
=
null
;
list
=
[];
};
this
.
getAnnotations
=
function
(
rangeUnparsed
)
{
if
(
!
annotationPanel
.
enable
)
{
return
$q
.
when
(
null
);
return
$q
.
when
(
[]
);
}
if
(
promiseCached
)
{
...
...
@@ -39,22 +41,21 @@ define([
var
graphiteEvents
=
this
.
getGraphiteEvents
(
rangeUnparsed
);
promiseCached
=
$q
.
all
([
graphiteMetrics
,
graphiteEvents
])
.
then
(
function
(
allAnnotations
)
{
var
nonNull
=
_
.
filter
(
allAnnotations
,
function
(
value
)
{
return
value
!==
null
;
});
return
_
.
flatten
(
nonNull
);
.
then
(
function
()
{
return
list
;
});
return
promiseCached
;
};
this
.
getGraphiteEvents
=
function
(
rangeUnparsed
)
{
var
annotations
=
_
.
where
(
annotationPanel
.
annotations
,
{
type
:
'graphite events'
,
enable
:
true
});
var
tags
=
_
.
pluck
(
annotations
,
'tags'
);
if
(
tags
.
length
===
0
)
{
var
annotations
=
this
.
getAnnotationsByType
(
'graphite events'
);
if
(
annotations
.
length
===
0
)
{
return
$q
.
when
(
null
);
}
var
tags
=
_
.
pluck
(
annotations
,
'tags'
);
var
eventsQuery
=
{
range
:
rangeUnparsed
,
tags
:
tags
.
join
(
' '
),
...
...
@@ -62,69 +63,83 @@ define([
return
datasourceSrv
.
default
.
events
(
eventsQuery
)
.
then
(
function
(
results
)
{
var
list
=
[];
_
.
each
(
results
.
data
,
function
(
event
)
{
list
.
push
(
createAnnotation
(
annotations
[
0
],
event
.
when
*
1000
,
event
.
what
,
event
.
tags
,
event
.
data
));
});
return
list
;
})
.
then
(
null
,
function
()
{
alertSrv
.
set
(
'Annotations'
,
'Could not fetch annotations'
,
'error'
);
});
.
then
(
null
,
errorHandler
);
};
this
.
get
GraphiteMetrics
=
function
(
rangeUnparsed
)
{
var
graphiteAnnotations
=
_
.
where
(
annotationPanel
.
annotations
,
{
type
:
'graphite metric'
,
enable
:
true
});
var
graphiteTargets
=
_
.
map
(
graphiteAnnotations
,
function
(
annotation
)
{
return
{
target
:
annotation
.
target
};
this
.
get
AnnotationsByType
=
function
(
type
)
{
return
_
.
where
(
annotationPanel
.
annotations
,
{
type
:
type
,
enable
:
true
});
};
if
(
graphiteTargets
.
length
===
0
)
{
this
.
getGraphiteMetrics
=
function
(
rangeUnparsed
)
{
var
annotations
=
this
.
getAnnotationsByType
(
'graphite metric'
);
if
(
annotations
.
length
===
0
)
{
return
$q
.
when
(
null
);
}
var
promises
=
_
.
map
(
annotations
,
function
(
annotation
)
{
var
graphiteQuery
=
{
range
:
rangeUnparsed
,
targets
:
graphiteTargets
,
targets
:
[{
target
:
annotation
.
target
}]
,
format
:
'json'
,
maxDataPoints
:
100
};
return
datasourceSrv
.
default
.
query
(
graphiteQuery
)
.
then
(
function
(
results
)
{
return
_
.
reduce
(
results
.
data
,
function
(
list
,
target
)
{
_
.
each
(
target
.
datapoints
,
function
(
values
)
{
if
(
values
[
0
]
===
null
)
{
return
;
}
var
receiveFunc
=
_
.
partial
(
receiveGraphiteMetrics
,
annotation
);
list
.
push
(
createAnnotation
(
graphiteAnnotations
[
0
],
values
[
1
]
*
1000
,
target
.
target
));
return
datasourceSrv
.
default
.
query
(
graphiteQuery
)
.
then
(
receiveFunc
)
.
then
(
null
,
errorHandler
);
});
return
list
;
},
[]);
})
.
then
(
null
,
function
()
{
alertSrv
.
set
(
'Annotations'
,
'Could not fetch annotations'
,
'error'
);
});
return
$q
.
all
(
promises
);
};
function
createAnnotation
(
annotation
,
time
,
description
,
tags
,
data
)
{
var
tooltip
=
"<small><b>"
+
description
+
"</b><br/>"
;
if
(
tags
)
{
tooltip
+=
(
tags
||
''
)
+
'<br/>'
;
function
errorHandler
(
err
)
{
console
.
log
(
'Annotation error: '
,
err
);
alertSrv
.
set
(
'Annotations'
,
'Could not fetch annotations'
,
'error'
);
}
tooltip
+=
'<i>'
+
moment
(
time
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
+
'</i><br/>'
;
if
(
data
)
{
function
receiveGraphiteMetrics
(
annotation
,
results
)
{
for
(
var
i
=
0
;
i
<
results
.
data
.
length
;
i
++
)
{
var
target
=
results
.
data
[
i
];
for
(
var
y
=
0
;
y
<
target
.
datapoints
.
length
;
y
++
)
{
var
datapoint
=
target
.
datapoints
[
y
];
if
(
datapoint
[
0
]
!==
null
)
{
list
.
push
(
createAnnotation
({
annotation
:
annotation
,
time
:
datapoint
[
1
]
*
1000
,
description
:
target
.
target
}));
}
}
}
}
function
createAnnotation
(
options
)
{
var
tooltip
=
"<small><b>"
+
options
.
description
+
"</b><br/>"
;
if
(
options
.
tags
)
{
tooltip
+=
(
options
.
tags
||
''
)
+
'<br/>'
;
}
tooltip
+=
'<i>'
+
moment
(
options
.
time
).
format
(
'YYYY-MM-DD HH:mm:ss'
)
+
'</i><br/>'
;
if
(
options
.
data
)
{
tooltip
+=
data
;
}
tooltip
+=
"</small>"
;
return
{
annotation
:
annotation
,
min
:
time
,
max
:
time
,
eventType
:
annotation
.
name
,
annotation
:
options
.
annotation
,
min
:
options
.
time
,
max
:
options
.
time
,
eventType
:
options
.
annotation
.
name
,
title
:
null
,
description
:
tooltip
,
score
:
1
...
...
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