Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
duniter-currency-monit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Merge Requests
11
Merge Requests
11
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nodes
typescript
modules
duniter-currency-monit
Commits
e88be150
Verified
Commit
e88be150
authored
Jan 20, 2018
by
Éloïs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[enh] add url csvCalculatorsRank
parent
7b1f06df
Pipeline
#715
passed with stage
in 21 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
9 deletions
+73
-9
lib/main.js
lib/main.js
+10
-1
lib/webserver.js
lib/webserver.js
+18
-1
routes/blockCount.js
routes/blockCount.js
+45
-7
No files found.
lib/main.js
View file @
e88be150
"
use strict
"
;
const
co
=
require
(
'
co
'
);
const
os
=
require
(
'
os
'
);
const
fs
=
require
(
'
fs
'
);
const
webserver
=
require
(
__dirname
+
'
/webserver.js
'
);
const
timestampToDatetime
=
require
(
__dirname
+
'
/timestampToDatetime.js
'
);
...
...
@@ -14,6 +16,13 @@ module.exports = (duniterServer, host, port, appParente, program) => co(function
var
x
=
new
Date
();
var
offset
=
-
x
.
getTimezoneOffset
();
//timestampToDatetime(1000000, true, offset);
// Get monitDatasPath
const
mdb
=
program
.
mdb
||
"
duniter_default
"
;
const
monitDatasPath
=
os
.
homedir
()
+
"
/.config/duniter/
"
+
mdb
+
"
/currency-monit/
"
;
// Create monitDatasPath
if
(
!
fs
.
existsSync
(
monitDatasPath
))
{
fs
.
mkdirSync
(
monitDatasPath
)
}
// Define cache
var
cache
=
{
...
...
@@ -39,7 +48,7 @@ module.exports = (duniterServer, host, port, appParente, program) => co(function
console
.
log
(
"
module currency-monit started
"
);
// Specialized node's UI
let
httpServer
=
webserver
(
host
,
port
,
appParente
,
duniterServer
,
offset
,
cache
);
let
httpServer
=
webserver
(
host
,
port
,
appParente
,
duniterServer
,
monitDatasPath
,
offset
,
cache
);
yield
httpServer
.
openConnection
();
})
...
...
lib/webserver.js
View file @
e88be150
...
...
@@ -13,7 +13,7 @@ const bodyParser = require('body-parser');
const
routes
=
require
(
__dirname
+
'
/../routes
'
);
const
tpl
=
require
(
__dirname
+
'
/tplit.js
'
);
module
.
exports
=
(
host
,
port
,
appParente
,
duniterServer
,
offset
,
cache
)
=>
{
module
.
exports
=
(
host
,
port
,
appParente
,
duniterServer
,
monitDatasPath
,
offset
,
cache
)
=>
{
var
app
=
express
();
...
...
@@ -31,6 +31,7 @@ module.exports = (host, port, appParente, duniterServer, offset, cache) => {
app
.
set
(
'
view engine
'
,
'
html
'
)
// register the template engine
app
.
locals
.
duniterServer
=
duniterServer
app
.
locals
.
monitDatasPath
=
monitDatasPath
app
.
locals
.
currencyName
=
duniterServer
.
conf
.
currency
app
.
locals
.
offset
=
offset
app
.
locals
.
cache
=
cache
...
...
@@ -39,6 +40,22 @@ module.exports = (host, port, appParente, duniterServer, offset, cache) => {
app
.
locals
.
HTML_TOR_HEAD
=
fs
.
readFileSync
(
__dirname
+
'
/../views/TOR_HEAD.html
'
,
'
utf-8
'
)
app
.
use
(
routes
)
/***************************************
* CSV des membres calculants
***************************************/
app
.
get
(
'
/csvCalculatorsRank
'
,
function
(
req
,
res
)
{
let
files
=
fs
.
readdirSync
(
monitDatasPath
+
'
/calculators_rank/
'
)
let
maxTimestamp
=
0
for
(
let
file
of
files
)
{
let
fileTimestamp
=
parseInt
(
file
.
split
(
'
_
'
)[
2
])
if
(
fileTimestamp
>
maxTimestamp
)
{
maxTimestamp
=
fileTimestamp
}
}
var
file
=
monitDatasPath
+
'
/calculators_rank/calculators_rank_
'
+
maxTimestamp
+
'
.csv
'
;
res
.
download
(
file
);
// Set disposition and send it.
});
// Si l'on ne dispose pas d'un serveur web parent, lancer notre propre serveur web
if
(
appParente
==
null
)
...
...
routes/blockCount.js
View file @
e88be150
"
use strict
"
;
const
co
=
require
(
'
co
'
)
const
fs
=
require
(
'
fs
'
)
const
timestampToDatetime
=
require
(
__dirname
+
'
/../lib/timestampToDatetime
'
)
const
colorScale
=
require
(
__dirname
+
'
/../lib/colorScale
'
)
const
getLang
=
require
(
__dirname
+
'
/../lib/getLang
'
)
...
...
@@ -12,7 +13,7 @@ var previousBlockchainTime= 0;
module
.
exports
=
(
req
,
res
,
next
)
=>
co
(
function
*
()
{
var
{
duniterServer
}
=
req
.
app
.
locals
var
{
duniterServer
,
monitDatasPath
}
=
req
.
app
.
locals
try
{
// get GET parameters
...
...
@@ -101,22 +102,41 @@ module.exports = (req, res, next) => co(function *() {
{
for
(
let
m
=
0
;
m
<
tabBlockMembers
.
length
;
m
++
)
{
for
(
let
n
=
0
;
n
<
9
;
n
++
)
{
tabCoreCountPerNode
[
m
].
push
(
0
);
tabBlockCountPerNode
[
m
].
push
(
0
);
if
(
data
==
'
meanNonce
'
)
{
tabDataPerNode
[
m
].
push
(
0
);
}
}
for
(
let
n
=
0
;
n
<
9
;
n
++
)
{
tabCoreCountPerNode
[
m
].
push
(
0
);
tabBlockCountPerNode
[
m
].
push
(
0
);
if
(
data
==
'
meanNonce
'
)
{
tabDataPerNode
[
m
].
push
(
0
);
}
}
}
}
// Open a write stream into a new calculators_rank file
let
pathToCalculatorsRankFile
=
monitDatasPath
+
'
calculators_rank/
'
let
calculatorsRankFilename
=
'
calculators_rank_
'
+
Date
.
now
()
+
'
.csv
'
if
(
!
fs
.
existsSync
(
pathToCalculatorsRankFile
))
{
fs
.
mkdirSync
(
pathToCalculatorsRankFile
)
}
var
ws
=
fs
.
createWriteStream
(
pathToCalculatorsRankFile
+
calculatorsRankFilename
,
{
flags
:
'
a
'
,
encoding
:
'
utf8
'
,
fd
:
null
,
mode
:
0o666
,
autoClose
:
true
});
// Calculate the sum of blocks and their nonce and number of core
let
calculatorsCount
=
1
;
for
(
let
b
=
begin
;
b
<
blockchain
.
length
;
b
++
)
{
for
(
let
m
=
0
;
m
<
tabBlockMembers
.
length
;
m
++
)
{
if
(
tabBlockMembers
[
m
].
pubkey
==
blockchain
[
b
].
issuer
)
{
if
(
tabBlockMembers
[
m
].
blockCount
==
0
)
{
//console.log("%s, %s, #%s, %s", calculatorsCount, tabBlockMembers[m].uid, b, timestampToDatetime(blockchain[b].medianTime));
ws
.
write
(
calculatorsCount
+
'
,
'
+
tabBlockMembers
[
m
].
uid
+
'
, #
'
+
b
+
'
,
'
+
timestampToDatetime
(
blockchain
[
b
].
medianTime
)
+
'
\r\n
'
);
calculatorsCount
++
;
}
tabBlockMembers
[
m
].
blockCount
++
;
let
nonce
=
parseInt
((
blockchain
[
b
].
nonce
).
toString
().
substr
(
3
));
if
(
data
==
'
meanNonce
'
)
{
tabBlockMembers
[
m
].
data
+=
nonce
;
}
...
...
@@ -135,6 +155,24 @@ module.exports = (req, res, next) => co(function *() {
}
}
}
// Close write stream into calculators_rank file
ws
.
end
();
// Remove oldest calculators_rank file
let
files
=
fs
.
readdirSync
(
pathToCalculatorsRankFile
);
if
(
files
.
length
>
10
)
{
let
minTimestamp
=
parseInt
(
Date
.
now
())
for
(
let
file
of
files
)
{
let
fileTimestamp
=
parseInt
(
file
.
split
(
'
_
'
)[
2
])
if
(
fileTimestamp
<
minTimestamp
)
{
minTimestamp
=
fileTimestamp
;
}
}
fs
.
unlink
(
pathToCalculatorsRankFile
+
'
calculators_rank_
'
+
minTimestamp
+
'
.csv
'
,
function
(
err
){
if
(
err
)
return
console
.
log
(
err
);
});
}
// Delete non-significant nodes
// A node is considered as significant if its blockCount represents more than 3 % of the total member blockCount
...
...
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