MCPcopy
hub / github.com/lxc/incus / GetMetrics

Method GetMetrics

client/incus_server.go:158–194  ·  view source on GitHub ↗

GetMetrics returns the text OpenMetrics data.

()

Source from the content-addressed store, hash-verified

156
157// GetMetrics returns the text OpenMetrics data.
158func (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.
197func (r *ProtocolIncus) ApplyServerPreseed(config api.InitPreseed) error {

Callers

nothing calls this directly

Calls 6

HasExtensionMethod · 0.95
setQueryAttributesMethod · 0.95
DoHTTPMethod · 0.95
WarnOnErrorFunction · 0.92
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected