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
528f5415
Commit
528f5415
authored
Feb 26, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More work on experimental InfluxDB 0.9 support
parent
ae7f18f9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
179 deletions
+14
-179
src/app/features/influxdb/datasource.js
+1
-176
src/app/features/influxdb/influxSeries.js
+11
-1
src/app/features/influxdb_08/datasource.js
+2
-2
No files found.
src/app/features/influxdb/datasource.js
View file @
528f5415
...
...
@@ -25,10 +25,6 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
this
.
name
=
datasource
.
name
;
this
.
database
=
datasource
.
database
;
this
.
basicAuth
=
datasource
.
basicAuth
;
this
.
grafanaDB
=
datasource
.
grafanaDB
;
this
.
saveTemp
=
_
.
isUndefined
(
datasource
.
save_temp
)
?
true
:
datasource
.
save_temp
;
this
.
saveTempTTL
=
_
.
isUndefined
(
datasource
.
save_temp_ttl
)
?
'30d'
:
datasource
.
save_temp_ttl
;
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
...
...
@@ -196,177 +192,6 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
return
deferred
.
promise
;
};
InfluxDatasource
.
prototype
.
saveDashboard
=
function
(
dashboard
)
{
var
tags
=
dashboard
.
tags
.
join
(
','
);
var
title
=
dashboard
.
title
;
var
temp
=
dashboard
.
temp
;
var
id
=
kbn
.
slugifyForUrl
(
title
);
if
(
temp
)
{
delete
dashboard
.
temp
;
}
var
data
=
[{
name
:
'grafana.dashboard_'
+
btoa
(
id
),
columns
:
[
'time'
,
'sequence_number'
,
'title'
,
'tags'
,
'dashboard'
,
'id'
],
points
:
[[
1000000000000
,
1
,
title
,
tags
,
angular
.
toJson
(
dashboard
),
id
]]
}];
if
(
temp
)
{
return
this
.
_saveDashboardTemp
(
data
,
title
,
id
);
}
else
{
var
self
=
this
;
return
this
.
_influxRequest
(
'POST'
,
'/series'
,
data
).
then
(
function
()
{
self
.
_removeUnslugifiedDashboard
(
id
,
title
,
false
);
return
{
title
:
title
,
url
:
'/dashboard/db/'
+
id
};
},
function
(
err
)
{
throw
'Failed to save dashboard to InfluxDB: '
+
err
.
data
;
});
}
};
InfluxDatasource
.
prototype
.
_removeUnslugifiedDashboard
=
function
(
id
,
title
,
isTemp
)
{
if
(
id
===
title
)
{
return
;
}
var
self
=
this
;
self
.
_getDashboardInternal
(
title
,
isTemp
).
then
(
function
(
dashboard
)
{
if
(
dashboard
!==
null
)
{
self
.
deleteDashboard
(
title
);
}
});
};
InfluxDatasource
.
prototype
.
_saveDashboardTemp
=
function
(
data
,
title
,
id
)
{
data
[
0
].
name
=
'grafana.temp_dashboard_'
+
btoa
(
id
);
data
[
0
].
columns
.
push
(
'expires'
);
data
[
0
].
points
[
0
].
push
(
this
.
_getTempDashboardExpiresDate
());
return
this
.
_influxRequest
(
'POST'
,
'/series'
,
data
).
then
(
function
()
{
var
baseUrl
=
window
.
location
.
href
.
replace
(
window
.
location
.
hash
,
''
);
var
url
=
baseUrl
+
"#dashboard/temp/"
+
id
;
return
{
title
:
title
,
url
:
url
};
},
function
(
err
)
{
throw
'Failed to save shared dashboard to InfluxDB: '
+
err
.
data
;
});
};
InfluxDatasource
.
prototype
.
_getTempDashboardExpiresDate
=
function
()
{
var
ttlLength
=
this
.
saveTempTTL
.
substring
(
0
,
this
.
saveTempTTL
.
length
-
1
);
var
ttlTerm
=
this
.
saveTempTTL
.
substring
(
this
.
saveTempTTL
.
length
-
1
,
this
.
saveTempTTL
.
length
).
toLowerCase
();
var
expires
=
Date
.
now
();
switch
(
ttlTerm
)
{
case
"m"
:
expires
+=
ttlLength
*
60000
;
break
;
case
"d"
:
expires
+=
ttlLength
*
86400000
;
break
;
case
"w"
:
expires
+=
ttlLength
*
604800000
;
break
;
default
:
throw
"Unknown ttl duration format"
;
}
return
expires
;
};
InfluxDatasource
.
prototype
.
_getDashboardInternal
=
function
(
id
,
isTemp
)
{
var
queryString
=
'select dashboard from "grafana.dashboard_'
+
btoa
(
id
)
+
'"'
;
if
(
isTemp
)
{
queryString
=
'select dashboard from "grafana.temp_dashboard_'
+
btoa
(
id
)
+
'"'
;
}
return
this
.
_seriesQuery
(
queryString
).
then
(
function
(
results
)
{
if
(
!
results
||
!
results
.
length
)
{
return
null
;
}
var
dashCol
=
_
.
indexOf
(
results
[
0
].
columns
,
'dashboard'
);
var
dashJson
=
results
[
0
].
points
[
0
][
dashCol
];
return
angular
.
fromJson
(
dashJson
);
},
function
()
{
return
null
;
});
};
InfluxDatasource
.
prototype
.
getDashboard
=
function
(
id
,
isTemp
)
{
var
self
=
this
;
return
this
.
_getDashboardInternal
(
id
,
isTemp
).
then
(
function
(
dashboard
)
{
if
(
dashboard
!==
null
)
{
return
dashboard
;
}
// backward compatible load for unslugified ids
var
slug
=
kbn
.
slugifyForUrl
(
id
);
if
(
slug
!==
id
)
{
return
self
.
getDashboard
(
slug
,
isTemp
);
}
throw
"Dashboard not found"
;
},
function
(
err
)
{
throw
"Could not load dashboard, "
+
err
.
data
;
});
};
InfluxDatasource
.
prototype
.
deleteDashboard
=
function
(
id
)
{
return
this
.
_seriesQuery
(
'drop series "grafana.dashboard_'
+
btoa
(
id
)
+
'"'
).
then
(
function
(
results
)
{
if
(
!
results
)
{
throw
"Could not delete dashboard"
;
}
return
id
;
},
function
(
err
)
{
throw
"Could not delete dashboard, "
+
err
.
data
;
});
};
InfluxDatasource
.
prototype
.
searchDashboards
=
function
(
queryString
)
{
var
influxQuery
=
'select * from /grafana.dashboard_.*/ where '
;
var
tagsOnly
=
queryString
.
indexOf
(
'tags!:'
)
===
0
;
if
(
tagsOnly
)
{
var
tagsQuery
=
queryString
.
substring
(
6
,
queryString
.
length
);
influxQuery
=
influxQuery
+
'tags =~ /.*'
+
tagsQuery
+
'.*/i'
;
}
else
{
var
titleOnly
=
queryString
.
indexOf
(
'title:'
)
===
0
;
if
(
titleOnly
)
{
var
titleQuery
=
queryString
.
substring
(
6
,
queryString
.
length
);
influxQuery
=
influxQuery
+
' title =~ /.*'
+
titleQuery
+
'.*/i'
;
}
else
{
influxQuery
=
influxQuery
+
'(tags =~ /.*'
+
queryString
+
'.*/i or title =~ /.*'
+
queryString
+
'.*/i)'
;
}
}
return
this
.
_seriesQuery
(
influxQuery
).
then
(
function
(
results
)
{
var
hits
=
{
dashboards
:
[],
tags
:
[],
tagsOnly
:
false
};
if
(
!
results
||
!
results
.
length
)
{
return
hits
;
}
for
(
var
i
=
0
;
i
<
results
.
length
;
i
++
)
{
var
dashCol
=
_
.
indexOf
(
results
[
i
].
columns
,
'title'
);
var
tagsCol
=
_
.
indexOf
(
results
[
i
].
columns
,
'tags'
);
var
idCol
=
_
.
indexOf
(
results
[
i
].
columns
,
'id'
);
var
hit
=
{
id
:
results
[
i
].
points
[
0
][
dashCol
],
title
:
results
[
i
].
points
[
0
][
dashCol
],
tags
:
results
[
i
].
points
[
0
][
tagsCol
].
split
(
","
)
};
if
(
idCol
!==
-
1
)
{
hit
.
id
=
results
[
i
].
points
[
0
][
idCol
];
}
hit
.
tags
=
hit
.
tags
[
0
]
?
hit
.
tags
:
[];
hits
.
dashboards
.
push
(
hit
);
}
return
hits
;
});
};
function
handleInfluxQueryResponse
(
alias
,
seriesList
)
{
var
influxSeries
=
new
InfluxSeries
({
seriesList
:
seriesList
,
alias
:
alias
});
return
influxSeries
.
getTimeSeries
();
...
...
@@ -386,7 +211,7 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
function
getInfluxTime
(
date
)
{
if
(
_
.
isString
(
date
))
{
return
date
.
replace
(
'now'
,
'now()'
);
return
date
.
replace
(
'now'
,
'now()'
)
.
replace
(
'-'
,
' - '
)
;
}
return
to_utc_epoch_seconds
(
date
);
...
...
src/app/features/influxdb/influxSeries.js
View file @
528f5415
...
...
@@ -28,7 +28,17 @@ function (_) {
for
(
var
i
=
0
;
i
<
series
.
values
.
length
;
i
++
)
{
datapoints
[
i
]
=
[
series
.
values
[
i
][
1
],
new
Date
(
series
.
values
[
i
][
0
]).
getTime
()];
}
output
.
push
({
target
:
series
.
name
,
datapoints
:
datapoints
});
var
seriesName
=
series
.
name
;
var
tags
=
_
.
map
(
series
.
tags
,
function
(
value
,
key
)
{
return
key
+
': '
+
value
;
});
if
(
tags
.
length
>
0
)
{
seriesName
=
seriesName
+
' {'
+
tags
.
join
(
', '
)
+
'}'
;
}
output
.
push
({
target
:
seriesName
,
datapoints
:
datapoints
});
});
return
output
;
...
...
src/app/features/influxdb_08/datasource.js
View file @
528f5415
...
...
@@ -30,8 +30,8 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
this
.
supportAnnotations
=
true
;
this
.
supportMetrics
=
true
;
this
.
editorSrc
=
'app/features/influxdb/partials/query.editor.html'
;
this
.
annotationEditorSrc
=
'app/features/influxdb/partials/annotations.editor.html'
;
this
.
editorSrc
=
'app/features/influxdb
_08
/partials/query.editor.html'
;
this
.
annotationEditorSrc
=
'app/features/influxdb
_08
/partials/annotations.editor.html'
;
}
InfluxDatasource
.
prototype
.
query
=
function
(
options
)
{
...
...
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