用python实现的mackerel客户端。

mackerel.client的Python项目详细描述


https://travis-ci.org/heavenshell/py-mackerel-client.svg?branch=master

client是一个访问mackerel(https://mackerel.io/)的python库。

此客户端是从mackerel-client-ruby移植的。

安装

$ pip install mackerel.client

依赖性

mackerel.client使用requestssimplejsonclick

用法

获取主机

frommackerel.clientimportClientclient=Client(mackerel_api_key='<Put your API key')host=client.get_hosts()

获得主机

frommackerel.clientimportClientclient=Client(mackerel_api_key='<Put your API key')host=client.get_host('<hostId>')

更新主机状态

frommackerel.clientimportClientclient=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')

退出主机

frommackerel.clientimportClientclient=Client(mackerel_api_key='<Put your API key')self.client.retire_host('<hostId>')

获取最新指标

frommackerel.clientimportClientclient=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'])

后指标

frommackerel.clientimportClientclient=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)

服务后指标

frommackerel.clientimportClientclient=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)

cli

从主机名或服务、角色获取主机信息。

$ mkr.py info [--name foo][--service service][--role role]

设置主机的状态。

$ mkr.py status --host-id foo --status working

使主机退役。

$ mkr.py retire --host-id foo

获取主机的状态。

$ mkr.py status --host-id foo

身份验证

$ exportMACKEREL_APIKEY=foobar

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java编辑并重新运行spring引导单元测试,无需重新加载上下文即可加快测试速度   为什么我不能做演员?   java为什么是线程。join通常用于停止安卓中的线程   java从weblogic服务器调用JSON POST REST服务时收到400:错误请求   java在DeviceAdmin模式禁用时设置身份验证?   java SortedMap的keySet()能否始终安全地强制转换到SortedSet?   安卓 java。lang.NoSuchMethodException可包裹类   java JOGL库安装   javatomcat内存管理   java使用getString()中的变量   java将最小星号设置为评级栏   Java中字符串相等的println()方法。。。它到底是如何工作的?   java如何从文本中输出的数组中放入随机图像