import { Injectable, InternalServerErrorException } from '@nestjs/common'; import axios from 'axios'; import { PrometheusQueryResult, PrometheusApiResponse, } from './interface/prometheus.interface'; @Injectable() export class PrometheusService { private readonly prometheusUrl = 'http://prometheus:9090/api/v1/query'; async getMetric(metric: string): Promise { try { const response = await axios.get< PrometheusApiResponse >(this.prometheusUrl, { params: { query: metric }, }); return response.data.data; } catch (error: unknown) { if (error instanceof Error) { throw new InternalServerErrorException( `Ошибка запроса: ${error.message}`, ); } throw new InternalServerErrorException( 'Неизвестная ошибка при запросе к Prometheus', ); } } }