# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from collections import OrderedDict import functools import hashlib import re import time from librato_python_web.instrumentor.custom_logging import getCustomLogger logger = getCustomLogger(__name__) RE_CLEANSE = re.compile('[^A-Za-z0-9.:\\-_]') MAX_NAME_LEN = 48 ALIAS_CACHE_LEN = 48 class Timing(object): context = None NET_KEY = '_net' @staticmethod def _get_dict(): if not Timing.context: import threading Timing.context = threading.local()
from contextlib import contextmanager from collections import OrderedDict, defaultdict from librato_python_web.instrumentor import context from librato_python_web.statsd.client import statsd_client from librato_python_web.instrumentor.util import AliasGenerator, Timing from librato_python_web.instrumentor.custom_logging import getCustomLogger logger = getCustomLogger(__name__) # noinspection PyClassHasNoInit class _global: reporters = {} def set_reporter(reporter, name='web'): """ Sets the reporter for configuration information. Defaults to StdoutConfigReporter. :param reporter: the reporter instance :type reporter: TelemetryReporter """ _global.reporters[name] = reporter def count(metric, incr=1, reporter='web'): """ Increment the count for the given metric by the given increment.