def send_to_statsd(key, value, domain=None): message = "%s %s %s\n" % (key, value, time.time()) message = remove_domain(message, domain) logger.debug("Sending message to Statsd: %s" % message) statsd.init_statsd({ "STATSD_HOST": CONF.graphite.carbon_server, "STATSD_BUCKET_PREFIX": CONF.graphite.prefix or ''}) statsd.gauge(key, value)
def init_statsd(): """ Initialize the statsd client. """ statsd.init_statsd({ 'STATSD_HOST': config.secrets.server('statsd.host'), 'STATSD_PORT': config.secrets.server('statsd.port'), 'STATSD_BUCKET_PREFIX': 'linkr', })
def send_to_statsd(key, value, domain=None): message = "%s %s %s\n" % (key, value, time.time()) message = remove_domain(message, domain) logger.debug("Sending message to Statsd: %s" % message) statsd.init_statsd({ "STATSD_HOST": CONF.graphite.carbon_server, "STATSD_BUCKET_PREFIX": CONF.graphite.prefix or '' }) statsd.gauge(key, value)
def test_init_statsd(self): settings = {'STATSD_HOST': '127.0.0.1', 'STATSD_PORT': 9999, 'STATSD_SAMPLE_RATE': 0.99, 'STATSD_BUCKET_PREFIX': 'testing'} statsd.init_statsd(settings) self.assertEqual(statsd.STATSD_HOST, '127.0.0.1') self.assertEqual(statsd.STATSD_PORT, 9999) self.assertEqual(statsd.STATSD_SAMPLE_RATE, 0.99) self.assertEqual(statsd.STATSD_BUCKET_PREFIX, 'testing')
def __init__(self, endpoint, pubsub_endpoint, check_delay, ssh_server, **config): super(StatsdEmitter, self).__init__(endpoint, pubsub_endpoint, check_delay, ssh_server=ssh_server) self.app = config.get('application_name', 'app') self.prefix = 'circus.%s.watcher' % self.app # initialize statsd statsd.init_statsd({'STATSD_HOST': config.get('host', 'localhost'), 'STATSD_PORT': int(config.get('port', '8125')), 'STATSD_SAMPLE_RATE': float(config.get('sample_rate', '1.0')), 'STATSD_BUCKET_PREFIX': self.prefix})
import requests import logging import couchdbkit import traceback import threading import Queue import copy import json import time import statsd from couch_named_python import version from habitat.utils import rfc3339, immortal_changes __all__ = ["SpaceNearUs"] logger = logging.getLogger("habitat_transition.spacenearus") statsd.init_statsd({"STATSD_BUCKET_PREFIX": "habitat.spacenearus"}) @version(1) def spacenear_filter(doc, req): """Select parsed payload_telemetry and all listener_telemetry documents.""" if "type" not in doc: return False if doc["type"] == "listener_telemetry": return True if doc["type"] == "payload_telemetry": if "data" in doc and "_parsed" in doc["data"]: return True return False
# Modules from the Python standard library. import datetime import time as timelib import sys import os import os.path import logging import traceback import calendar import optparse import subprocess import statsd import json statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habhub.predictor'}) # Output logger format log = logging.getLogger('main') log_formatter = logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s') console = logging.StreamHandler() console.setFormatter(log_formatter) log.addHandler(console) progress_f = '' progress = { 'run_time': '', 'dataset': '', 'pred_running': False, 'pred_complete': False, 'warnings': False,
def setUp(self): # Moneky patch statsd socket for testing statsd.socket = mock_udp_socket statsd.init_statsd()
# along with habitat. If not, see <http://www.gnu.org/licenses/>. """ Run the Parser as a daemon connected to CouchDB's _changes feed. """ import logging import couchdbkit import restkit import copy import statsd from . import parser from .utils import immortal_changes logger = logging.getLogger("habitat.parser_daemon") statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habitat'}) __all__ = ['ParserDaemon'] class ParserDaemon(object): """ :class:`ParserDaemon` runs persistently, watching CouchDB's _changes feed for new unparsed telemetry, parsing it with :class:`Parser` and storing the result back in the database. """ def __init__(self, config, daemon_name="parserdaemon"): """ On construction, it will: * Connect to CouchDB using ``self.config["couch_uri"]`` and
'NO->SE': ENTSOE.fetch_exchange, # PL 'PL->SE': ENTSOE.fetch_exchange, 'PL->SK': ENTSOE.fetch_exchange, # RO 'RO->RS': RO.fetch_exchange, 'RO->UA': RO.fetch_exchange, # SK # 'SK->UA': ENTSOE.fetch_exchange, } # Set up stats import statsd statsd.init_statsd({ 'STATSD_HOST': os.environ.get('STATSD_HOST', 'localhost'), 'STATSD_BUCKET_PREFIX': 'electricymap_feeder' }) # Set up database client = pymongo.MongoClient( os.environ.get('MONGO_URL', 'mongodb://localhost:27017')) db = client['electricity'] col_production = db['production'] col_exchange = db['exchange'] # Set up indices col_production.create_index([('datetime', -1), ('countryCode', 1)], unique=True) col_exchange.create_index([('datetime', -1), ('sortedCountryCodes', 1)], unique=True) # Set up memcached
""" Run the Parser as a daemon connected to CouchDB's _changes feed. """ import logging import couchdbkit import restkit import copy import statsd from . import parser from .utils import immortal_changes logger = logging.getLogger("habitat.parser_daemon") statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habitat'}) __all__ = ['ParserDaemon'] class ParserDaemon(object): """ :class:`ParserDaemon` runs persistently, watching CouchDB's _changes feed for new unparsed telemetry, parsing it with :class:`Parser` and storing the result back in the database. """ def __init__(self, config, daemon_name="parserdaemon"): """ On construction, it will:
import math import sys import os import socket import logging import traceback import calendar import optparse import subprocess import statsd import tempfile import shutil import bisect import simplejson as json statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habhub.predictor'}) # We use Pydap from http://pydap.org/. import pydap.exceptions, pydap.client, pydap.lib pydap.lib.CACHE = "/tmp/pydap-cache/" # horrid, horrid monkey patching to force # otherwise broken caching from dods server # this is really, really hacky import pydap.util.http def fresh(response_headers, request_headers): cc = pydap.util.http.httplib2._parse_cache_control(response_headers) if cc.has_key('no-cache'): return 'STALE' return 'FRESH' pydap.util.http.httplib2._entry_disposition = fresh
import requests import logging import couchdbkit import traceback import threading import Queue import copy import json import time import statsd from couch_named_python import version from habitat.utils import rfc3339, immortal_changes __all__ = ["SpaceNearUs"] logger = logging.getLogger("habitat_transition.spacenearus") statsd.init_statsd({'STATSD_BUCKET_PREFIX': 'habitat.spacenearus'}) @version(1) def spacenear_filter(doc, req): """Select parsed payload_telemetry and all listener_telemetry documents.""" if 'type' not in doc: return False if doc['type'] == "listener_telemetry": return True if doc['type'] == "payload_telemetry": if 'data' in doc and '_parsed' in doc['data']: return True return False
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ engine = engine_from_config(settings, 'sqlalchemy.') initialize_sql(engine) config = Configurator( settings=settings, # Custom access control policy root_factory=RootFactory, # Authentication authentication_policy=UrlPrefixAuthTktAuthenticationPolicy( secret='8c9b6d3ad7d20c43a6a9b173a3515ad0d3677825247083df7d5f5211e33b1138', secure=settings.get('session.secure', 'false').strip() == 'true', include_ip=True, timeout=1200, # 20 minutes session timeout reissue_time=120, # reissue the session cookie every 2 minutes http_only=True), authorization_policy=ACLAuthorizationPolicy(), # Beaker sessioning session_factory=session_factory_from_settings(settings)) # Configure StatsD integration if asbool(settings.get('nuvavaalit.statsd_enabled', 'false')): try: sample_rate = float(settings.get('nuvavaalit.statsd_sample_rate', None)) except (TypeError, ValueError): sample_rate = None statsd.init_statsd({ 'STATSD_HOST': settings.get('nuvavaalit.statsd_host', 'localhost'), 'STATSD_PORT': int(settings.get('nuvavaalit.statsd_port', 8125)), 'STATSD_SAMPLE_RATE': sample_rate, 'STATSD_BUCKET_PREFIX': settings.get('nuvavaalit.statsd_bucket_prefix', '').strip() or None, }) config.add_translation_dirs('nuvavaalit:locale') config.add_static_view('static', 'nuvavaalit:views/templates/static', cache_max_age=604800) # Basic routes config.add_route('home', '/') config.add_route('login', '/tunnistaudu') config.add_route('custom_js', '/script.js') # Pre-election candidate listing config.add_route('browse_candidates', '/ehdokkaat') # Voting process config.add_route('select', '/valitse') config.add_route('vote', '/aanesta/{id}') config.add_route('thanks', '/kiitos') config.add_route('results', '/tulokset') # HAProxy health check config.add_route('ping', '/ping') # InternetVista monitoring config.add_route('system_check', '/13fb4ad31bbd8c0a7dbcfc283ff449452cfbdf4b') # Language selection config.add_route('set_language', '/locale/{lang}') config.scan('nuvavaalit') return config.make_wsgi_app()
#!/usr/bin/env python import statsd statsd.init_statsd() counter = statsd.StatsdCounter('divisible by 3') x = 0 while True: x += 1 if not x % 3: counter += 1
def initialize_metrics(settings): statsd_settings = settings.get('statsd_configuration') statsd.init_statsd(statsd_settings)