glances_api 0.2.0__tar.gz → 0.3.2__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.
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2018 Fabian Affolter
3
+ Copyright (c) 2017-2021 Fabian Affolter <fabian@affolter-engineering.ch>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.1
2
+ Name: glances-api
3
+ Version: 0.3.2
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
+
@@ -1,7 +1,7 @@
1
1
  python-glances-api
2
2
  ==================
3
3
 
4
- Python API for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
4
+ A Python client for interacting with `Glances <https://nicolargo.github.io/glances/>`_.
5
5
 
6
6
  This module is not official, developed, supported or endorsed by Glances.
7
7
 
@@ -14,21 +14,16 @@ The module is available from the `Python Package Index <https://pypi.python.org/
14
14
 
15
15
  $ pip3 install glances_api
16
16
 
17
- Usage
18
- -----
17
+ Or on a Fedora-based system or on a CentOS/RHEL machine with has EPEL enabled.
19
18
 
20
- The file ``example.py`` contains an example about how to use this module.
21
-
22
- Development
23
- -----------
19
+ .. code:: bash
24
20
 
25
- For development is recommended to use a ``venv``.
21
+ $ sudo dnf -y install python3-glances-api
26
22
 
27
- .. code:: bash
23
+ Usage
24
+ -----
28
25
 
29
- $ python3.6 -m venv .
30
- $ source bin/activate
31
- $ python3 setup.py develop
26
+ The file ``example.py`` contains an example about how to use this module.
32
27
 
33
28
  License
34
29
  -------
@@ -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
+ username=None,
23
+ password=None,
24
+ ):
25
+ """Initialize the connection."""
26
+ schema = "https" if ssl else "http"
27
+ self.url = _RESOURCE.format(
28
+ schema=schema, host=host, port=port, version=version
29
+ )
30
+ self.plugins = None
31
+ self.values = None
32
+ self.username = username
33
+ self.password = password
34
+
35
+ async def get_data(self, endpoint):
36
+ """Retrieve the data."""
37
+ url = "{}/{}".format(self.url, endpoint)
38
+
39
+ try:
40
+ async with httpx.AsyncClient() as client:
41
+ if self.password is None:
42
+ response = await client.get(str(url))
43
+ else:
44
+ response = await client.get(
45
+ str(url), auth=(self.username, self.password)
46
+ )
47
+ except httpx.ConnectError:
48
+ raise exceptions.GlancesApiConnectionError(f"Connection to {url} failed")
49
+
50
+ if response.status_code == httpx.codes.UNAUTHORIZED:
51
+ raise exceptions.GlancesApiAuthorizationError(
52
+ "Please check your credentials"
53
+ )
54
+
55
+ if response.status_code == httpx.codes.OK:
56
+ try:
57
+ _LOGGER.debug(response.json())
58
+ # print(self.data)
59
+ # self.data = 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.2"
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.10b0"
26
+ pytest = "^6.2.5"
27
+ pytest-httpx = "^0.14.0"
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.2',
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,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,57 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: glances_api
3
- Version: 0.2.0
4
- Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/fabaff/python-glances-api
6
- Author: Fabian Affolter
7
- Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Download-URL: https://github.com/fabaff/python-glances-api/releases
10
- Description: python-glances-api
11
- ==================
12
-
13
- Python API 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
- Usage
27
- -----
28
-
29
- The file ``example.py`` contains an example about how to use this module.
30
-
31
- Development
32
- -----------
33
-
34
- For development is recommended to use a ``venv``.
35
-
36
- .. code:: bash
37
-
38
- $ python3.6 -m venv .
39
- $ source bin/activate
40
- $ python3 setup.py develop
41
-
42
- License
43
- -------
44
-
45
- ``python-glances-api`` is licensed under MIT, for more details check LICENSE.
46
-
47
- Platform: UNKNOWN
48
- Classifier: Development Status :: 3 - Alpha
49
- Classifier: Environment :: Console
50
- Classifier: Intended Audience :: Developers
51
- Classifier: License :: OSI Approved :: MIT License
52
- Classifier: Operating System :: MacOS :: MacOS X
53
- Classifier: Operating System :: Microsoft :: Windows
54
- Classifier: Operating System :: POSIX
55
- Classifier: Programming Language :: Python :: 3.5
56
- Classifier: Programming Language :: Python :: 3.6
57
- Classifier: Topic :: Utilities
@@ -1,77 +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__(self, loop, session, host='localhost', port=61208, version=2,
18
- ssl=False, username=None, password=None):
19
- """Initialize the connection."""
20
- schema = 'https' if ssl else 'http'
21
- self._loop = loop
22
- self._session = session
23
- self.url = _RESOURCE.format(schema=schema, host=host, port=port,
24
- version=version)
25
- self.data = None
26
- self.values = None
27
- self.plugins = None
28
- self.username = username
29
- self.password = password
30
-
31
- async def get_data(self):
32
- """Retrieve the data."""
33
- url = '{}/{}'.format(self.url, 'all')
34
-
35
- try:
36
- with async_timeout.timeout(5, loop=self._loop):
37
- if self.password is None:
38
- response = await self._session.get(url)
39
- else:
40
- auth = aiohttp.BasicAuth(self.username, self.password)
41
- response = await self._session.get(url, auth=auth)
42
-
43
- _LOGGER.debug("Response from Glances API: %s", response.status)
44
- self.data = await response.json()
45
- _LOGGER.debug(self.data)
46
- except (asyncio.TimeoutError, aiohttp.ClientError):
47
- _LOGGER.error("Can not load data from Glances API")
48
- raise exceptions.GlancesApiConnectionError()
49
-
50
- async def get_metrics(self, element):
51
- """Get all the metrics for a monitored element."""
52
- await self.get_data()
53
- await self.get_plugins()
54
-
55
- if element in self.plugins:
56
- self.values = self.data[element]
57
- else:
58
- raise exceptions.GlancesApiError("Element data not available")
59
-
60
- async def get_plugins(self):
61
- """Retrieve the available plugins."""
62
- url = '{}/{}'.format(self.url, 'pluginslist')
63
-
64
- try:
65
- with async_timeout.timeout(5, loop=self._loop):
66
- if self.password is None:
67
- response = await self._session.get(url)
68
- else:
69
- auth = aiohttp.BasicAuth(self.username, self.password)
70
- response = await self._session.get(url, auth=auth)
71
-
72
- _LOGGER.debug("Response from Glances API: %s", response.status)
73
- self.plugins = await response.json()
74
- _LOGGER.debug(self.plugins)
75
- except (asyncio.TimeoutError, aiohttp.ClientError):
76
- _LOGGER.error("Can not load plugins from Glances API")
77
- raise exceptions.GlancesApiConnectionError()
@@ -1,57 +0,0 @@
1
- Metadata-Version: 1.1
2
- Name: glances-api
3
- Version: 0.2.0
4
- Summary: Python API for interacting with Glances.
5
- Home-page: https://github.com/fabaff/python-glances-api
6
- Author: Fabian Affolter
7
- Author-email: fabian@affolter-engineering.ch
8
- License: MIT
9
- Download-URL: https://github.com/fabaff/python-glances-api/releases
10
- Description: python-glances-api
11
- ==================
12
-
13
- Python API 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
- Usage
27
- -----
28
-
29
- The file ``example.py`` contains an example about how to use this module.
30
-
31
- Development
32
- -----------
33
-
34
- For development is recommended to use a ``venv``.
35
-
36
- .. code:: bash
37
-
38
- $ python3.6 -m venv .
39
- $ source bin/activate
40
- $ python3 setup.py develop
41
-
42
- License
43
- -------
44
-
45
- ``python-glances-api`` is licensed under MIT, for more details check LICENSE.
46
-
47
- Platform: UNKNOWN
48
- Classifier: Development Status :: 3 - Alpha
49
- Classifier: Environment :: Console
50
- Classifier: Intended Audience :: Developers
51
- Classifier: License :: OSI Approved :: MIT License
52
- Classifier: Operating System :: MacOS :: MacOS X
53
- Classifier: Operating System :: Microsoft :: Windows
54
- Classifier: Operating System :: POSIX
55
- Classifier: Programming Language :: Python :: 3.5
56
- Classifier: Programming Language :: Python :: 3.6
57
- Classifier: Topic :: Utilities
@@ -1,13 +0,0 @@
1
- CHANGES.rst
2
- LICENSE
3
- MANIFEST.in
4
- README.rst
5
- setup.py
6
- glances_api/__init__.py
7
- glances_api/exceptions.py
8
- glances_api.egg-info/PKG-INFO
9
- glances_api.egg-info/SOURCES.txt
10
- glances_api.egg-info/dependency_links.txt
11
- glances_api.egg-info/requires.txt
12
- glances_api.egg-info/top_level.txt
13
- glances_api.egg-info/zip-safe
@@ -1,2 +0,0 @@
1
- aiohttp
2
- async_timeout
@@ -1 +0,0 @@
1
- glances_api
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
@@ -1,49 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Copyright (c) 2017-2018 Fabian Affolter <fabian@affolter-engineering.ch>
4
-
5
- Licensed under MIT. All rights reserved.
6
- """
7
- import os
8
- import sys
9
-
10
- try:
11
- from setuptools import setup
12
- except ImportError:
13
- from distutils.core import setup
14
-
15
- here = os.path.abspath(os.path.dirname(__file__))
16
-
17
- with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
18
- long_description = f.read()
19
-
20
- if sys.argv[-1] == 'publish':
21
- os.system('python3 setup.py sdist upload')
22
- sys.exit()
23
-
24
- setup(
25
- name='glances_api',
26
- version='0.2.0',
27
- description='Python API for interacting with Glances.',
28
- long_description=long_description,
29
- url='https://github.com/fabaff/python-glances-api',
30
- download_url='https://github.com/fabaff/python-glances-api/releases',
31
- author='Fabian Affolter',
32
- author_email='fabian@affolter-engineering.ch',
33
- license='MIT',
34
- install_requires=['aiohttp', 'async_timeout'],
35
- packages=['glances_api'],
36
- zip_safe=True,
37
- classifiers=[
38
- 'Development Status :: 3 - Alpha',
39
- 'Environment :: Console',
40
- 'Intended Audience :: Developers',
41
- 'License :: OSI Approved :: MIT License',
42
- 'Operating System :: MacOS :: MacOS X',
43
- 'Operating System :: Microsoft :: Windows',
44
- 'Operating System :: POSIX',
45
- 'Programming Language :: Python :: 3.5',
46
- 'Programming Language :: Python :: 3.6',
47
- 'Topic :: Utilities',
48
- ],
49
- )