GetMetrics returns the text OpenMetrics data.
()
| 156 | |
| 157 | // GetMetrics returns the text OpenMetrics data. |
| 158 | func (r *ProtocolIncus) GetMetrics() (string, error) { |
| 159 | // Check that the server supports it. |
| 160 | if !r.HasExtension("metrics") { |
| 161 | return "", errors.New("The server is missing the required \"metrics\" API extension") |
| 162 | } |
| 163 | |
| 164 | // Prepare the request. |
| 165 | requestURL, err := r.setQueryAttributes(fmt.Sprintf("%s/1.0/metrics", r.httpBaseURL.String())) |
| 166 | if err != nil { |
| 167 | return "", err |
| 168 | } |
| 169 | |
| 170 | req, err := http.NewRequest("GET", requestURL, nil) |
| 171 | if err != nil { |
| 172 | return "", err |
| 173 | } |
| 174 | |
| 175 | // Send the request. |
| 176 | resp, err := r.DoHTTP(req) |
| 177 | if err != nil { |
| 178 | return "", err |
| 179 | } |
| 180 | |
| 181 | defer logger.WarnOnError(resp.Body.Close, "Failed to close response body") |
| 182 | |
| 183 | if resp.StatusCode != http.StatusOK { |
| 184 | return "", fmt.Errorf("Bad HTTP status: %d", resp.StatusCode) |
| 185 | } |
| 186 | |
| 187 | // Get the content. |
| 188 | content, err := io.ReadAll(resp.Body) |
| 189 | if err != nil { |
| 190 | return "", err |
| 191 | } |
| 192 | |
| 193 | return string(content), nil |
| 194 | } |
| 195 | |
| 196 | // ApplyServerPreseed configures a target Incus server with the provided server and cluster configuration. |
| 197 | func (r *ProtocolIncus) ApplyServerPreseed(config api.InitPreseed) error { |
nothing calls this directly
no test coverage detected