|
|
@ -1,7 +1,10 @@ |
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
import { PropertyService } from '@ghostfolio/api/services/property/property.service'; |
|
|
import { |
|
|
import { |
|
|
GATHER_STATISTICS_PROCESS_JOB_NAME, |
|
|
GATHER_STATISTICS_DOCKER_HUB_PULLS_PROCESS_JOB_NAME, |
|
|
|
|
|
GATHER_STATISTICS_GITHUB_CONTRIBUTORS_PROCESS_JOB_NAME, |
|
|
|
|
|
GATHER_STATISTICS_GITHUB_STARGAZERS_PROCESS_JOB_NAME, |
|
|
|
|
|
GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME, |
|
|
HEADER_KEY_TOKEN, |
|
|
HEADER_KEY_TOKEN, |
|
|
PROPERTY_BETTER_UPTIME_MONITOR_ID, |
|
|
PROPERTY_BETTER_UPTIME_MONITOR_ID, |
|
|
PROPERTY_DOCKER_HUB_PULLS, |
|
|
PROPERTY_DOCKER_HUB_PULLS, |
|
|
@ -28,46 +31,82 @@ export class StatisticsGatheringProcessor { |
|
|
private readonly propertyService: PropertyService |
|
|
private readonly propertyService: PropertyService |
|
|
) {} |
|
|
) {} |
|
|
|
|
|
|
|
|
@Process(GATHER_STATISTICS_PROCESS_JOB_NAME) |
|
|
@Process(GATHER_STATISTICS_DOCKER_HUB_PULLS_PROCESS_JOB_NAME) |
|
|
public async gatherStatistics() { |
|
|
public async gatherDockerHubPullsStatistics() { |
|
|
Logger.log( |
|
|
Logger.log( |
|
|
'Statistics gathering has been started', |
|
|
'Docker Hub pulls statistics gathering has been started', |
|
|
'StatisticsGatheringProcessor' |
|
|
'StatisticsGatheringProcessor' |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
const [dockerHubPulls, gitHubContributors, gitHubStargazers, uptime] = |
|
|
const dockerHubPulls = await this.countDockerHubPulls(); |
|
|
await Promise.all([ |
|
|
|
|
|
this.countDockerHubPulls(), |
|
|
await this.propertyService.put({ |
|
|
this.countGitHubContributors(), |
|
|
key: PROPERTY_DOCKER_HUB_PULLS, |
|
|
this.countGitHubStargazers(), |
|
|
value: String(dockerHubPulls) |
|
|
this.getUptime() |
|
|
}); |
|
|
]); |
|
|
|
|
|
|
|
|
Logger.log( |
|
|
await Promise.all([ |
|
|
'Docker Hub pulls statistics gathering has been completed', |
|
|
dockerHubPulls !== undefined && |
|
|
'StatisticsGatheringProcessor' |
|
|
this.propertyService.put({ |
|
|
); |
|
|
key: PROPERTY_DOCKER_HUB_PULLS, |
|
|
} |
|
|
value: String(dockerHubPulls) |
|
|
|
|
|
}), |
|
|
@Process(GATHER_STATISTICS_GITHUB_CONTRIBUTORS_PROCESS_JOB_NAME) |
|
|
gitHubContributors !== undefined && |
|
|
public async gatherGitHubContributorsStatistics() { |
|
|
this.propertyService.put({ |
|
|
Logger.log( |
|
|
key: PROPERTY_GITHUB_CONTRIBUTORS, |
|
|
'GitHub contributors statistics gathering has been started', |
|
|
value: String(gitHubContributors) |
|
|
'StatisticsGatheringProcessor' |
|
|
}), |
|
|
); |
|
|
gitHubStargazers !== undefined && |
|
|
|
|
|
this.propertyService.put({ |
|
|
const gitHubContributors = await this.countGitHubContributors(); |
|
|
key: PROPERTY_GITHUB_STARGAZERS, |
|
|
|
|
|
value: String(gitHubStargazers) |
|
|
await this.propertyService.put({ |
|
|
}), |
|
|
key: PROPERTY_GITHUB_CONTRIBUTORS, |
|
|
uptime !== undefined && |
|
|
value: String(gitHubContributors) |
|
|
this.propertyService.put({ |
|
|
}); |
|
|
key: PROPERTY_UPTIME, |
|
|
|
|
|
value: String(uptime) |
|
|
Logger.log( |
|
|
}) |
|
|
'GitHub contributors statistics gathering has been completed', |
|
|
]); |
|
|
'StatisticsGatheringProcessor' |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Process(GATHER_STATISTICS_GITHUB_STARGAZERS_PROCESS_JOB_NAME) |
|
|
|
|
|
public async gatherGitHubStargazersStatistics() { |
|
|
|
|
|
Logger.log( |
|
|
|
|
|
'GitHub stargazers statistics gathering has been started', |
|
|
|
|
|
'StatisticsGatheringProcessor' |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const gitHubStargazers = await this.countGitHubStargazers(); |
|
|
|
|
|
|
|
|
|
|
|
await this.propertyService.put({ |
|
|
|
|
|
key: PROPERTY_GITHUB_STARGAZERS, |
|
|
|
|
|
value: String(gitHubStargazers) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Logger.log( |
|
|
|
|
|
'GitHub stargazers statistics gathering has been completed', |
|
|
|
|
|
'StatisticsGatheringProcessor' |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Process(GATHER_STATISTICS_UPTIME_PROCESS_JOB_NAME) |
|
|
|
|
|
public async gatherUptimeStatistics() { |
|
|
|
|
|
Logger.log( |
|
|
|
|
|
'Uptime statistics gathering has been started', |
|
|
|
|
|
'StatisticsGatheringProcessor' |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const uptime = await this.getUptime(); |
|
|
|
|
|
|
|
|
|
|
|
await this.propertyService.put({ |
|
|
|
|
|
key: PROPERTY_UPTIME, |
|
|
|
|
|
value: String(uptime) |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
Logger.log( |
|
|
Logger.log( |
|
|
'Statistics gathering has been completed', |
|
|
'Uptime statistics gathering has been completed', |
|
|
'StatisticsGatheringProcessor' |
|
|
'StatisticsGatheringProcessor' |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
@ -88,7 +127,7 @@ export class StatisticsGatheringProcessor { |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - DockerHub'); |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - DockerHub'); |
|
|
|
|
|
|
|
|
return undefined; |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -102,15 +141,29 @@ export class StatisticsGatheringProcessor { |
|
|
|
|
|
|
|
|
const $ = cheerio.load(body); |
|
|
const $ = cheerio.load(body); |
|
|
|
|
|
|
|
|
return extractNumberFromString({ |
|
|
console.log( |
|
|
value: $( |
|
|
$( |
|
|
'a[href="/ghostfolio/ghostfolio/graphs/contributors"] .Counter' |
|
|
'a[href="/ghostfolio/ghostfolio/graphs/contributors"] .Counter' |
|
|
).text() |
|
|
).text() |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const value = $( |
|
|
|
|
|
'a[href="/ghostfolio/ghostfolio/graphs/contributors"] .Counter' |
|
|
|
|
|
).text(); |
|
|
|
|
|
|
|
|
|
|
|
if (!value) { |
|
|
|
|
|
throw new Error( |
|
|
|
|
|
'Could not find the number of contributors in the page' |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return extractNumberFromString({ |
|
|
|
|
|
value |
|
|
}); |
|
|
}); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - GitHub'); |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - GitHub'); |
|
|
|
|
|
|
|
|
return undefined; |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -130,7 +183,7 @@ export class StatisticsGatheringProcessor { |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - GitHub'); |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - GitHub'); |
|
|
|
|
|
|
|
|
return undefined; |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -161,7 +214,7 @@ export class StatisticsGatheringProcessor { |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - Better Stack'); |
|
|
Logger.error(error, 'StatisticsGatheringProcessor - Better Stack'); |
|
|
|
|
|
|
|
|
return undefined; |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|