Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newhet
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
newhet
Commits
dac7026e
Commit
dac7026e
authored
Dec 04, 2019
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jkjk
parent
32b57214
Pipeline
#18
failed with stages
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
app.js
app.js
+53
-1
package.json
package.json
+1
-0
No files found.
app.js
View file @
dac7026e
...
@@ -5,7 +5,9 @@ const shell = require('shelljs')
...
@@ -5,7 +5,9 @@ const shell = require('shelljs')
const
cron
=
require
(
'
node-cron
'
);
const
cron
=
require
(
'
node-cron
'
);
const
cronRemover
=
require
(
'
node-cron
'
);
const
cronRemover
=
require
(
'
node-cron
'
);
const
fs
=
require
(
'
fs
'
)
const
fs
=
require
(
'
fs
'
)
const
cronSpeed
=
require
(
'
node-cron
'
);
const
shellExec
=
require
(
'
shell-exec
'
)
var
decimalPointRegex
=
/
\-?\d
+
\.\d
+/g
;
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
res
.
send
(
'
Hello World!
'
)
res
.
send
(
'
Hello World!
'
)
run
()
run
()
...
@@ -113,3 +115,53 @@ function getIp() {
...
@@ -113,3 +115,53 @@ function getIp() {
});
});
}
}
async
function
calculateSpeed
()
{
let
d
=
await
shellExec
(
'
vnstat -tr
'
)
d
=
d
.
stdout
d
=
d
.
match
(
decimalPointRegex
)
if
(
d
.
includes
(
'
kbit/s
'
))
{
d
[
0
]
=
1
d
[
1
]
=
1
}
else
if
(
d
.
includes
(
'
Mbit/s
'
))
{
}
else
if
(
d
.
includes
(
'
Gbit/s
'
))
{
d
[
0
]
=
d
[
0
]
*
1000
d
[
1
]
=
d
[
1
]
*
1000
}
else
if
(
d
.
includes
(
'
bit/s
'
))
{
d
[
0
]
=
1
d
[
1
]
=
1
}
await
sendRate
(
d
[
0
],
d
[
1
])
}
function
sendRate
(
rx
,
tx
)
{
const
request
=
require
(
'
request
'
);
let
url
=
'
http://admin.fcfglobal.co:3000/rate/
'
+
rx
+
'
/
'
+
tx
return
new
Promise
(
function
(
resolve
,
reject
)
{
request
(
url
,
{
timeout
:
6000
},
function
(
error
,
res
,
body
)
{
resolve
(
true
)
});
});
}
cronSpeed
.
schedule
(
'
*/5 * * * * *
'
,
()
=>
{
return
calculateSpeed
()
});
package.json
View file @
dac7026e
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
"
lodash
"
:
"
^4.17.15
"
,
"
lodash
"
:
"
^4.17.15
"
,
"
node-cron
"
:
"
^2.0.3
"
,
"
node-cron
"
:
"
^2.0.3
"
,
"
request
"
:
"
^2.88.0
"
,
"
request
"
:
"
^2.88.0
"
,
"
shell-exec
"
:
"
^1.0.2
"
,
"
shelljs
"
:
"
^0.8.3
"
"
shelljs
"
:
"
^0.8.3
"
}
}
}
}
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