-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfnm.js
More file actions
131 lines (126 loc) · 3.44 KB
/
Copy pathfnm.js
File metadata and controls
131 lines (126 loc) · 3.44 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* 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
*/
const db = require('./db')
const getFnms = (req, res, next) => {
const sqlFnm = db.miniQuery('.sql/misc/allFnm.sql')
db.foddb.any(sqlFnm)
.then((d) => {
res.status(200)
.json({
data: d.map((e) => {
return {
type: 'fnms',
id: e.id,
attributes: {
fnmid: e.fnmid,
couuid: e.couuid,
coid: e.coid,
netlist: e.netList,
hostname: e.hostname,
procintraffic: e.procInTraffic,
procouttraffic: e.procOutTraffic,
status: e.status
}
}
}),
meta: {
total: d.length
}
})
})
.catch((err) => {
return next(err.message)
})
}
/* uses default influx and pull from static query file from given url param */
const getSeries = (req, res, next) => {
const 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 * .."}
*/
const getAllSeries = db.miniQuery('.influxql/' + qryfile)
db.influxClient.query(getAllSeries.query)
.then((d) => {
res.status(200)
.json({
series: d,
meta: {
total: d.length
}
})
})
.catch((err) => {
return next(err.message)
})
}
const getSeriesWithTime = (req, res, next) => {
const qryfile = req.params.qryfile + '.sql'
// var topn = parseInt(req.params.num)
const 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((data) => {
res.status(200)
.json({
stamp: data,
meta: {
total: data.length
}
})
})
.catch((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((data) => {
// res.status(200)
// .json({
// stamp: data,
// meta: {
// total: data.length
// }
// })
// })
// .catch((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((data) => {
// res.status(200)
// .json({
// status: 'success',
// data: data,
// size: data.length,
// message: 'Retrieved requested series'
// })
// })
// .catch((err) => {
// return next(err.message)
// })
// }
const fnm = {
getSeries,
getSeriesWithTime,
getFnms
// getOneSeries
}
module.exports = fnm