collect more metrics, move everything related to metrics repo

This commit is contained in:
Daniel Dietzler
2023-12-11 23:18:21 +01:00
parent 874f707c92
commit e9197cde67
4 changed files with 49 additions and 33 deletions
@@ -1,11 +1,40 @@
import { MetricsDto } from '@app/domain/metrics';
import { IMetricsRepository } from '@app/domain/repositories/metrics.repository';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import axios from 'axios';
import os from 'os';
import { Repository } from 'typeorm';
import { AssetEntity, AssetType } from '../entities';
@Injectable()
export class MetricsRepository implements IMetricsRepository {
constructor(@InjectRepository(AssetEntity) private assetRepository: Repository<AssetEntity>) {}
async sendMetrics(payload: MetricsDto): Promise<void> {
await axios.post('IMMICH-DATA-DOMAIN', payload);
}
getAssetCount() {
return this.assetRepository.count();
}
getCpuCount() {
return os.cpus().length;
}
getCpuModel() {
return os.cpus()[0].model;
}
getMemoryCount() {
return os.totalmem();
}
getImageCount() {
return this.assetRepository.count({ where: { isVisible: true, type: AssetType.IMAGE } });
}
getVideoCount() {
return this.assetRepository.count({ where: { isVisible: true, type: AssetType.VIDEO } });
}
}