Use pickle protocol through rubypython

Asked by Ana Rosas

Hi,
I'm currently using graphite in for a Ruby on Rails app, we would like to pass batches of metrics to carbon via the pickle protocol, but knowing it's on python, I decided to use the RubyPython gateway. Here's my code,

      RubyPython.start
      stats= "[(path,(#{2.months.ago.to_i}, 10000))]"
      cPickle = RubyPython.import 'cPickle'
      serialized_stats = cPickle.dumps(stats, protocol=-1)
      struct = RubyPython.import 'struct'
      length = serialized_stats.rubify.length.to_i
      puts length
      header = struct.pack("!L", length)
      message = header + serialized_stats
      socket.write(message)
      RubyPython.stop
      socket.close

Everything works fine, no errors in the ruby side, but in the carbon-cache server I get this error

25/05/2012 12:42:05 :: [console] Unhandled Error
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/twisted/python/log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/usr/local/lib/python2.7/site-packages/twisted/python/log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/usr/local/lib/python2.7/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python2.7/site-packages/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/usr/local/lib/python2.7/site-packages/twisted/internet/selectreactor.py", line 150, in _doReadOrWrite
    why = getattr(selectable, method)()
  File "/usr/local/lib/python2.7/site-packages/twisted/internet/tcp.py", line 199, in doRead
    rval = self.protocol.dataReceived(data)
  File "/usr/local/lib/python2.7/site-packages/twisted/protocols/basic.py", line 755, in dataReceived
    self.stringReceived(packet)
  File "/opt/graphite/lib/carbon/protocols.py", line 93, in stringReceived
    for (metric, datapoint) in datapoints:

hope anyone can give me a clue to solve this
thanks!!!

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
Ana Rosas
Solved:
Last query:
Last reply:
Revision history for this message
Ana Rosas (a-rosas10) said :
#1

My bad i was sending it as string and not as tuple

Revision history for this message
Paul (thenut-d) said :
#2

I know this is pretty old, but I'm looking to do the same thing and having the same problem. Can you explain what changes you made to get this interpreted as a tuple?

Thanks!