https://github.com/heavenshell/py-mackerel-client
Mackerel client implemented by Python.
https://github.com/heavenshell/py-mackerel-client
mackerel mackerel-client python
Last synced: about 1 year ago
JSON representation
Mackerel client implemented by Python.
- Host: GitHub
- URL: https://github.com/heavenshell/py-mackerel-client
- Owner: heavenshell
- License: bsd-3-clause
- Created: 2015-02-28T14:20:14.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-05-23T03:30:13.000Z (about 3 years ago)
- Last Synced: 2024-10-29T22:47:23.542Z (over 1 year ago)
- Topics: mackerel, mackerel-client, python
- Language: Python
- Homepage:
- Size: 75.2 KB
- Stars: 8
- Watchers: 5
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
mackerel.client
===============
.. image:: https://travis-ci.org/heavenshell/py-mackerel-client.svg?branch=master
:target: https://travis-ci.org/heavenshell/py-mackerel-client
mackerel.client is a python library to access Mackerel (https://mackerel.io/).
This client is Ported from `mackerel-client-ruby `_.
Install
-------
.. code:: shell
$ pip install mackerel.client
Dependency
----------
mackerel.client use `requests `_, `simplejson `_ and `click `_.
Usage
-----
Get hosts
~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='')
Update host status
~~~~~~~~~~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='', 'poweroff')
# Standby.
self.client.update_host_status('', 'standby')
# Working.
self.client.update_host_status('', 'working')
# Maintenance.
self.client.update_host_status('', 'maintenance')
Retire host
~~~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='')
Get latest metrics
~~~~~~~~~~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='', ''],
['loadavg5', 'memory.free'])
Post metrics
~~~~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='')
metrics = [
{
'hostId': '', 'name': 'custom.metrics.loadavg',
'time': 1401537844, 'value': 1.4
},
{
'hostId': '', 'name': 'custom.metrics.uptime',
'time': 1401537844, 'value': 500
}
]
# Post `custom.metrics.loadavg` and `custom.metrics.uptime` to `hostId`.
client.post_metrics(metrics)
Post service metrics
~~~~~~~~~~~~~~~~~~~~
.. code:: python
from mackerel.client import Client
client = Client(mackerel_api_key='')
metrics = [
{
'name': 'custom.metrics.latency',
'time': 1401537844, 'value': 0.5
},
{
'name': 'custom.metrics.uptime',
'time': 1401537844, 'value': 500
}
]
# Post 'custom.metrics.latency' and 'custom.metrics.uptime' to `service_name`.
self.client.post_service_metrics('service_name', metrics)
CLI
---
Get host(s) information from hostname or service, role.
.. code:: shell
$ mkr.py info [--name foo] [--service service] [--role role]
Set status of a host.
.. code:: shell
$ mkr.py status --host-id foo --status working
Retire a host.
.. code:: shell
$ mkr.py retire --host-id foo
Get status of a host.
.. code:: shell
$ mkr.py status --host-id foo
Authentication
--------------
.. code:: shell
$ export MACKEREL_APIKEY=foobar