Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.6
current_version = 0.2.0
commit = False
tag = False
files = setup.py netuitive/__init__.py
Expand Down
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
-------

0.2.0 (2016-07-22)
---------------------

* sanitize metric names

0.1.6 (2016-05-20)
---------------------

Expand Down
2 changes: 1 addition & 1 deletion netuitive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

__author__ = 'Netuitive, Inc'
__version__ = '0.1.6'
__version__ = '0.2.0'

from .client import Client # nopep8
from .element import Element # nopep8
Expand Down
20 changes: 16 additions & 4 deletions netuitive/element.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from .attribute import Attribute
from .metric import Metric
from .sample import Sample
Expand Down Expand Up @@ -28,6 +30,14 @@ def __init__(self, ElementType='SERVER', location=None):
if location is not None:
self.location = location

def _sanitize(self, s):
"""
Sanitize the name of a metric to remove unwanted chars

"""

return re.sub('[^a-zA-Z0-9\\._-]', '_', s)

def add_attribute(self, name, value):
"""
:param name: Name of the attribute
Expand Down Expand Up @@ -117,25 +127,27 @@ def add_sample(self,
else:
Tags = None

metricIdSan = self._sanitize(metricId)

if len(self.metrics) > 0:
t = list(self.metrics)

if metricId not in t:
if metricIdSan not in t:
self.metrics.append(
Metric(metricId,
Metric(metricIdSan,
metricType,
sparseDataStrategy,
unit,
Tags))
else:
self.metrics.append(
Metric(metricId,
Metric(metricIdSan,
metricType,
sparseDataStrategy,
unit,
Tags))

self.samples.append(Sample(metricId,
self.samples.append(Sample(metricIdSan,
timestamp *
1000,
value,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name='netuitive',
version='0.1.6',
version='0.2.0',
description="Python Client for Netuitive Cloud",
long_description=readme + '\n\n' + history,
author="Netuitive",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_netuitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ def test_with_cnt(self):
self.assertEqual(
a.samples[0].cnt, 3)

def test_add_sanitize(self):
a = netuitive.Element()
a.add_sample(
'mongo.wiredTiger.cache.eviction$server populating queue,:but not evicting pages', 1434110794, 1, 'COUNTER', host='hostname')

self.assertEqual(a.metrics[
0].id, 'mongo.wiredTiger.cache.eviction_server_populating_queue__but_not_evicting_pages')

def test_post_format(self):
a = netuitive.Element()

Expand Down