コード例 #1
0
ファイル: __init__.py プロジェクト: jaylett/tp_to_statsd
def update_statsd_gauge(tp_process, tp_type, state_name, count):
    statsd_key = key_pattern % {
        'process': slugify(tp_process),
        'state': slugify(state_name),
        'type': slugify(tp_type),
    }
    print('Calculated %s as %d.' % (statsd_key, count))
    statsd.gauge(
        statsd_key,
        count,
    )
コード例 #2
0
def spanner_read_data(query, table):
    (instance_id, database_id) = from_env()
    instance = client.instance(instance_id)
    database = instance.database(database_id)

    logging.info("For {}:{}".format(instance_id, database_id))

    # Count bsos expired rows
    with statsd.timer(f"syncstorage.count_expired_{table}_rows.duration"):
        with database.snapshot() as snapshot:
            result = snapshot.execute_sql(query)
            row_count = result.one()[0]
            statsd.gauge(f"syncstorage.expired_{table}_rows", row_count)
            logging.info(f"Found {row_count} expired rows in {table}")
コード例 #3
0
ファイル: count_users.py プロジェクト: zaurask/syncstorage-rs
def spanner_read_data(request=None):
    (instance_id, database_id) = from_env()
    instance = client.instance(instance_id)
    database = instance.database(database_id)

    logging.info("For {}:{}".format(instance_id, database_id))

    # Count users
    with statsd.timer("syncstorage.count_users.duration"):
        with database.snapshot() as snapshot:
            query = 'SELECT COUNT (DISTINCT fxa_uid) FROM user_collections'
            result = snapshot.execute_sql(query)
            user_count = result.one()[0]
            statsd.gauge("syncstorage.distinct_fxa_uid", user_count)
            logging.info("Count found {} distinct users".format(user_count))
コード例 #4
0
 def reportStats(self, stats):
     for row in stats:
         base = 'haproxy.%s.%s.' % (row['pxname'], row['svname'])
         for key in GAUGES:
             value = row[key]
             if value != '':
                 statsd.gauge(base + key, int(value))
         for key in COUNTERS:
             metric = base + key
             newvalue = row[key]
             if newvalue == '':
                 continue
             newvalue = int(newvalue)
             oldvalue = self.prevdata.get(metric)
             if oldvalue is not None:
                 value = newvalue - oldvalue
                 statsd.incr(metric, value)
             self.prevdata[metric] = newvalue
コード例 #5
0
    def collect(self):
        if os.getenv('DUMMY_INPUT', 'FALSE') == 'TRUE':
            # Get dummy json data
            self._collect(DUMMY_INPUT_FILE)
        else:
            logging.info('Start fetching metrics')
            self._collect()
            logging.info('Finish fetching metrics')

        # for m in list(self.prom_metrics.values()):
        #     yield m

        if os.getenv('STD_OUTPUT', 'FALSE') == 'TRUE':
            for k, v in self.statsd_metrics.items():
                print k, '=>', v
        else:
            logging.info('Send metrics to STATSD')
            for k, v in self.statsd_metrics.items():
                try:
                    statsd.gauge(k, v)
                except Exception as e:
                    logging.error(
                        'Send metrics to STATSD error.\n {}'.format(e))