forked from deic-dk-retired/ddosapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfnm.js
96 lines (93 loc) · 2.76 KB
/
fnm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* 1. Use a influx query file. Parse and pass the query to curl and retrieve data.
* Expose tis function to be used in router.
* 2. Build dynamic influx queries using influxdb-nodejs api
*/
var db = require('./db')
/* uses default influx and pull from static query file from given url param */
function getSeries (req, res, next) {
var qryfile = req.params.qryfile + '.sql'
/**
* store minified queryfile object into a variable
* QueryFile { file: "filename.sql", options: {"debug":false,"minify":true,"compress":false}, query: "select * .."}
*/
var getAllSeries = db.miniQuery('.influxql/' + qryfile)
db.influxClient.query(getAllSeries.query)
.then(function (data) {
res.status(200)
.json({
stamp: data,
meta: {
total: data.length
}
})
})
.catch(function (err) {
return next(err.message)
})
}
function getSeriesWithTime (req, res, next) {
var qryfile = req.params.qryfile + '.sql'
// var topn = parseInt(req.params.num)
var getAllSeries = db.miniQuery('.influxql/' + qryfile)
/**
* from nth day to n-x days going backwards e.g. 5days ago to 6days ago gives data for 6 days ago thus
* "tmfrm < tuntil"
*/
db.influxnodeClient.query(getAllSeries.query)
.then(function (data) {
res.status(200)
.json({
stamp: data,
meta: {
total: data.length
}
})
})
.catch(function (err) {
return next(err.message)
})
// db.influxnodeClient.query('hosts')
// .where('resource', 'bps')
// .where('direction', 'incoming')
// .where('time', 'now() - 0', '<')
// .where('time', 'now() - 30m', '>')
// .addFunction('top', 'value', 20)
// .then(function (data) {
// res.status(200)
// .json({
// stamp: data,
// meta: {
// total: data.length
// }
// })
// })
// .catch(function (err) {
// return next(err.message)
// })
}
/**
* use npm influxdb-nodejs to fetch results using queryRaw()
*/
// function getOneSeries (req, res, next) {
// // var qryfile = req.params.qryfile + '.sql'
// // var getAllSeries = db.miniQuery('.influxql/' + qryfile)
// db.influxnodeClient.queryRaw('select max(value::float) from graphite.autogen.hosts where direction = \'incoming\' and time > now() - 25d group by resource, time(5d) order by time desc')
// .then(function (data) {
// res.status(200)
// .json({
// status: 'success',
// data: data,
// size: data.length,
// message: 'Retrieved requested series'
// })
// })
// .catch(function (err) {
// return next(err.message)
// })
// }
module.exports = {
getSeries: getSeries,
getSeriesWithTime: getSeriesWithTime
// getOneSeries: getOneSeries
}