Spaces:
Sleeping
Sleeping
File size: 879 Bytes
d3c13b7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package exporter
import (
"context"
"fmt"
"io"
"net/http"
)
/*
* --- Node Exporter Metric Service ---
*/
func (s *ExporterServiceImpl) ExporterMetricsService(ctx context.Context) (string, error) {
endpoint := fmt.Sprintf("%s/metrics", "http://localhost:9100")
req, err := http.NewRequestWithContext(ctx, "GET", endpoint, nil)
if err != nil {
return "", fmt.Errorf("failed to create request: %v", err)
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", fmt.Errorf("failed to perform request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("request failed with status code: %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %v", err)
}
metricsResponse := string(body)
return metricsResponse, nil
}
|