Beispiel #1
0
def init(init_type='plaintext_tcp', *args, **kwargs):
    """
    Create the module instance of the GraphiteClient.
    """
    global _module_instance
    graphitesend.reset()

    validate_init_types = ['plaintext_tcp', 'plaintext', 'pickle_tcp',
                           'pickle', 'plain']

    if init_type not in validate_init_types:
        raise graphitesend.GraphiteSendException(
            "Invalid init_type '%s', must be one of: %s" %
            (init_type, ", ".join(validate_init_types)))

    # Use TCP to send data to the plain text receiver on the graphite server.
    if init_type in ['plaintext_tcp', 'plaintext', 'plain']:
        _module_instance = MyGraphiteClient(*args, **kwargs)

    # Use TCP to send pickled data to the pickle receiver on the graphite
    # server.
    if init_type in ['pickle_tcp', 'pickle']:
        _module_instance = MyGraphiteClient(*args, **kwargs)

    return _module_instance
Beispiel #2
0
 def setUp(self):
     """ reset graphitesend """
     # Drop any connections or modules that have been setup from other tests
     graphitesend.reset()
     # Monkeypatch the graphitesend so that it points at a graphite service
     # running on one of my ([email protected]) systems.
     # graphitesend.default_graphite_server = 'graphite.dansysadm.com'
     graphitesend.default_graphite_server = 'localhost'
     import os
     self.hostname = os.uname()[1]
Beispiel #3
0
 def setUp(self):
     """ reset graphitesend """
     # Drop any connections or modules that have been setup from other tests
     graphitesend.reset()
     graphitesend.default_graphite_server = 'localhost'
     self.hostname = os.uname()[1]
Beispiel #4
0
 def tearDown(self):
     """ reset graphitesend """
     # Drop any connections or modules that have been setup from other tests
     graphitesend.reset()
Beispiel #5
0
 def test_reset(self):
     graphitesend.init()
     graphitesend.reset()
     graphite_instance = graphitesend._module_instance
     self.assertEqual(graphite_instance, None)
def migrate_one_server( srv ):
   
   params_get_params_unique  = {
      'target':'t1'  ,
      'target':'t2'
   }

   params2  = MultiDict([
      ('1', '2'), 
      ('1', '3')
   ])

   params2  = MultiDict([
      ('format' , 'json'                             ),
      ('target' , prefix_from + srv + '.*.*.*.*.*'   ),
      ('target' , prefix_from + srv + '.*.*.*.*'     ),
      ('target' , prefix_from + srv + '.*.*.*'       ),
      ('target' , prefix_from + srv + '.*.*'         ),
      ('from_old' , '-144minutes'                    ),
      ('from'  , str_day_start                       ),
      ('until' , str_day_end                         )
   ])

   # I needed to submit multiple similar get params to graphite API.
   # No, an array-param does not work.
   # All I tried was in vain.
   # The only way to submit repetitive get params is by concatenating them on the url
   params2 = {}

   url= 'http://'+ graphite_server_dns +'/render/'
   url= 'http://'+ graphite_server_dns +'/render/?format=json'
   url += '&target='+ prefix_from + srv + '.*.*.*.*.*'
   url += '&target='+ prefix_from + srv + '.*.*.*.*'
   url += '&target='+ prefix_from + srv + '.*.*.*'
   url += '&target='+ prefix_from + srv + '.*.*'
   url += '&from='  + str_day_start
   url += '&until=' + str_day_end

   resp = requests.get(url=url, params=params2)
   data = json.loads(resp.content)
    
   #print data
   
   count_targets = len(data)
      
   print "json data loaded - Anzahl targets: ", count_targets
   #print data[1]['target']
   #print data[1]['datapoints']
   

   i1 = 0
   data_by_timestamp = {}
   for metric in data:
      tg = metric['target']
      tg = tg.replace( prefix_from , prefix_to  );

      if i1 < 4 :
         print tg
      if i1 == 4:
         print "..."

      #print metric['datapoints']
      i11 = 0
      for dp in metric['datapoints']:
         ts = dp[1]
         mv = dp[0]
         i11+=1
         if i11  < 4  and i1 < 4:
            print ts,mv
         if i11 == 4  and i1 < 4:
            print "..."
         if mv == 'None' or mv is None :
            #print 'skipping Null - None ', mv
            continue
         #g.send( tg, float(mv), ts )    # this would be single pickle sender

         if str(ts) in data_by_timestamp:
            data_by_timestamp[str(ts)].update( {tg:mv} )   # append metric + value
         else:
            data_by_timestamp[str(ts)]= {tg:mv}            # first  metric + value
      i1+=1
      if i1 > 5000:
         print "more than 5000 metrics for one host - check this"
         sys.exit(0)
 

   #print data_by_timestamp
   print "send by timestamp"

  #g = graphitesend.init( graphite_server=graphite_server_dns , prefix=prefix_to, system_name=srv )
   g = graphitesend.init( graphite_server=graphite_server_dns , prefix='', system_name='' )

   i3=0
   for lp_ts in data_by_timestamp:
      i3+=1
      if i3 < 4 :
        print 'sending ts data' , lp_ts
        print '    '  +   str(data_by_timestamp[lp_ts])[:110] + " ... "
      g.send_dict( data_by_timestamp[lp_ts], int(lp_ts) )  


   graphitesend.reset()

   return
Beispiel #7
0
 def setUp(self):
     """ reset graphitesend """
     # Drop any connections or modules that have been setup from other tests
     graphitesend.reset()
     graphitesend.default_graphite_server = 'localhost'
     self.hostname = os.uname()[1]