2015-04-22 39 views
0

我是初學者,所以請親切。我想從服務器上安裝的某些虛擬機下載CPU利用率。服務器安裝了Graphite。我安裝了Python石墨API,並且我有服務器連接細節。如何讓REST API調用開始提取數據?使用Python從Graphite下載數據

+0

這裏是python代碼來拉數據,但它不使用該AP,只是urllibI:https://github.com/etsy/nagios_tools/blob/master/check_graphite_data – ziggestardust

回答

2

使用requests包:

>>> r = requests.get('https://your_graphite_host.com/render?target=app.numUsers&format=json', auth=('user', 'pass')) 
>>> r.json() # this will give your the JSON file with the data 

請記住,你將有相應的指標名稱,以取代app.numUsers。您也可以請求其他格式和時間範圍,請參閱graphite-api docs

+0

有沒有其他客戶端? – confiq

+0

是的,當然,你可以使用Python的urllib,或使用任何其他編程語言 – dukebody

+0

我正在尋找更好的石墨包裝...'robust-graphite-client'可能回答我的需要 – confiq