Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 21 additions and 72 deletions.
  1. +21 −72 ZenPacks/community/RabbitMQ/parsers/RabbitMQAPI.py
View
93 ZenPacks/community/RabbitMQ/parsers/RabbitMQAPI.py
@@ -21,36 +21,6 @@
from Products.ZenRRD.CommandParser import CommandParser
-def getTempFilename(keys):
- return os.path.join(
- tempfile.gettempdir(),
- '.zenoss_rabbitmq_%s' % md5.md5('+'.join(keys)).hexdigest())
-
-
-def saveData(keys, data):
- tmpfile = getTempFilename(keys)
- tmp = open(tmpfile, 'w')
- json.dump(data, tmp)
- tmp.close()
-
-
-def loadData(keys, expiration=1800):
- tmpfile = getTempFilename(keys)
- if not os.path.isfile(tmpfile):
- return None
-
- # Make sure temporary data isn't too stale.
- if os.stat(tmpfile).st_mtime < (time.time() - expiration):
- os.unlink(tmpfile)
- return None
-
- tmp = open(tmpfile, 'r')
- data = json.load(tmp)
- tmp.close()
-
- return data
-
-
class RabbitMQAPI(CommandParser):
eventKey = eventClassKey = 'rabbitmq_node_status'
@@ -103,7 +73,7 @@ def processListConnectionsResults(self, cmd, result):
# Rather than not record data when no connections are open we need to
# records zeros.
if len(connections) < 1:
- for metric in gauge_metrics
+ for metric in gauge_metrics:
if metric in dp_map:
result.values.append((dp_map[metric], 0))
@@ -123,67 +93,46 @@ def processListConnectionsResults(self, cmd, result):
if 'sendQueue' in dp_map:
result.values.append((dp_map['sendQueue'], reduce(
lambda x, y: x + y,
- (x['sendQueue'] for x in connections))))
+ (x['send_pend'] for x in connections))))
def processListChannelsResults(self, cmd, result):
- channels = {}
-
- for line in cmd.result.output.split('\n'):
- if not line:
- continue
-
- fields = re.split(r'\s+', line.rstrip())
-
- # pid consumer_count messages_unacknowledged acks_uncommitted
- if len(fields) != 4:
- return
-
- channels[fields[0]] = dict(
- consumers=int(fields[1]),
- unacknowledged=int(fields[2]),
- uncommitted=int(fields[3]),
- )
+ channels = json.loads(result)
dp_map = dict([(dp.id, dp) for dp in cmd.points])
- metrics = ('consumers', 'unacknowledged', 'uncommitted')
+ # dict of dp name to API name
+ metrics = {'consumers': 'consumer_count',
+ 'unacknowledged': 'messages_unacknowledged',
+ 'uncommitted': 'acks_uncommitted',
+ }
# Rather than not record data when no connections are open we need to
# records zeros.
- if len(channels.keys()) < 1:
- for metric in metrics:
+ if len(channels) < 1:
+ for metric in metrics.keys():
if metric in dp_map:
result.values.append((dp_map[metric], 0))
return
- for metric in metrics:
+ for metric in metrics.keys():
if metric in dp_map:
result.values.append((dp_map[metric], reduce(
lambda x, y: x + y,
- (x[metric] for x in channels.values()))))
+ (x[metrics[metric]] for x in channels))))
def processListQueuesResults(self, cmd, result):
- queues = {}
+ queuedata = json.loads(result)
- for line in cmd.result.output.split('\n'):
- if not line:
- continue
-
- fields = re.split(r'\s+', line.rstrip())
-
- # name messages_ready messages_unacknowledged messages consumers
- # memory
- if len(fields) != 6:
- return
-
- queues[fields[0]] = dict(
- ready=int(fields[1]),
- unacknowledged=int(fields[2]),
- messages=int(fields[3]),
- consumers=int(fields[4]),
- memory=int(fields[5]),
+ queues = {}
+ for queue in queuedata:
+ queues[queuedata['name']] = dict(
+ ready = queuedata['messages_ready'],
+ unacknowledged = queuedata['messages_unacknowledged'],
+ messages = queuedata['messages'],
+ consumers = queuedata['consumers'],
+ memory = queuedata['memory'],
)
if len(queues.keys()) < 1:

No commit comments for this range

Something went wrong with that request. Please try again.