Browse Source

add stats

master
zeus 4 years ago
parent
commit
d017f42bf3
  1. 35
      llo/connect-new.js
  2. 1
      package.json
  3. 6
      start
  4. 8
      start-venus-stats

35
llo/connect-new.js

@ -268,6 +268,38 @@ export NODE_PATH=$(npm root --quiet -g)
*/ */
try { try {
var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8')) var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8'))
try {
var MongoClient = require('mongodb').MongoClient;
var mongourl = `mongodb://${mongoserver.mongo_user}:${mongoserver.mongo_pass}@${mongoserver.mongo_ip}:${mongoserver.mongo_port}`;
const OPTS = {
useNewUrlParser: true,
useUnifiedTopology: true
};
MongoClient.connect(mongourl, OPTS, function(err, db) {
if(err){
console.log(err);
} else {
var dbo = db.db(mongoserver.mongo_db);
//var findcoll = `{"stackid":"${res.bootstrapstackid}"}`
//{EmployeeName : {$regex: "Gu" }}
var limit = 15
dbo.collection(mongoserver.mongo_coll).find({"stackid":res.bootstrapstackid},{sort:{_id:-1}}).limit(limit).toArray(function(err, result) {
if(err){
console.log(err);
} else {
console.log(result);
db.close();
}
});
}
});
} catch (err) {
console.error(err);
}
const myExec = ` const myExec = `
docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}" docker exec -it swarmlabwg-${res.bootstrapstackid} /bin/bash -c "ip link set ${DEV_NAME} down; ip link del ${DEV_NAME}"
sleep 1 sleep 1
@ -392,10 +424,8 @@ app.post('/hybrid_join_connect', (req, res, next) => {
if(RES.action == "connect"){ if(RES.action == "connect"){
fs.writeFileSync(`./hybrid/connect/${RES.bootstrapstackid}/swarmlabstatus`, 'wgstatusclient=on'); fs.writeFileSync(`./hybrid/connect/${RES.bootstrapstackid}/swarmlabstatus`, 'wgstatusclient=on');
var showexecrm = `/bin/sh ./hybrid/connect/${RES.bootstrapstackid}/swarmlabwg` var showexecrm = `/bin/sh ./hybrid/connect/${RES.bootstrapstackid}/swarmlabwg`
execSync(showexecrm); execSync(showexecrm);
var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s ` var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s `
exec(showexec, (err, stdout, stderr) => { exec(showexec, (err, stdout, stderr) => {
if (err) { if (err) {
@ -419,7 +449,6 @@ app.post('/hybrid_join_connect', (req, res, next) => {
} }
RES.debug = datajson RES.debug = datajson
if(results){ if(results){
RES.error = false RES.error = false
RES.error_msg = "ok" RES.error_msg = "ok"

1
package.json

@ -12,6 +12,7 @@
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.1", "express": "^4.17.1",
"helmet": "^4.1.1", "helmet": "^4.1.1",
"mongodb": "^3.6.6",
"pm2": "^4.5.1", "pm2": "^4.5.1",
"read-last-lines": "^1.7.2", "read-last-lines": "^1.7.2",
"simple-git": "^2.31.0", "simple-git": "^2.31.0",

6
start

@ -27,12 +27,14 @@ if [ "$cwdir" != "$wdir" ]; then
cd $wdir cd $wdir
fi fi
sudo /bin/bash ./hybrid/connect/get-swarmlab-ca > /dev/null 2>&1 sudo /bin/bash $wdir/hybrid/connect/get-swarmlab-ca > /dev/null 2>&1
sudo /bin/bash ./hybrid/connect/get-base-ca > /dev/null 2>&1 sudo /bin/bash $wdir/hybrid/connect/get-base-ca > /dev/null 2>&1
./update-agent.sh ./update-agent.sh
docker pull hub.swarmlab.io:5480/venusclient:latest docker pull hub.swarmlab.io:5480/venusclient:latest
bash ./start-venus-stats
pm2 stop venusclient > /dev/null 2>&1 pm2 stop venusclient > /dev/null 2>&1
sleep 1 sleep 1
pm2 start ecosystem.config.js --watch --ignore-watch="node_modules" > /dev/null 2>&1 pm2 start ecosystem.config.js --watch --ignore-watch="node_modules" > /dev/null 2>&1

8
start-venus-stats

@ -27,6 +27,8 @@ if [ "$cwdir" != "$wdir" ]; then
cd $wdir cd $wdir
fi fi
#echo $wdir
# #
#files/mongo/ #files/mongo/
# docker-compose.yml # docker-compose.yml
@ -58,7 +60,7 @@ fi
cp -raf $wdir/files/mongo/wg-json $wdir/hybrid/venus-stats cp -raf $wdir/files/mongo/wg-json $wdir/hybrid/venus-stats
cp -raf $wdir/files/mongo/mongod.conf $wdir/hybrid/venus-stats cp -raf $wdir/files/mongo/mongod.conf $wdir/hybrid/venus-stats
cp -raf $wdir/files/mongo/docker-compose.yml $wdir/hybrid/venus-stats cp -raf $wdir/files/mongo/docker-compose.yml $wdir/hybrid/venus-stats
cp -raf $wdir/files/mongo/files/mongo/venus-stats.js $wdir/hybrid/venus-stats cp -raf $wdir/files/mongo/venus-stats.js $wdir/hybrid/venus-stats
swuser=swarmlab swuser=swarmlab
@ -125,3 +127,7 @@ setconfig=$(jq \
echo $setconfig > $wdir/hybrid/venus-stats/config.json echo $setconfig > $wdir/hybrid/venus-stats/config.json
cd ./hybrid/venus-stats/
./start
cd $wdir

Loading…
Cancel
Save