glances_api 0.2.1__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.1
2
+ Name: glances-api
3
+ Version: 0.3.3
4
+ Summary: Python API for interacting with Glances
5
+ Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
6
+ License: MIT
7
+ Author: Fabian Affolter
8
+ Author-email: fabian@affolter-engineering.ch
9
+ Requires-Python: >=3.8,<4.0
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: MacOS :: MacOS X
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Topic :: Utilities
21
+ Requires-Dist: httpx (>=0.20,<1)
22
+ Project-URL: Repository, https://github.com/home-assistant-ecosystem/python-glances-api/releases
23
+ Description-Content-Type: text/x-rst
24
+
25
+ python-glances-api
26
+ ==================
27
+
28
+ A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
29
+
30
+ This module is not official, developed, supported or endorsed by Glances.
31
+
32
+ Installation
33
+ ------------
34
+
35
+ The module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.
36
+
37
+ .. code:: bash
38
+
39
+ $ pip3 install glances_api
40
+
41
+ Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
42
+
43
+ .. code:: bash
44
+
45
+ $ sudo dnf -y install python3-glances-api
46
+
47
+ Usage
48
+ -----
49
+
50
+ The file ``example.py`` contains an example about how to use this module.
51
+
52
+ License
53
+ -------
54
+
55
+ ``python-glances-api`` is licensed under MIT, for more details check LICENSE.
56
+
@@ -25,17 +25,6 @@ Usage
25
25
 
26
26
  The file ``example.py`` contains an example about how to use this module.
27
27
 
28
- Development
29
- -----------
30
-
31
- For development is recommended to use a ``venv``.
32
-
33
- .. code:: bash
34
-
35
- $ python3 -m venv .
36
- $ source bin/activate
37
- $ python3 setup.py develop
38
-
39
28
  License
40
29
  -------
41
30
 
@@ -0,0 +1,78 @@
1
+ """Client to interact with the Glances API."""
2
+ import asyncio
3
+ import logging
4
+
5
+ import httpx
6
+
7
+ from . import exceptions
8
+
9
+ _LOGGER = logging.getLogger(__name__)
10
+ _RESOURCE = "{schema}://{host}:{port}/api/{version}"
11
+
12
+
13
+ class Glances(object):
14
+ """A class for handling the data retrieval."""
15
+
16
+ def __init__(
17
+ self,
18
+ host="localhost",
19
+ port=61208,
20
+ version=2,
21
+ ssl=False,
22
+ verify_ssl=True,
23
+ username=None,
24
+ password=None,
25
+ ):
26
+ """Initialize the connection."""
27
+ schema = "https" if ssl else "http"
28
+ self.url = _RESOURCE.format(
29
+ schema=schema, host=host, port=port, version=version
30
+ )
31
+ self.plugins = None
32
+ self.values = None
33
+ self.username = username
34
+ self.password = password
35
+ self.verify_ssl = verify_ssl
36
+
37
+ async def get_data(self, endpoint):
38
+ """Retrieve the data."""
39
+ url = "{}/{}".format(self.url, endpoint)
40
+
41
+ try:
42
+ async with httpx.AsyncClient(verify=self.verify_ssl) as client:
43
+ if self.password is None:
44
+ response = await client.get(str(url))
45
+ else:
46
+ response = await client.get(
47
+ str(url), auth=(self.username, self.password)
48
+ )
49
+ except httpx.ConnectError:
50
+ raise exceptions.GlancesApiConnectionError(f"Connection to {url} failed")
51
+
52
+ if response.status_code == httpx.codes.UNAUTHORIZED:
53
+ raise exceptions.GlancesApiAuthorizationError(
54
+ "Please check your credentials"
55
+ )
56
+
57
+ if response.status_code == httpx.codes.OK:
58
+ try:
59
+ _LOGGER.debug(response.json())
60
+ if endpoint == "all":
61
+ self.data = response.json()
62
+ if endpoint == "pluginslist":
63
+ self.plugins = response.json()
64
+ except TypeError:
65
+ _LOGGER.error("Can not load data from Glances")
66
+ raise exceptions.GlancesApiConnectionError(
67
+ "Unable to get the data from Glances"
68
+ )
69
+
70
+ async def get_metrics(self, element):
71
+ """Get all the metrics for a monitored element."""
72
+ await self.get_data("all")
73
+ await self.get_data("pluginslist")
74
+
75
+ if element in self.plugins:
76
+ self.values = self.data[element]
77
+ else:
78
+ raise exceptions.GlancesApiError("Element data not available")
@@ -6,12 +6,14 @@ class GlancesApiError(Exception):
6
6
 
7
7
  pass
8
8
 
9
-
10
9
  class GlancesApiConnectionError(GlancesApiError):
11
10
  """When a connection error is encountered."""
12
11
 
13
12
  pass
13
+ class GlancesApiAuthorizationError(GlancesApiError):
14
+ """When a connection error is encountered."""
14
15
 
16
+ pass
15
17
 
16
18
  class GlancesApiNoDataAvailable(GlancesApiError):
17
19
  """When no data is available."""
@@ -0,0 +1,33 @@
1
+ [tool.poetry]
2
+ name = "glances_api"
3
+ version = "0.3.3"
4
+ description = "Python API for interacting with Glances"
5
+ authors = ["Fabian Affolter <fabian@affolter-engineering.ch>"]
6
+ homepage = "https://github.com/home-assistant-ecosystem/python-glances-api"
7
+ repository = "https://github.com/home-assistant-ecosystem/python-glances-api/releases"
8
+ readme = "README.rst"
9
+ license = "MIT"
10
+ classifiers = [
11
+ "Development Status :: 3 - Alpha",
12
+ "Environment :: Console",
13
+ "Intended Audience :: Developers",
14
+ "Operating System :: MacOS :: MacOS X",
15
+ "Operating System :: Microsoft :: Windows",
16
+ "Operating System :: POSIX",
17
+ "Topic :: Utilities",
18
+ ]
19
+
20
+ [tool.poetry.dependencies]
21
+ python = "^3.8"
22
+ httpx = ">=0.20,<1"
23
+
24
+ [tool.poetry.dev-dependencies]
25
+ black = "^21.12b0"
26
+ pytest = "^6.2.5"
27
+ pytest-httpx = ">0.15,<1"
28
+ pytest-asyncio = "^0.16.0"
29
+ isort = "^5.10.0"
30
+
31
+ [build-system]
32
+ requires = ["poetry-core>=1.0.0"]
33
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ from setuptools import setup
3
+
4
+ packages = \
5
+ ['glances_api']
6
+
7
+ package_data = \
8
+ {'': ['*']}
9
+
10
+ install_requires = \
11
+ ['httpx>=0.20,<1']
12
+
13
+ setup_kwargs = {
14
+ 'name': 'glances-api',
15
+ 'version': '0.3.3',
16
+ 'description': 'Python API for interacting with Glances',
17
+ 'long_description': 'python-glances-api\n==================\n\nA Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.\n\nThis module is not official, developed, supported or endorsed by Glances.\n\nInstallation\n------------\n\nThe module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.\n\n.. code:: bash\n\n $ pip3 install glances_api\n\nOr on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.\n\n.. code:: bash\n\n $ sudo dnf -y install python3-glances-api\n\nUsage\n-----\n\nThe file ``example.py`` contains an example about how to use this module.\n\nLicense\n-------\n\n``python-glances-api`` is licensed under MIT, for more details check LICENSE.\n',
18
+ 'author': 'Fabian Affolter',
19
+ 'author_email': 'fabian@affolter-engineering.ch',
20
+ 'maintainer': None,
21
+ 'maintainer_email': None,
22
+ 'url': 'https://github.com/home-assistant-ecosystem/python-glances-api',
23
+ 'packages': packages,
24
+ 'package_data': package_data,
25
+ 'install_requires': install_requires,
26
+ 'python_requires': '>=3.8,<4.0',
27
+ }
28
+
29
+
30
+ setup(**setup_kwargs)
@@ -1,29 +0,0 @@
1
- name: Python package and lint
2
-
3
- on:
4
- push:
5
- branches: [ master ]
6
- pull_request:
7
- branches: [ master ]
8
-
9
- jobs:
10
- build:
11
-
12
- runs-on: ubuntu-latest
13
- strategy:
14
- matrix:
15
- python-version: [3.5, 3.6, 3.7, 3.8]
16
-
17
- steps:
18
- - uses: actions/checkout@v2
19
- - name: Set up Python ${{ matrix.python-version }}
20
- uses: actions/setup-python@v2
21
- with:
22
- python-version: ${{ matrix.python-version }}
23
- - name: Install dependencies
24
- run: |
25
- python -m pip install --upgrade pip
26
- pip install flake8 pytest
27
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28
- - name: Black Code Formatter
29
- uses: lgeiger/black-action@v1.0.1
@@ -1,10 +0,0 @@
1
- Changes
2
- =======
3
-
4
- 20181121 - 0.2.0
5
- ----------------
6
- - Support for HTTP Basic authentication
7
-
8
- 20180814 - 0.1.0
9
- ----------------
10
- - Initial release
@@ -1,2 +0,0 @@
1
- include LICENSE
2
- include CHANGES.rst
@@ -1,63 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: glances_api
3
- Version: 0.2.1
4
- Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
6
- Author: Fabian Affolter
7
- Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Download-URL: https://github.com/home-assistant-ecosystem/python-glances-api/releases
10
- Description: python-glances-api
11
- ==================
12
-
13
- A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
14
-
15
- This module is not official, developed, supported or endorsed by Glances.
16
-
17
- Installation
18
- ------------
19
-
20
- The module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.
21
-
22
- .. code:: bash
23
-
24
- $ pip3 install glances_api
25
-
26
- Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
27
-
28
- .. code:: bash
29
-
30
- $ sudo dnf -y install python3-glances-api
31
-
32
- Usage
33
- -----
34
-
35
- The file ``example.py`` contains an example about how to use this module.
36
-
37
- Development
38
- -----------
39
-
40
- For development is recommended to use a ``venv``.
41
-
42
- .. code:: bash
43
-
44
- $ python3 -m venv .
45
- $ source bin/activate
46
- $ python3 setup.py develop
47
-
48
- License
49
- -------
50
-
51
- ``python-glances-api`` is licensed under MIT, for more details check LICENSE.
52
-
53
- Platform: UNKNOWN
54
- Classifier: Development Status :: 3 - Alpha
55
- Classifier: Environment :: Console
56
- Classifier: Intended Audience :: Developers
57
- Classifier: License :: OSI Approved :: MIT License
58
- Classifier: Operating System :: MacOS :: MacOS X
59
- Classifier: Operating System :: Microsoft :: Windows
60
- Classifier: Operating System :: POSIX
61
- Classifier: Programming Language :: Python :: 3.5
62
- Classifier: Programming Language :: Python :: 3.6
63
- Classifier: Topic :: Utilities
@@ -1,31 +0,0 @@
1
- """Sample script to use the Python API client for Glances."""
2
- import asyncio
3
-
4
- import aiohttp
5
-
6
- from glances_api import Glances
7
-
8
- HOST = "127.0.0.1"
9
- VERSION = 3
10
-
11
-
12
- async def main():
13
- """The main part of the example script."""
14
- async with aiohttp.ClientSession() as session:
15
- data = Glances(loop, session, version=VERSION)
16
-
17
- # Get the metrics for the memory
18
- await data.get_metrics("mem")
19
-
20
- # Print the values
21
- print("Memory values:", data.values)
22
-
23
- # Get the metrics about the disks
24
- await data.get_metrics("diskio")
25
-
26
- # Print the values
27
- print("Disk values:", data.values)
28
-
29
-
30
- loop = asyncio.get_event_loop()
31
- loop.run_until_complete(main())
@@ -1,89 +0,0 @@
1
- """Client to interact with the Glances API."""
2
- import asyncio
3
- import logging
4
-
5
- import aiohttp
6
- import async_timeout
7
-
8
- from . import exceptions
9
-
10
- _LOGGER = logging.getLogger(__name__)
11
- _RESOURCE = "{schema}://{host}:{port}/api/{version}"
12
-
13
-
14
- class Glances(object):
15
- """A class for handling the data retrieval."""
16
-
17
- def __init__(
18
- self,
19
- loop,
20
- session,
21
- host="localhost",
22
- port=61208,
23
- version=2,
24
- ssl=False,
25
- username=None,
26
- password=None,
27
- ):
28
- """Initialize the connection."""
29
- schema = "https" if ssl else "http"
30
- self._loop = loop
31
- self._session = session
32
- self.url = _RESOURCE.format(
33
- schema=schema, host=host, port=port, version=version
34
- )
35
- self.data = None
36
- self.values = None
37
- self.plugins = None
38
- self.username = username
39
- self.password = password
40
-
41
- async def get_data(self):
42
- """Retrieve the data."""
43
- url = "{}/{}".format(self.url, "all")
44
-
45
- try:
46
- with async_timeout.timeout(5, loop=self._loop):
47
- if self.password is None:
48
- response = await self._session.get(url)
49
- else:
50
- auth = aiohttp.BasicAuth(self.username, self.password)
51
- response = await self._session.get(url, auth=auth)
52
-
53
- _LOGGER.debug("Response from Glances API: %s", response.status)
54
- print(response.status)
55
- print(response.text)
56
- self.data = await response.json()
57
- _LOGGER.debug(self.data)
58
- except (asyncio.TimeoutError, aiohttp.ClientError):
59
- _LOGGER.error("Can not load data from Glances API")
60
- raise exceptions.GlancesApiConnectionError()
61
-
62
- async def get_metrics(self, element):
63
- """Get all the metrics for a monitored element."""
64
- await self.get_data()
65
- await self.get_plugins()
66
-
67
- if element in self.plugins:
68
- self.values = self.data[element]
69
- else:
70
- raise exceptions.GlancesApiError("Element data not available")
71
-
72
- async def get_plugins(self):
73
- """Retrieve the available plugins."""
74
- url = "{}/{}".format(self.url, "pluginslist")
75
-
76
- try:
77
- with async_timeout.timeout(5, loop=self._loop):
78
- if self.password is None:
79
- response = await self._session.get(url)
80
- else:
81
- auth = aiohttp.BasicAuth(self.username, self.password)
82
- response = await self._session.get(url, auth=auth)
83
-
84
- _LOGGER.debug("Response from Glances API: %s", response.status)
85
- self.plugins = await response.json()
86
- _LOGGER.debug(self.plugins)
87
- except (asyncio.TimeoutError, aiohttp.ClientError):
88
- _LOGGER.error("Can not load plugins from Glances API")
89
- raise exceptions.GlancesApiConnectionError()
@@ -1,63 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: glances-api
3
- Version: 0.2.1
4
- Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/home-assistant-ecosystem/python-glances-api
6
- Author: Fabian Affolter
7
- Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Download-URL: https://github.com/home-assistant-ecosystem/python-glances-api/releases
10
- Description: python-glances-api
11
- ==================
12
-
13
- A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
14
-
15
- This module is not official, developed, supported or endorsed by Glances.
16
-
17
- Installation
18
- ------------
19
-
20
- The module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.
21
-
22
- .. code:: bash
23
-
24
- $ pip3 install glances_api
25
-
26
- Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
27
-
28
- .. code:: bash
29
-
30
- $ sudo dnf -y install python3-glances-api
31
-
32
- Usage
33
- -----
34
-
35
- The file ``example.py`` contains an example about how to use this module.
36
-
37
- Development
38
- -----------
39
-
40
- For development is recommended to use a ``venv``.
41
-
42
- .. code:: bash
43
-
44
- $ python3 -m venv .
45
- $ source bin/activate
46
- $ python3 setup.py develop
47
-
48
- License
49
- -------
50
-
51
- ``python-glances-api`` is licensed under MIT, for more details check LICENSE.
52
-
53
- Platform: UNKNOWN
54
- Classifier: Development Status :: 3 - Alpha
55
- Classifier: Environment :: Console
56
- Classifier: Intended Audience :: Developers
57
- Classifier: License :: OSI Approved :: MIT License
58
- Classifier: Operating System :: MacOS :: MacOS X
59
- Classifier: Operating System :: Microsoft :: Windows
60
- Classifier: Operating System :: POSIX
61
- Classifier: Programming Language :: Python :: 3.5
62
- Classifier: Programming Language :: Python :: 3.6
63
- Classifier: Topic :: Utilities
@@ -1,16 +0,0 @@
1
- CHANGES.rst
2
- LICENSE
3
- MANIFEST.in
4
- README.rst
5
- example.py
6
- requirements.txt
7
- setup.py
8
- .github/workflows/python-package.yml
9
- glances_api/__init__.py
10
- glances_api/exceptions.py
11
- glances_api.egg-info/PKG-INFO
12
- glances_api.egg-info/SOURCES.txt
13
- glances_api.egg-info/dependency_links.txt
14
- glances_api.egg-info/requires.txt
15
- glances_api.egg-info/top_level.txt
16
- glances_api.egg-info/zip-safe
@@ -1,2 +0,0 @@
1
- aiohttp<4,>=3.7.4
2
- async_timeout<4
@@ -1 +0,0 @@
1
- glances_api
@@ -1,2 +0,0 @@
1
- # python-glances-api requirements. Use setup.py for the dependencies.
2
- .
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
@@ -1,41 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Set up the Python API client for Glances."""
3
- import os
4
- import sys
5
-
6
- try:
7
- from setuptools import setup
8
- except ImportError:
9
- from distutils.core import setup
10
-
11
- here = os.path.abspath(os.path.dirname(__file__))
12
-
13
- with open(os.path.join(here, "README.rst"), encoding="utf-8") as readme_file:
14
- long_description = readme_file.read()
15
-
16
- setup(
17
- name="glances_api",
18
- version="0.2.1",
19
- description="Python API for interacting with Glances.",
20
- long_description=long_description,
21
- url="https://github.com/home-assistant-ecosystem/python-glances-api",
22
- download_url="https://github.com/home-assistant-ecosystem/python-glances-api/releases",
23
- author="Fabian Affolter",
24
- author_email="fabian@affolter-engineering.ch",
25
- license="MIT",
26
- install_requires=["aiohttp>=3.7.4,<4", "async_timeout<4"],
27
- packages=["glances_api"],
28
- zip_safe=True,
29
- classifiers=[
30
- "Development Status :: 3 - Alpha",
31
- "Environment :: Console",
32
- "Intended Audience :: Developers",
33
- "License :: OSI Approved :: MIT License",
34
- "Operating System :: MacOS :: MacOS X",
35
- "Operating System :: Microsoft :: Windows",
36
- "Operating System :: POSIX",
37
- "Programming Language :: Python :: 3.5",
38
- "Programming Language :: Python :: 3.6",
39
- "Topic :: Utilities",
40
- ],
41
- )
File without changes