跳转到主要内容

Juju数据库自省

项目描述

提供自省工具以了解系统状态,包括通常是透明的关联数据。

这是一个面向高级用户的诊断或检查环境状态的辅助工具。

*风险自担。这可能在不同版本的juju之间导致损坏*

这非常具体于特定juju版本的底层数据库结构,这是一个可能在不提前通知的情况下更改的实现细节。

尽管如此,这里的实现适用于所有现有的juju核心版本。然而,过去的成功不能保证未来的兼容性。

*不要写入数据库*

不要尝试写入这些结构中的任何一个,会发生糟糕的事情,并且你必须保留所有损坏的内容。如果你需要修改某些内容,请使用juju api。Juju使用mongodb客户端事务库,该库可以原子地执行多文档修改,并且依赖于所有写入者使用相同的txn库。更多详细信息请在此处查看

http://blog.labix.org/2012/08/22/multi-doc-transactions-for-mongodb

安装

通过pypi可用,依赖项是pymongo和pyyaml

$ pip install juju-dbinspect

根据你的提供商和juju版本,你可能需要打开状态服务器(如果不是ha,则为机器0)上的端口37017的访问权限。

CLI简介

CLI用法通过内置的帮助进行文档记录

$ juju db --help

juju db --help
usage: juju-db [-h] [-e ENVIRONMENT] [-v] targets [targets ...]

Juju database introspection

  Drop into an interactive python shell.
    $ juju db shell

  Get the last n transactions (default 100) that have modified the
  environment.
    $ juju db history [n]

  Get the names of all the services in the system.
    $ juju db services

  Get the names of all the units in the system.
    $ juju db units

  Get the details on machine 0.
    $ juju db 0

  Get the details on the unit mysql/0.
    $ juju db mysql/0

  Get the details on the mysql service::
    $ juju db mysql

  Get the relation settings for the mysql/0 unit in the wordpress relation::
    $ juju db mysql/0 wordpress


positional arguments:
  targets

optional arguments:
  -h, --help            show this help message and exit
  -e ENVIRONMENT, --environment ENVIRONMENT
                      Juju environment to operate on
  -v, --verbose         Verbose output

数据库交互式Shell

还可以通过具有相同核心功能的Python交互式Shell访问数据库。可以使用以下命令启动shell:

kapil@realms-slice:~$ juju db shell -e syracuse
Juju DB Shell
>>>

基本实体迭代命令

>>> units()
[u'message/0', u'db/0', u'identity/0', u'meter/0']
>>> machines()
[u'0', u'230', u'232', u'233', u'231']
>>> services()
[u'db', u'identity', u'message', u'meter']
>>> pprint(relations())
[u'db:cluster',
 u'message:cluster',
 u'identity:cluster',
 u'meter:identity-service identity:identity-service',
 u'identity:shared-db db:shared-db',
 u'meter:amqp message:amqp']

让我们检查机器0的约束

>> machine('0').constraints
  {u'cpupower': None, u'container': None, u'cpucores': None,
   u'mem': None, u'arch': None, u'rootdisk': None}

机器230上有哪些单位

>> machine('230').units

meter/0单位发生了什么

>>> pprint(unit('meter/0'))

{u'_id': u'meter/0',
 u'charmurl': u'local:precise/ceilometer-52',
 u'life': 0,
 u'machineid': u'233',
 u'ports': [{u'number': 8777, u'protocol': u'tcp'}],
 u'principal': u'',
 u'privateaddress': u'10.0.3.103',
 u'publicaddress': u'10.0.3.103',
 u'resolved': u'',
 u'series': u'precise',
 u'service': u'meter',
 u'subordinates': [],
 u'tools': {u'sha256': u'',
            u'size': 0L,
            u'url': u'',
            u'version': u'1.17.3.1-precise-amd64'}}


 >>> unit('meter/0').status
 {u'status': u'started', u'statusinfo': u'', u'statusdata': {}}

让我们检查身份与计费服务之间的关系,并查看它们单位的关联数据

>>> unit('meter/0').relation_data('identity')
 {u'_id': u'r#190#requirer#meter/0',
  u'admin_url': u'http://10.0.3.103:8777',
  u'internal_url': u'http://10.0.3.103:8777',
  u'private-address': u'10.0.3.103',
  u'public_url': u'http://10.0.3.103:8777',
  u'region': u'RegionOne',
  u'requested_roles': u'ResellerAdmin',
  u'service': u'ceilometer'}

>>> unit('identity/0').relation_data('meter')
 {u'_id': u'r#190#provider#identity/0',
  u'admin_token': u'witieweithoinaiwuojeFiepuneiseye',
  u'auth_host': u'10.0.3.27',
  u'auth_port': u'35357',
  u'auth_protocol': u'https',
  u'ca_cert': u'omitted for brevity',
  u'https_keystone': u'True',
  u'private-address': u'10.0.3.27',
  u'service_host': u'10.0.3.27',
  u'service_password': u'eingahVeehivaiHahnohngahTooYizei',
  u'service_port': u'5000',
  u'service_protocol': u'https',
  u'service_tenant': u'services',
  u'service_username': u'ceilometer',
  u'ssl_cert': u'omitted for brevity',
  u'ssl_key': u'omitted for brevity'}
>>>

我们还可以通过检查事务日志来查看环境的历史记录

>>> history()

2014/03/06-19:31:39 applied
  units:message/0 update {u'$set': {u'privateaddress': u'10.0.3.215'}}
2014/03/06-19:31:39 applied
  units:message/0 update {u'$set': {u'publicaddress': u'10.0.3.215'}}
2014/03/06-19:31:40 applied
  settingsrefs:s#message#local:precise/rabbitmq-server-146 update {u'$inc': {u'refcount': 1}}
  units:message/0 update {u'$set': {u'charmurl': u'local:precise/rabbitmq-server-146'}}
2014/03/06-19:33:07 applied
  units:message/0 update {u'$addToSet': {u'ports': {u'protocol': u'tcp', u'number': 5672}}}
2014/03/06-19:33:08 applied
  units:message/0 cond {u'life': {u'$ne': 2}}
  statuses:u#message/0 update {u'$set': {u'status': u'installed', u'statusdata': {}, u'statusinfo': u''}}
2014/03/06-19:33:08 applied
  units:message/0 update {u'$pull': {u'ports': {u'protocol': u'tcp', u'number': 55672}}}
2014/03/06-19:33:09 applied
  units:message/0 update {u'$addToSet': {u'ports': {u'protocol': u'tcp', u'number': 5671}}}
2014/03/06-19:33:13 applied
  units:message/0 cond {u'life': {u'$ne': 2}}
  statuses:u#message/0 update {u'$set': {u'status': u'started', u'statusdata': {}, u'statusinfo': u''}}
2014/03/06-19:33:13 applied
  units:message/0 cond {u'life': 0}
  relations:message:cluster update {u'$inc': {u'unitcount': 1}}
  settings:r#198#peer#message/0 create {u'private-address': u'10.0.3.215'}
  relationscopes:r#198#peer#message/0 create {u'_id': u'r#198#peer#message/0'}
2014/03/06-19:33:43 applied
  units:identity/0 cond {u'life': 0}
  relations:identity:cluster update {u'$inc': {u'unitcount': 1}}
  settings:r#197#peer#identity/0 create {u'private-address': u'10.0.3.80'}
  relationscopes:r#197#peer#identity/0 create {u'_id': u'r#197#peer#identity/0'}
2014/03/06-19:33:52 applied
  units:identity/0 cond {u'life': 0}
  relations:identity:shared-db db:shared-db update {u'$inc': {u'unitcount': 1}}
  settings:r#200#requirer#identity/0 create {u'private-address': u'10.0.3.80'}
  relationscopes:r#200#requirer#identity/0 create {u'_id': u'r#200#requirer#identity/0'}
2014/03/06-19:33:52 applied
  units:db/0 cond {u'life': 0}
  relations:identity:shared-db db:shared-db update {u'$inc': {u'unitcount': 1}}
  settings:r#200#provider#db/0 create {u'private-address': u'10.0.3.225'}
  relationscopes:r#200#provider#db/0 create {u'_id': u'r#200#provider#db/0'}
2014/03/06-19:33:52 applied
  units:message/0 cond {u'life': 0}
  relations:meter:amqp message:amqp update {u'$inc': {u'unitcount': 1}}
  settings:r#199#provider#message/0 create {u'private-address': u'10.0.3.215'}
  relationscopes:r#199#provider#message/0 create {u'_id': u'r#199#provider#message/0'}
2014/03/06-19:33:53 applied
  settings:r#199#provider#message/0 update {u'$set': {u'hostname':
  u'10.0.3.215', u'ssl_port': u'5671', u'ssl_ca':'value_omitted'}
  u'$unset': {}}

可用的辅助命令

  • 单元

  • 单元

  • 服务

  • 服务

  • 机器

  • 机器

  • 关系

  • 关系

  • 魅力

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

juju-dbinspect-0.1.6.1.tar.gz (10.2 kB 查看散列)

上传时间

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页