Mackerel client implemented by Python.
Project description
mackerel.clienthde is a python library to access Mackerel (https://mackerel.io/).
This project is forked from heavenshell/py-mackerel-client, which is initially ported from mackerel-client-ruby.
Install
$ pip install mackerel.clienthde
Dependency
mackerel.clienthde use requests, simplejson and click.
Usage
Get hosts
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
hosts = client.get_hosts()
Get host
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
host = client.get_host('<hostId>')
Update host status
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
# Poweroff.
self.client.update_host_status('<hostId>', 'poweroff')
# Standby.
self.client.update_host_status('<hostId>', 'standby')
# Working.
self.client.update_host_status('<hostId>', 'working')
# Maintenance.
self.client.update_host_status('<hostId>', 'maintenance')
Retire host
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
self.client.retire_host('<hostId>')
Get latest metrics
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
# Get hostId A's and hostId B's loadavg5, memory.free value.
metrics = self.client.get_latest_metrics(['<hostId A>', '<hostId B>'],
['loadavg5', 'memory.free'])
Post metrics
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key>')
metrics = [
{
'hostId': '<hostId>', 'name': 'custom.metrics.loadavg',
'time': 1401537844, 'value': 1.4
},
{
'hostId': '<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
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your 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)
Get monitors [NEW in this forked version]
from mackerel.clienthde import Client
# Alternatively, you can set MACKEREL_APIKEY as environment variable
# And simply call "client = Client()"
client = Client(mackerel_api_key='<Put your API key')
monitors = client.get_monitors()
CLI
Get host(s) information from hostname or service, role.
$ mkr.py info [--name foo] [--service service] [--role role]
Set status of a host.
$ mkr.py status --host-id foo --status working
Retire a host.
$ mkr.py retire --host-id foo
Get status of a host.
$ mkr.py status --host-id foo
Authentication
$ export MACKEREL_APIKEY=foobar
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mackerel.clienthde-0.0.2.zip
(13.9 kB
view details)
File details
Details for the file mackerel.clienthde-0.0.2.zip
.
File metadata
- Download URL: mackerel.clienthde-0.0.2.zip
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3405be22c34f209fa61775011fd3f5d8b741514e686d07ffee35868e79d8c521 |
|
MD5 | 098c8dd9e0a5fd4b23a04b54ccccb2ef |
|
BLAKE2b-256 | 99c53cf8e840b8b9a4ce8d96cc0b067c721c37605a35563d3fe62b23d08ee787 |