Skip to content

Commit 780e80d

Browse files
committed
Merge branch 'release/0.0.5'
2 parents bf2a9f2 + c8af3ac commit 780e80d

File tree

7 files changed

+283
-178
lines changed

7 files changed

+283
-178
lines changed

.clang-format

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
AccessModifierOffset: -4
2+
AllowAllParametersOfDeclarationOnNextLine: false
3+
AllowShortFunctionsOnASingleLine: Empty
4+
BinPackArguments: false
5+
BinPackParameters: false
6+
ColumnLimit: 120
7+
IndentCaseLabels: false
8+
IndentWidth: 4
9+
10+
---
11+
Language: Cpp
12+
# BasedOnStyle: Google
13+
#AccessModifierOffset: -1
14+
AlignAfterOpenBracket: Align
15+
AlignConsecutiveAssignments: false
16+
AlignConsecutiveDeclarations: false
17+
AlignEscapedNewlinesLeft: true
18+
AlignOperands: true
19+
AlignTrailingComments: true
20+
#AllowAllParametersOfDeclarationOnNextLine: true
21+
AllowShortBlocksOnASingleLine: false
22+
AllowShortCaseLabelsOnASingleLine: false
23+
#AllowShortFunctionsOnASingleLine: All
24+
AllowShortIfStatementsOnASingleLine: true
25+
AllowShortLoopsOnASingleLine: true
26+
AlwaysBreakAfterDefinitionReturnType: None
27+
AlwaysBreakAfterReturnType: None
28+
AlwaysBreakBeforeMultilineStrings: true
29+
AlwaysBreakTemplateDeclarations: true
30+
#BinPackArguments: true
31+
#BinPackParameters: true
32+
BraceWrapping:
33+
AfterClass: false
34+
AfterControlStatement: false
35+
AfterEnum: false
36+
AfterFunction: false
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
BeforeCatch: false
42+
BeforeElse: false
43+
IndentBraces: false
44+
BreakBeforeBinaryOperators: None
45+
BreakBeforeBraces: Attach
46+
BreakBeforeTernaryOperators: true
47+
BreakConstructorInitializersBeforeComma: false
48+
BreakAfterJavaFieldAnnotations: false
49+
BreakStringLiterals: true
50+
#ColumnLimit: 80
51+
CommentPragmas: '^ IWYU pragma:'
52+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
53+
ConstructorInitializerIndentWidth: 4
54+
ContinuationIndentWidth: 4
55+
Cpp11BracedListStyle: true
56+
DerivePointerAlignment: true
57+
DisableFormat: false
58+
ExperimentalAutoDetectBinPacking: false
59+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
60+
IncludeCategories:
61+
- Regex: '^<.*\.h>'
62+
Priority: 1
63+
- Regex: '^<.*'
64+
Priority: 2
65+
- Regex: '.*'
66+
Priority: 3
67+
IncludeIsMainRegex: '([-_](test|unittest))?$'
68+
#IndentCaseLabels: true
69+
#IndentWidth: 2
70+
IndentWrappedFunctionNames: false
71+
JavaScriptQuotes: Leave
72+
JavaScriptWrapImports: true
73+
KeepEmptyLinesAtTheStartOfBlocks: false
74+
MacroBlockBegin: ''
75+
MacroBlockEnd: ''
76+
MaxEmptyLinesToKeep: 1
77+
NamespaceIndentation: None
78+
ObjCBlockIndentWidth: 2
79+
ObjCSpaceAfterProperty: false
80+
ObjCSpaceBeforeProtocolList: false
81+
PenaltyBreakBeforeFirstCallParameter: 1
82+
PenaltyBreakComment: 300
83+
PenaltyBreakFirstLessLess: 120
84+
PenaltyBreakString: 1000
85+
PenaltyExcessCharacter: 1000000
86+
PenaltyReturnTypeOnItsOwnLine: 200
87+
PointerAlignment: Left
88+
ReflowComments: true
89+
SortIncludes: true
90+
SpaceAfterCStyleCast: false
91+
SpaceAfterTemplateKeyword: true
92+
SpaceBeforeAssignmentOperators: true
93+
SpaceBeforeParens: ControlStatements
94+
SpaceInEmptyParentheses: false
95+
SpacesBeforeTrailingComments: 2
96+
SpacesInAngles: false
97+
SpacesInContainerLiterals: true
98+
SpacesInCStyleCastParentheses: false
99+
SpacesInParentheses: false
100+
SpacesInSquareBrackets: false
101+
Standard: Auto
102+
TabWidth: 8
103+
UseTab: Never
104+
...
105+

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.2)
22

33
project(StatsdClient)
44

5-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
5+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/cpp-statsd-client)
66

7-
install(FILES src/* DESTINATION include)
7+
install(FILES UDPSender.hpp StatsdClient.hpp DESTINATION include)
88

99
find_package(Threads)
1010
add_executable(testStatsdClient ${CMAKE_CURRENT_SOURCE_DIR}/tests/testStatsdClient.cpp)

README.md

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# C++ StatsD Client
22

3+
![logo](https://raw.githubusercontent.com/vthiery/cpp-statsd-client/develop/images/logo.svg?sanitize=true)
4+
35
[ ![Download](https://api.bintray.com/packages/vthiery/conan-packages/statsdclient%3Avthiery/images/download.svg) ](https://bintray.com/vthiery/conan-packages/statsdclient%3Avthiery/_latestVersion)
46
[![Build Status](https://travis-ci.org/vthiery/cpp-statsd-client.svg?branch=develop)](https://travis-ci.org/vthiery/cpp-statsd-client)
57
[![Github Issues](https://img.shields.io/github/issues/vthiery/cpp-statsd-client.svg)](https://github.com/vthiery/cpp-statsd-client/issues)
@@ -9,9 +11,30 @@ A header-only StatsD client implemented in C++.
911
The client allows:
1012
- batching,
1113
- change of configuration at runtime,
12-
- user-define frequency rate.
14+
- user-defined frequency rate.
15+
16+
## Install and Test
17+
18+
### Makefile
19+
20+
In order to install the header files and/or run the tests, simply use the Makefile and execute
21+
22+
```
23+
make install
24+
```
25+
26+
and
27+
28+
```
29+
make test
30+
```
31+
32+
### Conan
33+
34+
If you are using [Conan](https://www.conan.io/) to manage your dependencies, merely add statsdclient/x.y.z@vthiery/stable to your conanfile.py's requires, where x.y.z is the release version you want to use. Please file issues here if you experience problems with the packages. You can also directly download the latest version [here](https://bintray.com/vthiery/conan-packages/statsdclient%3Avthiery/_latestVersion).
1335

1436
## Usage
37+
### Example
1538
A simple example of how to use the client:
1639

1740
```cpp
@@ -20,13 +43,13 @@ using namespace Statsd;
2043

2144
int main()
2245
{
23-
// Define the client
24-
StatsdClient client{ "127.0.0.1", 5005, "myPrefix.", 3 };
46+
// Define the client on localhost, with port 8080, using a prefix and a batching size of 20 bytes
47+
StatsdClient client{ "127.0.0.1", 8080, "myPrefix.", 20 };
2548

26-
// Increment "coco"
49+
// Increment the metric "coco"
2750
client.increment("coco");
2851

29-
// Decrement "kiki"
52+
// Decrement the metric "kiki"
3053
client.decrement("kiki");
3154

3255
// Adjusts "toto" by +3
@@ -43,5 +66,46 @@ int main()
4366
}
4467
```
4568

69+
### Configuration
70+
71+
The configuration of the client must be input when one instantiates it. Nevertheless, the API allows the configuration ot change afterwards. For example, one can do the following:
72+
73+
```cpp
74+
#include "StatsdClient.hpp"
75+
using namespace Statsd;
76+
77+
int main()
78+
{
79+
// Define the client on localhost, with port 8080, using a prefix and a batching size of 20 bytes
80+
StatsdClient client{ "127.0.0.1", 8080, "myPrefix.", 20 };
81+
82+
client.increment("coco");
83+
84+
// Set a new configuration, using a different port and a different prefix
85+
client.setConfig("127.0.0.1", 8000, "anotherPrefix.");
86+
87+
client.decrement("kiki");
88+
}
89+
```
90+
91+
The batchsize is the only parameter that cannot be changed for the time being.
92+
93+
### Batching
94+
95+
The client supports batching of the metrics:
96+
* the unit of the batching parameter is bytes,
97+
* it is optional and not setting it will result in an immediate send of any metrics,
98+
99+
If set, the UDP sender will spawn a thread sending the metrics to the server every 1 second by aggregates. The aggregation logic is as follows:
100+
* if the last message has already reached the batching limit, add a new element in a message queue;
101+
* otherwise, append the message to the last one, separated by a `\n`.
102+
103+
### Frequency rate
104+
105+
When sending a metric, a frequency rate can be set in order to limit the metrics' sampling. By default, the frequency rate is set to one and won't affect the sampling. If set to a value `epsilon` (0.0001 for the time being) close to one, the sampling is not affected either.
106+
107+
If the frequency rate is set and `epsilon` different from one, the sending will be rejected randomly (the higher the frequency rate, the lower the probability of rejection).
108+
109+
46110
## License
47111
This library is under MIT license.

images/logo.svg

Lines changed: 16 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)