Estrazione delle metriche da un'istanza utilizzando il client Monitoring Python
Puoi estrarre le metriche da un'istanza IBM Cloud Monitoring tramite le operazioni API REST che puoi eseguire utilizzando un client Python o utilizzando un comando cURL.
Ottenere le metriche utilizzando un client Python
Per informazioni su come utilizzare il client Python, vedi Utilizzo del client Python.
Il seguente codice mostra la struttura di uno script Python che puoi utilizzare per recuperare metriche da un'istanza Monitoring:
# Reference the Python client
from sdcclient import IbmAuthHelper, SdMonitorClient
# Add the monitoring instance information that is required for authentication
URL = <MONITORING-ENDPOINT>
APIKEY = <IAM_APIKEY>
GUID = <GUID>
ibm_headers = IbmAuthHelper.get_headers(URL, APIKEY, GUID)
# Instantiate the Python client
sdclient = SdMonitorClient(sdc_url=URL, custom_headers=ibm_headers)
# Specify the ID for keys, and ID with aggregation for values
metrics = [
{"id": "cpu.used.percent", "aggregations": {"time": "timeAvg", "group": "avg"}}
]
# Add a data filter or set to None if you want to see "everything"
filter = None
# Time window:
# - for "from A to B": start is equal to A, end is equal to B (expressed in seconds)
# - for "last X seconds": start is equal to -X, end is equal to 0
start = -600
end = 0
# Sampling time:
# - for time series: sampling is equal to the "width" of each data point (expressed in seconds)
# - for aggregated data (similar to bar charts, pie charts, tables, etc.): sampling is equal to 0
sampling = 60
# Load data
ok, res = sdclient.get_data(metrics, start, end, sampling, filter=filter)
if ok:
print(res)
È necessario includere le seguenti informazioni: <MONITORING-ENDPOINT>, <IAM_APIKEY> e <GUID> Questi dati sono necessari per autenticare la richiesta con l'istanza di monitoraggio. Per
ottenere le informazioni sull'istanza di monitoraggio, consulta Autentica il tuo ID utente o servizio utilizzando IAM.
Esempi
Per gli esempi Python, vedi uno dei seguenti esempi:
Dizionario metriche
Per visualizzare le metriche predefinite, consultare Dizionario delle metriche.
Per visualizzare le metriche predefinite definite dai servizi IBM Cloud abilitati al monitoraggio, vedi Servizi cloud.
Aggregazione dei dati
Per informazioni sull'aggregazione dati, consultare Aggregazione dati.