diff --git a/.env b/.env new file mode 100644 index 0000000..2979ce2 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +#PROMETHEUS_API=http://192.168.2.37:9090/api/v1 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 82cfd43..b86a806 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,6 @@ RUN npm install COPY . . +ENV NODE_ENV=development + CMD ["npm", "run", "start:dev"] diff --git a/Jenkinsfile b/Jenkinsfile index 6ae7c82..745cad1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -41,7 +41,6 @@ pipeline { always { script { echo "Cleaning up workspace..." - sh "rm -rf ${env.WORKSPACE}/package/ || true" sh "rm -rf ${env.WORKSPACE}/rc/ || true" } } @@ -56,7 +55,7 @@ pipeline { -u "${GITEA_USER}:${GITEA_PASS}" \ -H "Content-Type: application/json" \ -d '{"do":"merge"}' \ - http://git.entcor/api/v1/repos/DmitriyA/trust-module-backend/pulls/${prId}/merge + http://git.entcor/api/v1/repos/deployer3000/trust-module-backend/pulls/${prId}/merge """ echo "PR ${prId} merged successfully into master!" } diff --git a/package.json b/package.json index f14298a..5e92a63 100644 --- a/package.json +++ b/package.json @@ -74,4 +74,4 @@ "coverageDirectory": "../coverage", "testEnvironment": "node" } -} +} \ No newline at end of file diff --git a/src/prometheus.service.ts b/src/prometheus.service.ts index 333292c..407cdb0 100644 --- a/src/prometheus.service.ts +++ b/src/prometheus.service.ts @@ -8,15 +8,10 @@ import { PrometheusMetric } from './prometheus-metric.interface'; export class PrometheusService { private readonly prometheusUrl: string; - constructor( - private readonly httpService: HttpService, - private readonly configService: ConfigService - ) { - this.prometheusUrl = this.configService.get('PROMETHEUS_API', 'http://localhost:9090'); - console.log('Prometheus API URL:', this.prometheusUrl); - } + constructor(private readonly httpService: HttpService) { } + + //Получаем тип метрики - // Получаем тип метрики async fetchMetricType(metric: string): Promise { try { const response = await lastValueFrom( @@ -33,24 +28,8 @@ export class PrometheusService { } } - // Получаем описание метрики - async fetchMetricDescription(metric: string): Promise { - try { - const response = await lastValueFrom( - this.httpService.get(`${this.prometheusUrl}/metadata`, { - params: { metric }, - }) - ); + //Данные конкретной метрики, включая ее тип - const metadata = response.data.data[metric]; - return metadata?.length ? metadata[0].help : undefined; - } catch (error) { - console.error(`Ошибка при получении описания метрики ${metric}:`, error); - return undefined; - } - } - - // Получаем данные метрики (текущие значения) async fetchMetrics(metric: string): Promise { const response = await lastValueFrom( this.httpService.get(`${this.prometheusUrl}/query`, { @@ -58,46 +37,18 @@ export class PrometheusService { }) ); - const metricType = await this.fetchMetricType(metric); - const metricDescription = await this.fetchMetricDescription(metric); + const metricType = await this.fetchMetricType(metric); // Получаем тип return response.data.data.result.map((entry): PrometheusMetric => ({ ...entry.metric, - timestamp: entry.value[0] * 1000, - value: parseFloat(entry.value[1]), - type: metricType || 'unknown', - description: metricDescription, // Добавляем описание + timestamp: entry.value[0] * 1000, // Преобразуем в миллисекунды + value: parseFloat(entry.value[1]), // Преобразуем в число + type: metricType || 'unknown', // Добавляем тип метрики })); } - // Получаем данные метрики за интервал - async fetchMetricsRange(metric: string, start: number, end: number, step: number): Promise { - const response = await lastValueFrom( - this.httpService.get(`${this.prometheusUrl}/query_range`, { - params: { - query: metric, - start, - end, - step, - }, - }) - ); + //Получаем данные всех метрик - const metricType = await this.fetchMetricType(metric); - const metricDescription = await this.fetchMetricDescription(metric); - - return response.data.data.result.flatMap((entry) => - entry.values.map((value): PrometheusMetric => ({ - ...entry.metric, - timestamp: value[0] * 1000, - value: parseFloat(value[1]), - type: metricType || 'unknown', - description: metricDescription, // Добавляем описание - })) - ); - } - - // Получаем список всех метрик async fetchAllMetrics(): Promise { const response = await lastValueFrom( this.httpService.get(`${this.prometheusUrl}/label/__name__/values`) @@ -105,7 +56,8 @@ export class PrometheusService { return response.data.data; } - // Получаем все метрики с их значениями + // Получаем список всех метрик + async fetchAllMetricsWithValues(): Promise { const metricNames = await this.fetchAllMetrics(); const promises = metricNames.map(async (metric) => { @@ -114,4 +66,4 @@ export class PrometheusService { }); return Promise.all(promises); } -} \ No newline at end of file +}