用python实现的mackerel客户端。

mackerel.clienthde的Python项目详细描述


https://travis-ci.org/HDE/py-mackerel-client.svg?branch=hde-devhttps://coveralls.io/repos/github/HDE/py-mackerel-client/badge.svg?branch=hde-dev

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

这个项目是从heavenshell/py-mackerel-client派生的,最初是从mackerel-client-ruby移植的。

安装

$ pip install mackerel.clienthde

依赖性

requestssimplejsonclick

用法

获取主机

frommackerel.clienthdeimportClient# 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()

获得主机

frommackerel.clienthdeimportClient# 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>')

更新主机状态

frommackerel.clienthdeimportClient# 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')

退出主机

frommackerel.clienthdeimportClient# 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>')

获取最新指标

frommackerel.clienthdeimportClient# 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'])

后指标

frommackerel.clienthdeimportClient# 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)

服务后指标

frommackerel.clienthdeimportClient# 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)

获取监视器[此分叉版本中的新功能]

frommackerel.clienthdeimportClient# 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()# list all Monitors# Specify list of ids to search, return a dict with id as keymonitor_targets=client.get_monitors(ids=['1ABCDabcde1'])

创建监视器[在此分叉版本中新建]

frommackerel.clienthdeimportClient# Alternatively, you can set MACKEREL_APIKEY as environment variable# And simply call "client = Client()"client=Client(mackerel_api_key='<Put your API key')# Create monitor as specified in https://mackerel.io/api-docs/entry/monitors#createparams={'type':'service','name':'ConsumedReadCapacityUnits.table-name','service':'HDE','duration':1,'metric':'ConsumedReadCapacityUnits.table-name','operator':'>','warning':700,'critical':900}# Post params to Mackerel# result['id'] will give Monitor id if create operation succeededresult=client.create_monitor(params)

更新监视器[此分叉版本中的新功能]

frommackerel.clienthdeimportClient# Alternatively, you can set MACKEREL_APIKEY as environment variable# And simply call "client = Client()"client=Client(mackerel_api_key='<Put your API key')# Since update Monitor requires all fields to be specified,# it is suggested to retrieve the latest value firstmonitor_id='1ABCDabcde1'monitors=client.get_monitors(ids=[monitor_id])monitor=monitors[monitor_id]# In this example, we assume Monitor is class of MonitorServicemonitor.warning=800monitor.critical=1000# Update params to Mackerelresult=client.update_monitor(monitor_id=monitor_id,monitor_params=monitor._to_post_params_dict())

删除监视器[在此分叉版本中新增]

frommackerel.clienthdeimportClient# Alternatively, you can set MACKEREL_APIKEY as environment variable# And simply call "client = Client()"client=Client(mackerel_api_key='<Put your API key')# Delete Monitorresult=client.delete_monitor(monitor_id='1ABCDabcde1')

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 Android:在ListView上使用setOnItemClickListener   使用Netbeans 7.0连接到SQL Server的java正在挂起   java Spring3依赖项注入不适用于mule   java Flink SQL结果字段与LocalDateTime上请求的类型错误不匹配   java找不到文件的结尾   考虑到NamingStrategy,java有没有办法将字符串转换为JsonNode?   使用Netbeans/ant部署java(命令行)应用程序   java如何修复Spring引导多部分上载中的“所需请求部分不存在”   java在应用程序启动时通过引用获取映射未知目标实体属性异常   java形状旋转问题Java2d   Weblogic服务器上的java ExecuteAndWaitInterceptor问题   JavaSpringBoot:project将图像保存在错误的路径中,并且在使用IDEIntellji打开时不显示图像   类向java接口添加方法   Swing组件上的Java 7泛型   sql server如何从java获取用户名。sql。联系   java如何检查该行是否与正则表达式(regex)冲突?   java如何在spring引导安全中为计数失败登录设置验证登录为false   图像如何在Java中使PNG的白色透明?