Skip to content

Instantly share code, notes, and snippets.

@maedoc
Created November 7, 2022 16:06
Show Gist options
  • Select an option

  • Save maedoc/fe2c3fbdcb012aea6ee2cf7634a8d4ef to your computer and use it in GitHub Desktop.

Select an option

Save maedoc/fe2c3fbdcb012aea6ee2cf7634a8d4ef to your computer and use it in GitHub Desktop.
uptime to nines
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "79532d26-eaab-4acf-ab8f-916203291a76",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "864a3a7d-514c-4711-9c28-583cbefbb376",
"metadata": {},
"source": [
"How do you get the number of nines from uptime percentage? Let's make some uptime percentages with clear 'nines' counts"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "e0c5272d-7a99-46ea-b419-95484095a2fc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"99.99\n",
"99.999\n",
"99.9999\n",
"99.99999\n",
"99.999999\n",
"99.9999999\n",
"99.99999999\n",
"99.999999999\n",
"99.9999999999\n",
"99.99999999999\n"
]
}
],
"source": [
"pct = [90.0, 99.0, 99.9]\n",
"for i in range(10):\n",
" pct.append( float(str(pct[-1]) + '9') )\n",
" print(pct[-1])"
]
},
{
"cell_type": "markdown",
"id": "7efbb7ae-82e2-40b0-9ee9-29799bebf908",
"metadata": {},
"source": [
"That last one is 13 nines.\n",
"\n",
"Convert uptime percentage to nines with a short formula:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c36b2e15-ee26-4174-aa69-c1583d981d7e",
"metadata": {},
"outputs": [],
"source": [
"nines = 2 - np.log10(100 - np.array(pct))"
]
},
{
"cell_type": "markdown",
"id": "08ce87f9-ae81-446a-9ff8-aef0bda7cc6c",
"metadata": {},
"source": [
"and check it's correct:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ffcd60f9-6af3-47a7-97be-bd2e0cf4e970",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1. , 2. , 3. , 4. , 5. ,\n",
" 6. , 7. , 8. , 9.00000003, 10.00000027,\n",
" 10.99999842, 11.99999225, 12.99980714])"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nines"
]
},
{
"cell_type": "markdown",
"id": "e216756d-780b-4cee-863e-4519e6944dcb",
"metadata": {},
"source": [
"95% is consider 1.5 nines, does it work?"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "d2779bef-9313-4fb4-9b3c-e1b0086b720d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.3010299956639813"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 - np.log10(100 - 95)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment