Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support long int for metrics value #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
113 changes: 102 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,104 @@
build
*.pyc
dist
*.tar.gz
*.o
a.out
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so
*.egg-info
.env
__pycache__

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
*.sublime-workspace
.envrc-extra

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
18 changes: 9 additions & 9 deletions cystatsd/collector/collector.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,40 @@ cdef class MetricCollector:
def __init__(self, int mtu=512):
self.collector = CPPMetricCollector(mtu)

cpdef _push_timer(self, bytes name, int value, float rate):
cpdef _push_timer(self, bytes name, long long int value, float rate):
self.collector.pushTimer(name, value, rate)

def push_timer(self, name, int value, float rate=1.0):
def push_timer(self, name, long long int value, float rate=1.0):
if isinstance(name, UNICODE_TYPE):
name = name.encode('utf-8')
self._push_timer(name, value, rate)

cpdef _push_counter(self, bytes name, int value, float rate=1.0):
cpdef _push_counter(self, bytes name, long long int value, float rate=1.0):
self.collector.pushCounter(name, value, rate)

def push_counter(self, name, int value, float rate=1.0):
def push_counter(self, name, long long int value, float rate=1.0):
if isinstance(name, UNICODE_TYPE):
name = name.encode('utf-8')
self._push_counter(name, value, rate)

cpdef _push_gauge(self, bytes name, int value, float rate=1.0):
cpdef _push_gauge(self, bytes name, long long int value, float rate=1.0):
self.collector.pushGauge(name, value, rate)

cpdef _push_gauge_delta(self, bytes name, int value, float rate=1.0):
cpdef _push_gauge_delta(self, bytes name, long long int value, float rate=1.0):
self.collector.pushGaugeDelta(name, value, rate)

def push_gauge(self, name, int value, float rate=1.0, delta = False):
def push_gauge(self, name, long long int value, float rate=1.0, delta = False):
if isinstance(name, UNICODE_TYPE):
name = name.encode('utf-8')
if delta:
self._push_gauge_delta(name, value, rate)
else:
self._push_gauge(name, value, rate)

cpdef _push_set(self, bytes name, int value, float rate=1.0):
cpdef _push_set(self, bytes name, long long int value, float rate=1.0):
self.collector.pushSet(name, value, rate)

def push_set(self, name, int value, float rate=1.0):
def push_set(self, name, long long int value, float rate=1.0):
if isinstance(name, UNICODE_TYPE):
name = name.encode('utf-8')
self._push_set(name, value, rate)
Expand Down
20 changes: 10 additions & 10 deletions cystatsd/collector/cstatsd_proto.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ cdef extern from "./statsd_proto.hpp" namespace "statsd_proto":
cdef cppclass MetricCollector:
MetricCollector()
MetricCollector(size_t)
void pushGauge(const string &name, int value)
void pushGaugeDelta(const string &name, int value)
void pushTimer(const string &name, int value)
void pushCounter(const string &name, int value)
void pushSet(const string &name, int value)
void pushGauge(const string &name, int value, float rate)
void pushGaugeDelta(const string &name, int value, float rate)
void pushTimer(const string &name, int value, float rate)
void pushCounter(const string &name, int value, float rate)
void pushSet(const string &name, int value, float rate)
void pushGauge(const string &name, long long int value)
void pushGaugeDelta(const string &name, long long int value)
void pushTimer(const string &name, long long int value)
void pushCounter(const string &name, long long int value)
void pushSet(const string &name, long long int value)
void pushGauge(const string &name, long long int value, float rate)
void pushGaugeDelta(const string &name, long long int value, float rate)
void pushTimer(const string &name, long long int value, float rate)
void pushCounter(const string &name, long long int value, float rate)
void pushSet(const string &name, long long int value, float rate)
vector[string] flush()

14 changes: 7 additions & 7 deletions cystatsd/collector/statsd_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const char* BufferHandle::data() const {


Metric::Metric(){}
Metric::Metric(MetricType mtype, std::string name, int64_t val)
Metric::Metric(MetricType mtype, std::string name, long long int val)
: metricType_(mtype), name_(name), value_(val) {}

void Metric::encodeTo(BufferHandle *buff) {
Expand Down Expand Up @@ -85,7 +85,7 @@ SampledMetric::SampledMetric(Metric met, float rate)
: metric_(met), rate_(rate) {}

SampledMetric::SampledMetric(MetricType mtype,
const string& name, int64_t value, float rate)
const string& name, long long int value, float rate)
: metric_(mtype, name, value), rate_(rate) {}

SampledMetric::SampledMetric() {}
Expand Down Expand Up @@ -166,23 +166,23 @@ std::vector<std::string> MetricCollector::flush() {
return result;
}

void MetricCollector::pushTimer(const string& name, int64_t val, float rate) {
void MetricCollector::pushTimer(const string& name, long long int val, float rate) {
metrics_.emplace_back(MetricType::TIMER, name, val, rate);
}

void MetricCollector::pushCounter(const string& name, int64_t val, float rate) {
void MetricCollector::pushCounter(const string& name, long long int val, float rate) {
metrics_.emplace_back(MetricType::COUNTER, name, val, rate);
}

void MetricCollector::pushGauge(const string& name, int64_t val, float rate) {
void MetricCollector::pushGauge(const string& name, long long int val, float rate) {
metrics_.emplace_back(MetricType::GAUGE, name, val, rate);
}

void MetricCollector::pushGaugeDelta(const string& name, int64_t val, float rate) {
void MetricCollector::pushGaugeDelta(const string& name, long long int val, float rate) {
metrics_.emplace_back(MetricType::GAUGE_DELTA, name, val, rate);
}

void MetricCollector::pushSet(const string& name, int64_t val, float rate) {
void MetricCollector::pushSet(const string& name, long long int val, float rate) {
metrics_.emplace_back(MetricType::SET, name, val, rate);
}

Expand Down
16 changes: 8 additions & 8 deletions cystatsd/collector/statsd_proto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ class Metric {
protected:
MetricType metricType_ {MetricType::NONE};
std::string name_ {""};
int64_t value_ {0};
long long int value_ {0};
public:
Metric();
Metric(MetricType mtype, std::string name, int64_t val);
Metric(MetricType mtype, std::string name, long long int val);
void encodeTo(BufferHandle*);
};

Expand All @@ -55,7 +55,7 @@ class SampledMetric {
SampledMetric();
bool isSampled() const;
SampledMetric(Metric met, float rate);
SampledMetric(MetricType met, const std::string &name, int64_t val, float rate);
SampledMetric(MetricType met, const std::string &name, long long int val, float rate);
SampledMetric(Metric met);
void encodeTo(BufferHandle*);
};
Expand All @@ -70,11 +70,11 @@ class MetricCollector {
size_t count() const;
bool empty() const;
std::vector<std::string> flush();
void pushTimer(const std::string& name, int64_t value, float rate = 1.0);
void pushCounter(const std::string& name, int64_t value, float rate = 1.0);
void pushGauge(const std::string& name, int64_t value, float rate = 1.0);
void pushGaugeDelta(const std::string& name, int64_t value, float rate = 1.0);
void pushSet(const std::string& name, int64_t value, float rate = 1.0);
void pushTimer(const std::string& name, long long int value, float rate = 1.0);
void pushCounter(const std::string& name, long long int value, float rate = 1.0);
void pushGauge(const std::string& name, long long int value, float rate = 1.0);
void pushGaugeDelta(const std::string& name, long long int value, float rate = 1.0);
void pushSet(const std::string& name, long long int value, float rate = 1.0);
};


Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cython==0.27.3
nose==1.3.7