Exemplo n.º 1
0
    def open_spider(self, spider):
        self.timestamp = time.time()
        self.attraction_metric_map = spider.settings.get('ATTRACTION_METRIC_MAP')
        if self.attraction_metric_map is None or len(self.attraction_metric_map) == 0:
            raise KeyError('No ATTRACTION_METRIC_MAP defined in settings.py.')

        graphite_server = spider.settings.get('GRAPHITE_SERVER', self.default_graphite_server)
        graphite_port = spider.settings.get('GRAPHITE_PORT', self.default_graphite_port)
        log.msg("Using %s:%d as Graphite server" % (graphite_server, graphite_port), level=log.INFO, spider=spider)
        try:
            self.g = graphitesend.init(
                    graphite_server=graphite_server,
                    graphite_port=graphite_port,
                    prefix='',
                    system_name='')
        except graphitesend.GraphiteSendException, e:
            if spider.settings.get('GRAPHITE_DRYRUN_ENABLED', True):
                log.msg("Unable to connect to Graphite server %s:%d; will use dry run mode" % (graphite_server, graphite_port), level=log.WARNING, spider=spider)
                self.g = graphitesend.init(
                        prefix='',
                        system_name='',
                        dryrun=True)
            else:
                log.msg("Unable to connect to Graphite server %s:%d and dry run mode disabled" % (graphite_server, graphite_port), level=log.ERROR, spider=spider)
                raise e
 def run(self):
         while True:
                 graphitesend.init(graphite_server='localhost', system_name='', group='power', prefix='house')                        
                 try:
                         watts, temperature = get_data()
                         graphitesend.send_dict({'temperature':temperature, 'usage':watts})
                         time.sleep(5)
                 except (KeyboardInterrupt, SystemExit):
                         raise
                 except:
                         pass
                         
                 time.sleep(5)
Exemplo n.º 3
0
def graphite_send(**kwargs):
    try:
        g = graphitesend.init(prefix=settings.GRAPHITE_PREFIX + '.',
                              graphite_server=settings.GRAPHITE_HOST)
        g.send_dict(kwargs)
    except Exception:
        logging.getLogger('django').exception('Graphite is down')
Exemplo n.º 4
0
 def render(self):
     runtime = self.runtime
     metrics = {'upstream.repos.behind': 0,
                'upstream.repos.ahead': 0,
                'upstream.commits.ahead': 0,
                'upstream.commits.behind': 0}
     for repository in runtime.repositories.values():
         if repository.behind and repository.behind > 0:
             metrics['upstream.repos.behind'] += 1
             metrics['upstream.commits.behind'] += repository.behind
         if repository.ahead and repository.ahead > 0:
             metrics['upstream.repos.ahead'] += 1
             metrics['upstream.commits.ahead'] += repository.ahead
         for (name, diff) in repository.diffs.items():
             if diff.is_valid:
                 for r in ('repos', 'commits'):
                     for b in ('behind', 'ahead'):
                         if not metrics.has_key('%s.%s.%s' % (diff.target, r, b)):
                             metrics['%s.%s.%s' % (diff.target, r, b)] = 0
                 if diff.behind and diff.behind > 0:
                     metrics['%s.repos.behind' % diff.target] += 1
                     metrics['%s.commits.behind' % diff.target] += diff.behind
                 if diff.ahead and diff.ahead > 0:
                     metrics['%s.repos.ahead' % diff.target] += 1
                     metrics['%s.commits.ahead' % diff.target] += diff.ahead
     if not self.runtime.config.has_key('graphite_host'):
         logging.error('No graphite server in config file')
     else:
         if not self.runtime.config.has_key('graphite_prefix'):
             prefix = 'pytriage'
         else:
             prefix = self.runtime.config['graphite_prefix']
         logging.info('Sending data to graphite')
         g = graphitesend.init(prefix=prefix, system_name='', graphite_server=self.runtime.config['graphite_host'])
         g.send_dict(metrics)
Exemplo n.º 5
0
def main():
    free_raw_data = []
    free_data = {}
    for line in os.popen('free -m').readlines():
        line = line.strip()
        bits = line.split()

        if bits[0] == 'total':
            continue

        free_raw_data.append(bits[1:])

    # Parse the first line
    free_data['mem.total'] = free_raw_data[0][0]
    free_data['mem.used'] = free_raw_data[0][1]
    free_data['mem.free'] = free_raw_data[0][2]
    free_data['mem.share'] = free_raw_data[0][3]
    free_data['mem.buffers'] = free_raw_data[0][4]
    free_data['mem.cached'] = free_raw_data[0][5]
        
    # Parse the 2nd line
    free_data['mem.used_minus_buffers'] = free_raw_data[1][1]
    free_data['mem.free_minus_buffers'] = free_raw_data[1][2]

    # Parse the 3rd line
    free_data['swap.total'] = free_raw_data[2][0]
    free_data['swap.used'] = free_raw_data[2][1]
    free_data['swap.free'] = free_raw_data[2][2]

    # Print the results
    g = graphitesend.init(dryrun=True, prefix="free")
    print g.send_dict(free_data)
Exemplo n.º 6
0
def send_metric(waittime):
    g = graphitesend.init(graphite_server='xxx', graphite_port=2003, system_name='checkdownload')
    try:
        g.send('time', waittime)
        log.info(' sent data to graphite server')
    except(TypeError, GraphiteSendException) as e:
        log.error('can not send data to graphite server')
Exemplo n.º 7
0
 def test_send_list_metric_value_timestamp_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='')
     # Make sure it can handle custom timestamp
     response = graphite_instance.send_list(
         [('metric', 1, 1), ('metric', 1, 2)])
     # self.assertEqual('sent 46 long message:' in response, True)
     self.assertEqual('test.metric 1.000000 1' in response, True)
     self.assertEqual('test.metric 1.000000 2' in response, True)
Exemplo n.º 8
0
 def test_send_list_metric_value_single_timestamp(self):
     # Make sure it can handle custom timestamp
     graphite_instance = graphitesend.init(prefix='test')
     response = graphite_instance.send_list([('metric', 1)], timestamp=1)
     # self.assertEqual('sent 23 long message: test.metric' in response,
     # True)
     self.assertEqual('1.00000' in response, True)
     self.assertEqual(response.endswith('1\n'), True)
Exemplo n.º 9
0
    def __init__(self, units='celsius', host='graphite.example.com',
                 port=2003, prefix='braubuddy'):

        self._api = graphitesend.init(
            graphite_server=host,
            graphite_port=port,
            prefix=prefix,
            system_name='',
        )
        super(GraphiteAPIOutput, self).__init__(units)
Exemplo n.º 10
0
 def cnt_gsend(self):
     if "CNT_TYPE" in environ:
         pre = "psutil.%s" % environ["CNT_TYPE"]
     else:
         pre = "psutil.notype"
     try:
         self._gsend = graphitesend.init(graphite_server=self._cfg["--carbon-host"], prefix=pre)
     except graphitesend.GraphiteSendException:
         time.sleep(5)
         self.cnt_gsend()
Exemplo n.º 11
0
 def test_clean_metric(self):
     g = graphitesend.init()
     #
     metric_name = g.clean_metric_name('test(name)')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test name')
     self.assertEqual(metric_name, 'test_name')
     #
     metric_name = g.clean_metric_name('test  name')
     self.assertEqual(metric_name, 'test__name')
Exemplo n.º 12
0
 def test_send_list_metric_value_timestamp_default_2(self):
     graphite_instance = graphitesend.init(prefix='test', system_name='foo')
     # Make sure it can handle custom timestamp, fill in the missing with
     # the current time.
     response = graphite_instance.send_list(
         [
             ('metric', 1),
             ('metric', 2, 2),
         ],
         timestamp='4'
     )
     # self.assertEqual('sent 69 long message:' in response, True)
     self.assertEqual('test.foo.metric 1.000000 4' in response, True)
     self.assertEqual('test.foo.metric 2.000000 2' in response, True)
Exemplo n.º 13
0
 def __init__(self,
              application,
              graphite_host,
              graphite_port,
              graphite_prefix):
     if not graphitesend:
         raise ImportError("graphite middleware configured, but no graphite python module found. "
                           "Please install the python graphitesend module to use this functionality.")
     self.application = application
     try:
         self.graphite_client = graphitesend.init(graphite_server=graphite_host, graphite_port=int(graphite_port), prefix=graphite_prefix.rstrip('.'))
     except graphitesend.graphitesend.GraphiteSendException:
         self.graphite_client = None
         log.exception("Could not instantiate graphite metrics logger. It will be disabled until Galaxy restart")
 def __init__(self,
              application,
              graphite_host,
              graphite_port,
              graphite_prefix):
     if not graphitesend:
         raise ImportError("graphite middleware configured, but no graphite python module found. "
                           "Please install the python graphitesend module to use this functionality.")
     self.application = application
     try:
         self.graphite_client = graphitesend.init(graphite_server=graphite_host, graphite_port=int(graphite_port), prefix=graphite_prefix.rstrip('.'))
     except graphitesend.graphitesend.GraphiteSendException:
         self.graphite_client = None
         log.exception("Could not instantiate graphite metrics logger. It will be disabled until Galaxy restart")
Exemplo n.º 15
0
    def op_nok(self, operations):
        try:
            counter = Counter([ns['ns'] for ns in operations])
            graphite = graphitesend.init(**self.params.get('graphitesend_params', {}))

            graphite.send('total', sum(counter.values()))
            if self.params.get('metric_per_ns'):
                graphite.send_dict(counter)
        except Exception as e:
            logging.error('unable to run :: {} :: {}'.format(self.name, e))
            return False
        else:
            logging.info('run :: {} :: send OK'.format(self.name))
            return True
Exemplo n.º 16
0
    def op_nok(self, operations):
        try:
            counter = Counter([ns['ns'] for ns in operations])
            graphite = graphitesend.init(
                **self.params.get('graphitesend_params', {}))

            graphite.send('total', sum(counter.values()))
            if self.params.get('metric_per_ns'):
                graphite.send_dict(counter)
        except Exception as e:
            logging.error('unable to run :: {} :: {}'.format(self.name, e))
            return False
        else:
            logging.info('run :: {} :: send OK'.format(self.name))
            return True
Exemplo n.º 17
0
def send_graphite(df, benchdate):
    hostname, branch, commit = get_meta_triplet()
    # graphite data is prefixed with {hostname}.{branch}
    print(header_template.format(f"Beginning Upload for: {hostname}.{branch}"))

    try:
        g = graphitesend.init(graphite_server=GRAPHITE_SERVER, prefix=f"{hostname}.{branch}", system_name='')
        for name, row in df.iterrows():
            idx = name.find('_')
            if idx:
                name = list(name); name[idx] = '.'; name = ''.join(name)
            print("Uploading: {}, {}, timestamp: {}".format(name, row.cpu_time, benchdate.timestamp()))
            g.send(name, row['cpu_time'], timestamp=benchdate.timestamp())
    except Exception as e:
        print("WARNING: Couldn't send data to Graphite!")
        print(e)
Exemplo n.º 18
0
 def graphite_send(self, name, value, guid, suffix,
                     host_name, component_name="default"):
     """
     call Graphite platform using graphitesend
     """
     # replace fqdn with underscores
     host_name = re.sub(r"\.", "_", host_name)
     host_name = self.config.get('localhost_name', host_name)
     suffix = "_{0}".format(suffix)
     prefix = "graphite_agent.{0}.{1}".format(host_name, guid)
     timeout = self.config.get('graphite_timeout', 2)
     g = graphitesend.init(prefix=prefix, suffix=suffix,
         graphite_server=self.config.application['graphite_host'],
         graphite_port=self.config.application['graphite_port'],
         system_name=component_name, timeout_in_seconds=timeout)
     g.send(name, value)
Exemplo n.º 19
0
 def _updatedb(self, temp, duty):
     try:
         logfile = "/mnt/ramdisk/" + self.name
         with open (logfile, 'w+') as f: f.write(str(temp))
     except:
         print "Error writing to ramdisk file"
     #send to graphite
     if self.state == "control":
         target=self.target
     else:
         target=0
     summary = {'temperature':temp, 'target':target, 'duty':duty}
     
     try:
         graph = graphitesend.init(graphite_server='192.168.1.3',prefix="brewing", system_name=self.name)
         graph.send_dict(summary) 
     except:
         print("error sending to graphite")
         traceback.print_exc() 
Exemplo n.º 20
0
def send_metrics(whisper_file, time_stamp, value, args):
    """
    Send a given whisper file's data to InfluxDB
    :param whisper_file: The compelte path to the whisper file.
    :param time_stamp:  The time stamp for value in unix epoch
    :param value: The value of the metric at time timestamp
    :param args: the configparser object
    """
    metric = get_metric_name(whisper_file)
    system_name = metric.split('.', 1)[0]
    metric_name = metric.split('.', 1)[1]

    print metric_name
    g = graphitesend.init(prefix='',
                          system_name=system_name,
                          graphite_server=args.influxdb_host,
                          graphite_port=int(args.influxdb_port))
    g.send(metric=metric_name, value=value, timestamp=float(time_stamp))
    # Sleep for 50 millisecond, to give influxDB time to write the points
    time.sleep(0.02)
Exemplo n.º 21
0
def main():
    hostname = sys.argv[1]
    print('Starting hostname={}'.format(hostname))

    print('Init graphitesend')
    g = graphitesend.init(graphite_server=os.environ['GRAPHITE_SERVER'],
                          graphite_port=int(os.environ['GRAPHITE_PORT']),
                          prefix='ping.{}'.format(hostname.replace('.', '_')))

    while True:
        start = time.time()
        delay = ping.do_one(hostname, 2)

        if delay:
            print('delay={}'.format(delay))
            g.send('time', delay)
        else:
            print('timeout')

        end = time.time()
        if end - start < INTERVAL:
            time.sleep(INTERVAL - end + start)
Exemplo n.º 22
0
)

options, arguments = cmdline.parse_args()

if not options.userid:
    cmdline.error("Evohome userid must be specified")

if not options.password:
    cmdline.error("Evohome password must be specified")

client = EvohomeClient(options.userid, options.password)

locationid = client.installation_info[0]["locationInfo"]["locationId"]

graphitesend.init(
    prefix="evohome",
    graphite_server=options.graphitehost,
    graphite_port=options.graphiteport,
    system_name=locationid,
    lowercase_metric_names=True,
)

metrics = {}
for device in client.temperatures():
    if device["thermostat"] is "DOMESTIC_HOT_WATER":
        metrics["water.temp"] = device["temp"]
    else:
        metrics["heating.{0}.setpoint".format(device["name"])] = device["setpoint"]
        metrics["heating.{0}.temp".format(device["name"])] = device["temp"]
graphitesend.send_dict(metrics)
Exemplo n.º 23
0
        while True:
            self.read_and_forward()
            time.sleep(self.interval)

    def read_and_forward(self):
        #cur_game_time = self.vessel.met*1000
        for one_telem_name, one_telem_callback in self.telemetries:
            self.g.send(one_telem_name, one_telem_callback(self.vessel))
        print "forwarded"


import graphitesend
if __name__ == "__main__":
    #GRAPHITE
    g = graphitesend.init(graphite_server="192.168.254.100",
                          system_name="active_vessel",
                          prefix="ksp")

    #KRPC
    conn = krpc.connect(address="localhost", name="telemetry_monitor")

    list_o_telems = [
        ("resource.ElectricCharge",
         lambda x: x.resources.amount("ElectricCharge")),
        ("resource.LiquidFuel", lambda x: x.resources.amount("LiquidFuel")),
        ("resource.Oxidizer", lambda x: x.resources.amount("Oxidizer")),
        ("resource.Monopropellant",
         lambda x: x.resources.amount("Monopropellant")),
        ("resource.Ablator", lambda x: x.resources.amount("Ablator")),
        ("resource.Ore", lambda x: x.resources.amount("Ore")),
        ("physics.thrust", lambda x: x.thrust)
Exemplo n.º 24
0
 def test_create_graphitesend_instance(self):
     g = graphitesend.init()
     expected_type = type(graphitesend.GraphiteClient())
     g_type = type(g)
     self.assertEqual(g_type, expected_type)
Exemplo n.º 25
0
 def testDryrunConnectFailure(self):
     g = graphitesend.init(prefix='', dryrun=True)
     self.assertEqual(type(g).__name__, 'GraphiteClient')
     with self.assertRaises(graphitesend.GraphiteSendException):
         g.connect()
Exemplo n.º 26
0
 def testEmptyAddr(self):
     g = graphitesend.init(prefix='', dryrun=True)
     self.assertEqual(g.addr, None)
Exemplo n.º 27
0
#!/usr/bin/env python
import graphitesend

g = graphitesend.init(group='meminfo.',
                      suffix='_mb',
                      lowercase_metric_names=True)
data = []
for line in open('/proc/meminfo').readlines():
    bits = line.split()

    # We dont care about the pages.
    if len(bits) == 2:
        continue

    # remove the : from the metric name
    metric = bits[0]
    metric = metric.replace(':', '')

    # Covert the default kb into mb
    value = int(bits[1])
    value = value / 1024

    data.append((metric, value))

print(g.send_list(data))
Exemplo n.º 28
0
 def test_no_system_name(self):
     g = graphitesend.init(group='foo')
     custom_prefix = g.prefix
     expected_prefix = 'systems.%s.foo.' % self.hostname
     self.assertEqual(custom_prefix, expected_prefix)
Exemplo n.º 29
0
 def test_empty_system_name(self):
     g = graphitesend.init(system_name='')
     custom_prefix = g.prefix
     expected_prefix = 'systems.'
     self.assertEqual(custom_prefix, expected_prefix)
Exemplo n.º 30
0
 def test_system_name(self):
     g = graphitesend.init(system_name='remote_host')
     custom_prefix = g.prefix
     expected_prefix = 'systems.remote_host.'
     self.assertEqual(custom_prefix, expected_prefix)
Exemplo n.º 31
0
 def test_set_lowercase_metric_names(self):
     g = graphitesend.init(lowercase_metric_names=True)
     self.assertEqual(g.lowercase_metric_names, True)
Exemplo n.º 32
0
#!/usr/bin/env python
import graphitesend

g = graphitesend.init(group='meminfo.', suffix='_mb',
                      lowercase_metric_names=True)
data = []
for line in open('/proc/meminfo').readlines():
    bits = line.split()

    # We dont care about the pages.
    if len(bits) == 2:
        continue

    # remove the : from the metric name
    metric = bits[0]
    metric = metric.replace(':', '')

    # Covert the default kb into mb
    value = int(bits[1])
    value = value / 1024

    data.append((metric, value))

print(g.send_list(data))
Exemplo n.º 33
0
 def test_monkey_patch_of_graphitehost(self):
     g = graphitesend.init()
     custom_prefix = g.addr[0]
     self.assertEqual(custom_prefix, 'localhost')
import psycopg2
import graphitesend
import threading
import logging
from psycopg2.extras import RealDictCursor
from psycopg2.pool import SimpleConnectionPool
from datetime import timedelta

event = threading.Event()
g = graphitesend.init(prefix='server_status',
                      graphite_server='localhost',
                      system_name='')
logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s %(levelname)s  - %(message)s')


class GetVaneQServersInfo:
    def __init__(self, **kwargs):
        self.pool = SimpleConnectionPool(minconn=2, maxconn=5, **kwargs)
        self.filter_item = [
            'name', 'mac_address', 'version', 'capabilities', 'drb_uri',
            'ipaddress', 'upgrade_message', 'build', 'guid'
        ]

    def _get_data(self, conn):
        with conn.cursor(cursor_factory=RealDictCursor) as cur:
            cur.execute('SELECT * FROM miq_servers')
            result = cur.fetchall()
        return result

    def _parse_data(self, conn):
Exemplo n.º 35
0
    prices = urllib2.urlopen(req2)
    currprice = prices.read()
    pricedata = simplejson.loads(currprice)
except urllib2.HTTPError, e:
    e.fp.read()



elecperDay = 1.3 * 0.12 * 24 * activeWorkers / 1.26
# rought approximation of 1.3kw per miner at 15cents CDN with 1.26 hard coded exchange rate

USDBTC = pricedata["bpi"]["USD"]["rate"]
USDBTC = float(USDBTC.replace(',', ''))
print USDBTC

usdPerDay = USDBTC * btcPerDay
profitperDay = usdPerDay - elecperDay


print usdPerDay

print averageHashrate 
print btcPerDay

g = graphitesend.init(graphite_server='localhost',system_name='f2pool',group='mining')
print g.send('averageHashrate', averageHashrate)
print g.send('btcPerDay', btcPerDay)
print g.send('usdPerDay', usdPerDay)
print g.send('USDBTC', USDBTC)
print g.send('elecperDay', elecperDay)
print g.send('profitperDay', profitperDay)
Exemplo n.º 36
0
 def test_prefix_double_dot(self):
     g = graphitesend.init(prefix='custom_prefix.')
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'custom_prefix.%s.' % self.hostname)
Exemplo n.º 37
0
btcPerDay = totalProf

elecperDay = 0
# rough approximation of robbie elec costs / month
pricesite = "https://api.coindesk.com/v1/bpi/currentprice.json"
req2 = urllib2.Request(pricesite, headers=hdr)
try:
    prices = urllib2.urlopen(req2)
    currprice = prices.read()
    pricedata = simplejson.loads(currprice)
except urllib2.HTTPError, e:
    e.fp.read()

USDBTC = pricedata["bpi"]["USD"]["rate"]
USDBTC = float(USDBTC.replace(',', ''))
print "BTC price:" + str(USDBTC)

usdPerDay = USDBTC * btcPerDay
print "USD per day:" + str(usdPerDay)
profitperDay = usdPerDay - elecperDay

print usdPerDay
print btcPerDay

g = graphitesend.init(graphite_server='localhost', system_name='joe')
print g.send('btcPerDay', btcPerDay)
print g.send('usdPerDay', usdPerDay)
print g.send('USDBTC', USDBTC)
print g.send('elecperDay', elecperDay)
print g.send('profitperDay', profitperDay)
Exemplo n.º 38
0
 def test_prefix_remove_spaces(self):
     g = graphitesend.init(prefix='custom prefix')
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'custom_prefix.%s.' % self.hostname)
Exemplo n.º 39
0
 def test_set_prefix_group(self):
     g = graphitesend.init(prefix='prefix', group='group')
     custom_prefix = g.prefix
     expected_prefix='prefix.%s.group.' % self.hostname
     self.assertEqual(custom_prefix, expected_prefix)
Exemplo n.º 40
0
            peers_total += mc_result[i]

    peers_accounted = 0
    for i in range(torrents_total * 5, torrents_total * 6):
        if mc_result[i]:
            peers_accounted += mc_result[i]

    d["peers.seeds_connected"] = seeds
    d["peers.total_connected"] = peers_total
    d["peers.accounted"] = peers_accounted

    # Print result dict in alphabetical order.
    # for key in sorted(d.iterkeys()):
    #     print "%s: %s" % (key, d[key])

    return d


g = graphitesend.init(prefix=graphite_prefix,
                      dryrun=graphite_dryrun,
                      graphite_server=graphite_server,
                      graphite_port=graphite_port,
                      group="rtorrent")

if interval is False:
    print g.send_dict(get_rtorrent_data(xmlrpc_uri))
else:
    while True:
        print g.send_dict(get_rtorrent_data(xmlrpc_uri))
        time.sleep(interval)
Exemplo n.º 41
0
 def testCreateGraphiteClient(self):
     g = graphitesend.init(prefix='', dryrun=True)
     self.assertEqual(type(g).__name__, 'GraphiteClient')
     dryrun_message = g.send('metric', 1, 1)
     self.assertEqual(dryrun_message,
                      "%s.metric 1.000000 1\n" % self.hostname)
Exemplo n.º 42
0
#!/usr/bin/env python

import graphitesend

lines = open('/proc/net/netstat').readlines()

tcp_metrics = lines[0].split()[1:]
tcp_values = lines[1].split()[1:]
ip_metrics = lines[2].split()[1:]
ip_values = lines[3].split()[1:]

data_list = zip(tcp_metrics + ip_metrics, tcp_values + ip_values)

g = graphitesend.init(group='netstat.', lowercase_metric_names=True)
print g.send_list(data_list)
Exemplo n.º 43
0
 def test_fqdn_squash(self):
     g = graphitesend.init(fqdn_squash=True)
     custom_prefix = g.prefix
     expected_results='systems.%s.' % self.hostname.replace('.','_')
     self.assertEqual(custom_prefix, expected_results)
Exemplo n.º 44
0
 def test_lowercase_metric_names(self):
     g = graphitesend.init(lowercase_metric_names=True)
     send_data = g.send('METRIC', 1)
     self.assertEqual('metric' in send_data, True)
     self.assertEqual('METRIC' in send_data, False)
Exemplo n.º 45
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import serial
import graphitesend, time

g = graphitesend.init(graphite_server='127.0.0.1', group='mppt', prefix='')


class vedirect:
    def __init__(self, serialport):
        self.serialport = serialport
        self.ser = serial.Serial(serialport, 19200, timeout=10)
        self.header1 = '\r'
        self.header2 = '\n'
        self.delimiter = '\t'
        self.key = ''
        self.value = ''
        self.bytes_sum = 0
        self.state = self.WAIT_HEADER
        self.dict = {}

    (WAIT_HEADER, IN_KEY, IN_VALUE, IN_CHECKSUM) = range(4)

    def input(self, byte):
        if self.state == self.WAIT_HEADER:
            self.bytes_sum += ord(byte)
            if byte == self.header1:
                self.state = self.WAIT_HEADER
            elif byte == self.header2:
                self.state = self.IN_KEY
Exemplo n.º 46
0
 def test_noprefix(self):
     g = graphitesend.init()
     custom_prefix = g.prefix
     self.assertEqual(custom_prefix, 'systems.%s.' % self.hostname)