Skip to content
Snippets Groups Projects
bright-connect.ipynb 2.16 KiB
Newer Older
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The following code blocks are the required modules and initial example from the developers manual for working with the RPC-based client library for programatic control of cmd.\n",
    "\n",
    "The example is not yet working, possibly due to python version differences.  In 8.2 the library is build for python 2.7.5.\n",
    "\n",
    "```\n",
    "!pip install pyOpenSSL==17.5.0 ply lxml tabulate monotonic humanfriendly six\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pythoncm.cluster import Cluster\n",
    "from pythoncm.settings import Settings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "settings = Settings(host='master',\n",
    "                    port=8081,\n",
    "                    cert_file='~/.cm/cert.pem',\n",
    "                    key_file='~/.cm/cert.key',\n",
    "                    ca_file='pythoncm/etc/cacert.pem')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cluster = Cluster(settings) #, check_api=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "use rest api for now to avoid RPC issues with library.\n",
    "\n",
    "convert curl command for currnet power to rest query\n",
    "https://curl.trillworks.com/\n",
    "\n",
    "```curl --cert ~/.cm/cert.pem --key ~/.cm/cert.key --cacert pythoncm/etc/cacert.pem \"https://master:8081/rest/v1/monitoring/latest?measurable=Pwr_Consumption&indent=1\"```\n",
    "\n",
    "the sum on the commandline, dealing with weird outlier data from one node is:\n",
    "\n",
    "```curl --cert ~/.cm/cert.pem --key ~/.cm/cert.key -k \"https://master:8081/rest/v1/monitoring/latest?measurable=Pwr_Consumption&indent=1\" | jq '.data[] | select(.raw < 10000) .raw' | awk '{sum=$1+sum} END {print sum}'```"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}