Created
October 20, 2022 11:17
-
-
Save andrewm4894/cf28b69850200bdfceaf32185340ee59 to your computer and use it in GitHub Desktop.
just run some curl.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyNiMFvl2kjq2XdlV+btQrJY", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/andrewm4894/cf28b69850200bdfceaf32185340ee59/just-run-some-curl.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"Just run some curl comand and get response back in python" | |
], | |
"metadata": { | |
"id": "X_88uDPpFBM0" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import json\n", | |
"import os" | |
], | |
"metadata": { | |
"id": "fGja608C7g9W" | |
}, | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"id": "ISGmyWd47NWR" | |
}, | |
"outputs": [], | |
"source": [ | |
"# paste curl command in here\n", | |
"curl = \"\"\"\n", | |
"curl https://london.my-netdata.io/api/v1/allmetrics?format=json\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# run curl comand and load response into a json dict\n", | |
"response = json.loads(os.popen(curl).read())" | |
], | |
"metadata": { | |
"id": "ZACkeXyE7p4s" | |
}, | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# do whatever you want with the response\n", | |
"response['system.cpu']['dimensions']" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "cauHkufGFTwi", | |
"outputId": "8900e96f-ddcb-451b-deaa-3bb74c03e313" | |
}, | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"{'guest_nice': {'name': 'guest_nice', 'value': 0.0},\n", | |
" 'guest': {'name': 'guest', 'value': 0.0},\n", | |
" 'steal': {'name': 'steal', 'value': 0.0},\n", | |
" 'softirq': {'name': 'softirq', 'value': 0.0},\n", | |
" 'irq': {'name': 'irq', 'value': 0.0},\n", | |
" 'user': {'name': 'user', 'value': 1.0},\n", | |
" 'system': {'name': 'system', 'value': 1.0},\n", | |
" 'nice': {'name': 'nice', 'value': 0.0},\n", | |
" 'iowait': {'name': 'iowait', 'value': 0.0},\n", | |
" 'idle': {'name': 'idle', 'value': 98.0}}" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 4 | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment