Skip to content

Commit

Permalink
added filesize from objecttypes
Browse files Browse the repository at this point in the history
  • Loading branch information
StiftungAusNachlass committed Sep 4, 2024
1 parent 12ec628 commit c5a10b6
Showing 1 changed file with 88 additions and 10 deletions.
98 changes: 88 additions & 10 deletions src/server/extension/monitoring-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,50 @@ process.stdin.on('end', () => {
});
});
}

function getObjecttypeStatsFromAPI() {
return new Promise((resolve, reject) => {
fetch('http://fylr.localhost:8081/api/v1/objecttype?access_token=' + access_token, {
headers: {
'Accept': 'application/json'
},
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error("Fehler bei der Anfrage an /inspect/objecttypes/");
}
})
.then(objecttypes => {
objecttypes = objecttypes.map((objecttype) => objecttype.objecttype.name);
let statsPromises = objecttypes.map(objecttype => {
let url = `http://fylr.localhost:8082/inspect/objecttypes/${objecttype}/`;
return fetch(url, {
headers: {
'Accept': 'application/json'
},
})
.then(response => {
if (response.ok) {
return response.json();
} else {
throw new Error(`Fehler bei der Anfrage an /inspect/objecttypes/${objecttype}/`);
}
});
});
return Promise.all(statsPromises);
})
.then(allStats => {
resolve(allStats);
})
.catch(error => {
console.log(error);
throwError("Fehler bei der Anfrage an /inspect/objecttypes/ oder /objecttype/stats ", "");
});
});
}


async function fetchData() {
const infoData = await Promise.all([
Expand All @@ -248,11 +292,12 @@ process.stdin.on('end', () => {
getPluginInfoFromAPI(),
getConfigFromAPI(),
getConfigFromInspectAPI(),
getPoolStatsFromAPI()
getPoolStatsFromAPI(),
getObjecttypeStatsFromAPI()
]);

let configinfo = infoData[6];

//////////////////////////////////////////////////////////////
// email-configs
result.email = {};
Expand Down Expand Up @@ -489,20 +534,53 @@ process.stdin.on('end', () => {
result.pluginsAllEnabled = false;
result.pluginsDisabled = disabledPlugins;
}

// poolstats

// filestats
result.file_stats = {};
result.file_stats.count = 0;
result.file_stats.size = 0;

// from pool
if (infoData[8]) {
if (infoData[8].PoolStatsSubpools) {
result.file_stats = {};
result.file_stats.count = infoData[8].PoolStatsSubpools.files.count;
var sizeString = (infoData[8].PoolStatsSubpools.files.size / (1024 ** 3)).toFixed(2) + ' GB';
if(sizeString == '0.00 GB') {
sizeString = (infoData[8].PoolStatsSubpools.files.size / (1024 ** 2)).toFixed(2) + ' MB';
}
result.file_stats.size = sizeString;
result.file_stats.size = infoData[8].PoolStatsSubpools.files.size;
}
}

// from objecttype
if(infoData[9].length > 0) {
let otCount = 0;
let otSize = 0;
for(let i=0;i<infoData[9].length;i++){
if(infoData[9][i].OtStats) {
if(infoData[9][i].OtStats.files) {
if(infoData[9][i].OtStats.files.size) {
var size = infoData[9][i].OtStats.files.size;
var count = infoData[9][i].OtStats.files.count;
if(count) {
otCount += count;
}
if(size != 0) {
otSize = otSize + size;
}
}
}
}
}
result.file_stats.count += otCount;
result.file_stats.size += otSize;
}

if(result.file_stats.count > 0) {
var sizeString = (result.file_stats.size / (1024 ** 3)).toFixed(2) + ' GB';
if(sizeString == '0.00 GB') {
sizeString = (result.file_stats.size / (1024 ** 2)).toFixed(2) + ' MB';
}
result.file_stats.size = sizeString;
}


// parse info from settings (via session)
result.name = sessionData.instance.name;
result.external_url = info.external_url;
Expand Down

0 comments on commit c5a10b6

Please sign in to comment.