├── .gitattributes
├── .gitignore
├── .nuget
├── nuget.config
└── packages.config
├── CHANGELOG.md
├── LICENSE
├── Metrics.InfluxDB.sln
├── Publishing
├── Metrics.NET.InfluxDB.nuspec
└── push-nuget.bat
├── README.md
├── SharedAssemblyInfo.cs
├── Src
├── Metrics.InfluxDB.SamplesConsole
│ ├── App.config
│ ├── Metrics.InfluxDB.SamplesConsole.csproj
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
├── Metrics.InfluxDB.Tests
│ ├── InfluxdbTestUtils.cs
│ ├── InfluxdbTests.cs
│ ├── Metrics.InfluxDB.Tests.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── packages.config
└── Metrics.InfluxDB
│ ├── Adapters
│ ├── InfluxdbConverter.cs
│ ├── InfluxdbFormatter.cs
│ ├── InfluxdbHttpWriter.cs
│ ├── InfluxdbJsonWriter.cs
│ ├── InfluxdbUdpWriter.cs
│ └── InfluxdbWriter.cs
│ ├── InfluxdbBaseReport.cs
│ ├── InfluxdbConfigExtensions.cs
│ ├── InfluxdbHttpReport.cs
│ ├── InfluxdbJsonReport.cs
│ ├── InfluxdbReport.cs
│ ├── InfluxdbUdpReport.cs
│ ├── Metrics.InfluxDB.csproj
│ ├── Model
│ ├── InfluxBatch.cs
│ ├── InfluxConfig.cs
│ ├── InfluxField.cs
│ ├── InfluxLineProtocol.cs
│ ├── InfluxPrecision.cs
│ ├── InfluxRecord.cs
│ ├── InfluxTag.cs
│ └── InfluxUtils.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── packages.config
├── build.bat
├── build.sh
└── create-nuget.bat
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.cs diff=csharp
3 | *.sln merge=union
4 | *.csproj merge=union
5 | *.vbproj merge=union
6 | *.fsproj merge=union
7 | *.dbproj merge=union
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | Docs
4 | Publishing/lib
5 | *.nupkg
6 | .nuget/nuget.exe
7 |
8 | # User-specific files
9 | *.suo
10 | *.user
11 | *.sln.docstates
12 | *.userprefs
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | x64/
18 | build/
19 | bld/
20 | [Bb]in/
21 | [Oo]bj/
22 |
23 | # MSTest test Results
24 | [Tt]est[Rr]esult*/
25 | [Bb]uild[Ll]og.*
26 |
27 | #NUNIT
28 | *.VisualState.xml
29 | TestResult.xml
30 |
31 | # Build Results of an ATL Project
32 | [Dd]ebugPS/
33 | [Rr]eleasePS/
34 | dlldata.c
35 |
36 | *_i.c
37 | *_p.c
38 | *_i.h
39 | *.ilk
40 | *.meta
41 | *.obj
42 | *.pch
43 | *.pdb
44 | *.pgc
45 | *.pgd
46 | *.rsp
47 | *.sbr
48 | *.tlb
49 | *.tli
50 | *.tlh
51 | *.tmp
52 | *.tmp_proj
53 | *.log
54 | *.vspscc
55 | *.vssscc
56 | .builds
57 | *.pidb
58 | *.svclog
59 | *.scc
60 |
61 | # Chutzpah Test files
62 | _Chutzpah*
63 |
64 | # Visual C++ cache files
65 | ipch/
66 | *.aps
67 | *.ncb
68 | *.opensdf
69 | *.sdf
70 | *.cachefile
71 |
72 | # Visual Studio profiler
73 | *.psess
74 | *.vsp
75 | *.vspx
76 |
77 | # TFS 2012 Local Workspace
78 | $tf/
79 |
80 | # Guidance Automation Toolkit
81 | *.gpState
82 |
83 | # ReSharper is a .NET coding add-in
84 | _ReSharper*/
85 | *.[Rr]e[Ss]harper
86 | *.DotSettings.user
87 |
88 | # JustCode is a .NET coding addin-in
89 | .JustCode
90 |
91 | # TeamCity is a build add-in
92 | _TeamCity*
93 |
94 | # DotCover is a Code Coverage Tool
95 | *.dotCover
96 |
97 | # NCrunch
98 | *.ncrunch*
99 | _NCrunch_*
100 | .*crunch*.local.xml
101 |
102 | # MightyMoose
103 | *.mm.*
104 | AutoTest.Net/
105 |
106 | # Web workbench (sass)
107 | .sass-cache/
108 |
109 | # Installshield output folder
110 | [Ee]xpress/
111 |
112 | # DocProject is a documentation generator add-in
113 | DocProject/buildhelp/
114 | DocProject/Help/*.HxT
115 | DocProject/Help/*.HxC
116 | DocProject/Help/*.hhc
117 | DocProject/Help/*.hhk
118 | DocProject/Help/*.hhp
119 | DocProject/Help/Html2
120 | DocProject/Help/html
121 |
122 | # Click-Once directory
123 | publish/
124 |
125 | # Publish Web Output
126 | *.[Pp]ublish.xml
127 | *.azurePubxml
128 |
129 | # NuGet Packages Directory
130 | packages/
131 | ## TODO: If the tool you use requires repositories.config uncomment the next line
132 | #!packages/repositories.config
133 |
134 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
135 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented)
136 | !packages/build/
137 |
138 | # Windows Azure Build Output
139 | csx/
140 | *.build.csdef
141 |
142 | # Windows Store app package directory
143 | AppPackages/
144 |
145 | # Others
146 | sql/
147 | *.Cache
148 | ClientBin/
149 | [Ss]tyle[Cc]op.*
150 | ~$*
151 | *~
152 | *.dbmdl
153 | *.dbproj.schemaview
154 | *.pfx
155 | *.publishsettings
156 | node_modules/
157 |
158 | # RIA/Silverlight projects
159 | Generated_Code/
160 |
161 | # Backup & report files from converting an old project file to a newer
162 | # Visual Studio version. Backup files are not needed, because we have git ;-)
163 | _UpgradeReport_Files/
164 | Backup*/
165 | UpgradeLog*.XML
166 | UpgradeLog*.htm
167 |
168 | # SQL Server files
169 | *.mdf
170 | *.ldf
171 |
172 | # Business Intelligence projects
173 | *.rdl.data
174 | *.bim.layout
175 | *.bim_*.settings
176 |
177 | # Microsoft Fakes
178 | FakesAssemblies/
179 |
--------------------------------------------------------------------------------
/.nuget/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.nuget/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ### 0.5.0 / 2017-07-05 (0.5.0-pre / 2017-02-04)
2 | * separation from the core Metrics.NET library. For changes previous to this version, see the changelog of the core library.
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2016 Jason O'Bryan, The Recognos Metrics.NET Team
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Metrics.InfluxDB.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25123.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metrics.InfluxDB", "Src\Metrics.InfluxDB\Metrics.InfluxDB.csproj", "{1B6C2147-30DB-4C58-AD92-5FD34937F9A4}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metrics.InfluxDB.Tests", "Src\Metrics.InfluxDB.Tests\Metrics.InfluxDB.Tests.csproj", "{1D9413B0-4B25-48AC-9298-554284D409DE}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{1555B234-F26A-4035-B319-22B968388198}"
11 | ProjectSection(SolutionItems) = preProject
12 | .nuget\nuget.config = .nuget\nuget.config
13 | .nuget\packages.config = .nuget\packages.config
14 | EndProjectSection
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{6FC413CE-2AD2-4A89-A11E-B8A34112DFEA}"
17 | ProjectSection(SolutionItems) = preProject
18 | build.bat = build.bat
19 | build.sh = build.sh
20 | EndProjectSection
21 | EndProject
22 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Publishing", "Publishing", "{5812CC1A-41DB-4BAA-A7B2-03318A9C6BA2}"
23 | ProjectSection(SolutionItems) = preProject
24 | create-nuget.bat = create-nuget.bat
25 | Publishing\Metrics.NET.InfluxDB.nuspec = Publishing\Metrics.NET.InfluxDB.nuspec
26 | Publishing\push-nuget.bat = Publishing\push-nuget.bat
27 | EndProjectSection
28 | EndProject
29 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EDB9E6D3-9939-4F18-A2F5-05C2363B9D72}"
30 | ProjectSection(SolutionItems) = preProject
31 | CHANGELOG.md = CHANGELOG.md
32 | LICENSE = LICENSE
33 | README.md = README.md
34 | SharedAssemblyInfo.cs = SharedAssemblyInfo.cs
35 | EndProjectSection
36 | EndProject
37 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Metrics.InfluxDB.SamplesConsole", "Src\Metrics.InfluxDB.SamplesConsole\Metrics.InfluxDB.SamplesConsole.csproj", "{3D15CA8C-06EA-4302-829D-A201871DB1FC}"
38 | EndProject
39 | Global
40 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
41 | Debug|Any CPU = Debug|Any CPU
42 | Release|Any CPU = Release|Any CPU
43 | EndGlobalSection
44 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
45 | {1B6C2147-30DB-4C58-AD92-5FD34937F9A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46 | {1B6C2147-30DB-4C58-AD92-5FD34937F9A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
47 | {1B6C2147-30DB-4C58-AD92-5FD34937F9A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
48 | {1B6C2147-30DB-4C58-AD92-5FD34937F9A4}.Release|Any CPU.Build.0 = Release|Any CPU
49 | {1D9413B0-4B25-48AC-9298-554284D409DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50 | {1D9413B0-4B25-48AC-9298-554284D409DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
51 | {1D9413B0-4B25-48AC-9298-554284D409DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
52 | {1D9413B0-4B25-48AC-9298-554284D409DE}.Release|Any CPU.Build.0 = Release|Any CPU
53 | {3D15CA8C-06EA-4302-829D-A201871DB1FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54 | {3D15CA8C-06EA-4302-829D-A201871DB1FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
55 | {3D15CA8C-06EA-4302-829D-A201871DB1FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
56 | {3D15CA8C-06EA-4302-829D-A201871DB1FC}.Release|Any CPU.Build.0 = Release|Any CPU
57 | EndGlobalSection
58 | GlobalSection(SolutionProperties) = preSolution
59 | HideSolutionNode = FALSE
60 | EndGlobalSection
61 | EndGlobal
62 |
--------------------------------------------------------------------------------
/Publishing/Metrics.NET.InfluxDB.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Metrics.NET.InfluxDbReporting
5 | 0.5.0
6 | Metrics.NET.InfluxDbReporting
7 | Jason O'Bryan, The Recognos Metrics.NET Team
8 | Jason O'Bryan, The Recognos Metrics.NET Team
9 | https://github.com/Recognos/Metrics.NET.InfluxDB/blob/master/LICENSE
10 | https://github.com/Recognos/Metrics.NET.InfluxDB
11 | http://www.erata.net/Metrics.NET/metrics_32.png
12 | false
13 | This library provides support for InfluxDB reporters in the Metrics.NET monitoring and reporting library. Supports InfluxDB Line Protocol for InfluxDB v0.9.1 and above, and JSON Protocol for InfluxDB v0.9.1 and below.
14 | InfluxDB reporter integration for the Metrics.NET monitoring and reporting library.
15 | Jason O'Bryan, The Recognos Metrics.NET Team
16 | influxdb, influx, metrics, measurements, charts, timer, histogram, duration, health checks
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Publishing/push-nuget.bat:
--------------------------------------------------------------------------------
1 | ..\.nuget\nuget.exe push Metrics.NET.InfluxDbReporting.0.5.0.nupkg -Source https://www.nuget.org
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Metrics.NET.InfluxDB
2 |
3 | InfluxDB reporter integration for Metrics.NET.
4 |
5 | Current version: **v0.5.0-pre**
6 |
7 | This library provides support for InfluxDB reporters using the [Metrics.NET](https://github.com/Recognos/Metrics.NET) monitoring and reporting library.
8 |
9 | Supports InfluxDB Line Protocol for InfluxDB v0.9.1 and above.
10 | Supports InfluxDB JSON Protocol for InfluxDB v0.9.1 and below.
11 |
12 | The JSON protocol, which was previously used by the InfluxDB reporter, has been [deprecated](https://docs.influxdata.com/influxdb/v0.13/write_protocols/json/) and removed in InfluxDB versions greater than v0.9.1. The expected way to write metric data to InfluxDB after this point is by using the [LineProtocol syntax](https://docs.influxdata.com/influxdb/v0.13/write_protocols/line/) defined in the InfluxDB docs.
13 |
14 | This library adds support for the newer versions of InfluxDB which use the line protocol syntax and supports both the HTTP and UDP protocols.
15 |
16 | More documentation is availale in the [wiki](https://github.com/Recognos/Metrics.NET.InfluxDB/wiki).
17 |
18 | [Changelog](https://github.com/Recognos/Metrics.NET.InfluxDB/blob/master/CHANGELOG.md)
19 |
20 | [Metrics.NET Repository](https://github.com/Recognos/Metrics.NET)
21 |
22 | ## Configuration
23 |
24 | Configuration can be done using the different overloads of the `MetricsReports` configuration object. For example, the following code will add an InfluxDB reporter using the HTTP protocol for a database named `testdb` on host `10.0.10.24:80`:
25 | ```
26 | Metric.Config
27 | .WithReporting(report => report
28 | .WithInfluxDbHttp("10.0.10.24", "testdb", reportInterval, null, c => c
29 | .WithConverter(new DefaultConverter().WithGlobalTags("host=web1,env=dev"))
30 | .WithFormatter(new DefaultFormatter().WithLowercase(true))
31 | .WithWriter(new InfluxdbHttpWriter(c, 1000))));
32 | ```
33 |
34 | ## Extensibility
35 |
36 | The InfluxDB report has been refactored to separate the writing process into a separate `InfluxdbWriter` which is responsible for writing the data using the whichever protocol is chosen. This also allows extending the model to support other or future types of protocols and formats defined by InfluxDB.
37 |
38 | Writing data to InfluxDB is done in 3 different and extendable steps:
39 | - `InfluxdbConverter`: Converts the metric data into `InfluxRecords`, which are the data model object for InfluxDB datapoints.
40 | - `InfluxdbFormatter`: Formats the metric name and tag/field names used in the InfluxDB tables. For example, this can convert all names to lowercase or replace any spaces with underscores.
41 | - `InfluxdbWriter`: Writes the `InfluxRecords` to the database. Derived implementations exist for the HTTP and UDP protocols.
42 |
43 | ## Building
44 |
45 | _NOTE: All build scripts must be run from the repository root._
46 |
47 | Run `build.bat` to compile and test the `Metrics.InfluxDB.dll` assmebly. Output gets copied to the `.\bin\` directory.
48 |
49 | Run `create-nuget.bat` to build the solution and create a nuget `.nupkg` package in the `.\Publishing\` directory.
50 |
51 | ## License
52 |
53 | This library will keep the same license as the main [Metrics.NET project](https://github.com/Recognos/Metrics.NET).
54 |
55 | The main metrics project is released under the terms:
56 | Copyright (c) 2016 The Recognos Metrics.NET Team
57 | Published under Apache Software License 2.0, see [LICENSE](https://github.com/Recognos/Metrics.NET/blob/master/LICENSE)
58 |
59 | This library (Metrics.NET.InfluxDB) is released under the Apache 2.0 License (see [LICENSE](https://github.com/Recognos/Metrics.NET.InfluxDB/blob/master/LICENSE))
60 | Copyright (c) 2016 Jason O'Bryan, The Recognos Metrics.NET Team
61 |
--------------------------------------------------------------------------------
/SharedAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 |
4 | [assembly: AssemblyConfiguration("")]
5 | [assembly: AssemblyCompany("The Recognos Metrics.NET Team")]
6 | [assembly: AssemblyProduct("Metrics.NET")]
7 | [assembly: AssemblyCopyright("Copyright Jason O'Bryan, The Recognos Metrics.NET Team © 2017")]
8 | [assembly: ComVisible(false)]
9 | [assembly: AssemblyVersion("0.5.0")]
10 | [assembly: AssemblyFileVersion("0.5.0")]
11 | [assembly: AssemblyInformationalVersion("0.5.0")]
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.SamplesConsole/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.SamplesConsole/Metrics.InfluxDB.SamplesConsole.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {3D15CA8C-06EA-4302-829D-A201871DB1FC}
8 | Exe
9 | Properties
10 | Metrics.InfluxDB.SamplesConsole
11 | Metrics.InfluxDB.SamplesConsole
12 | v4.5
13 | 512
14 | true
15 |
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | ..\..\bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | ..\..\bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 | ..\..\packages\Metrics.NET.0.3.7\lib\net45\Metrics.dll
39 | True
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | {1b6c2147-30db-4c58-ad92-5fd34937f9a4}
61 | Metrics.InfluxDB
62 |
63 |
64 |
65 |
72 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.SamplesConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Metrics.InfluxDB.SamplesConsole
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | Metric.Config
10 | .WithReporting(config => config
11 | .WithInfluxDbHttp(new Uri(""), TimeSpan.FromSeconds(10)));
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.SamplesConsole/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Metrics.InfluxDB.SamplesConsole")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Metrics.InfluxDB.SamplesConsole")]
13 | [assembly: AssemblyCopyright("Copyright © 2017")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("3d15ca8c-06ea-4302-829d-a201871db1fc")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.SamplesConsole/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.Tests/InfluxdbTestUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Diagnostics;
4 | using System.Text;
5 | using Metrics.InfluxDB.Adapters;
6 | using Metrics.InfluxDB.Model;
7 |
8 | namespace Metrics.InfluxDB.Tests
9 | {
10 | ///
11 | /// Defines a test case for an .
12 | ///
13 | public class TagTestCase
14 | {
15 | public InfluxTag Tag { get; set; }
16 | public String Output { get; set; }
17 |
18 | public TagTestCase(String key, String value, String output)
19 | : this(new InfluxTag(key, value), output) {
20 | }
21 |
22 | public TagTestCase(InfluxTag tag, String output) {
23 | Tag = tag;
24 | Output = output;
25 | }
26 |
27 | public Object[] ToArray() { return this; }
28 |
29 | public static implicit operator Object[] (TagTestCase item) {
30 | return new Object[] { item.Tag, item.Output };
31 | }
32 | }
33 |
34 | ///
35 | /// Defines a test case for an .
36 | ///
37 | public class FieldTestCase
38 | {
39 | public InfluxField Field { get; set; }
40 | public String Output { get; set; }
41 |
42 | public FieldTestCase(String key, Object value, String output)
43 | : this(new InfluxField(key, value), output) {
44 | }
45 |
46 | public FieldTestCase(InfluxField field, String output) {
47 | Field = field;
48 | Output = output;
49 | }
50 |
51 | public Object[] ToArray() { return this; }
52 |
53 | public static implicit operator Object[] (FieldTestCase item) {
54 | return new Object[] { item.Field, item.Output };
55 | }
56 | }
57 |
58 |
59 | ///
60 | /// An implementation used for unit testing. This writer keeps a list of all batches flushed to the writer.
61 | ///
62 | public class InfluxdbTestWriter : InfluxdbLineWriter
63 | {
64 | ///
65 | /// The list of all batches flushed by the writer.
66 | ///
67 | public List FlushHistory { get; } = new List();
68 |
69 | ///
70 | /// A copy of the last batch that was flushed by the writer.
71 | ///
72 | public InfluxBatch LastBatch { get; private set; } = new InfluxBatch();
73 |
74 | ///
75 | /// Creates a new with the specified configuration and batch size.
76 | ///
77 | /// The InfluxDB configuration.
78 | /// The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.
79 | public InfluxdbTestWriter(InfluxConfig config, Int32 batchSize = 0)
80 | : base(config, batchSize) {
81 | }
82 |
83 |
84 | protected override Byte[] WriteToTransport(Byte[] bytes) {
85 | var lastBatch = LastBatch = new InfluxBatch(Batch.ToArray());
86 | FlushHistory.Add(lastBatch);
87 | return null;
88 | }
89 | }
90 |
91 | ///
92 | /// An implementation used for unit testing. This writer keeps a list of all batches flushed to the writer.
93 | ///
94 | public class InfluxdbHttpWriterExt : InfluxdbHttpWriter
95 | {
96 | ///
97 | /// The list of all batches flushed by the writer.
98 | ///
99 | public List FlushHistory { get; } = new List();
100 |
101 | ///
102 | /// A copy of the last batch that was flushed by the writer.
103 | ///
104 | public InfluxBatch LastBatch { get; private set; } = new InfluxBatch();
105 |
106 |
107 | ///
108 | /// Creates a new with the specified URI.
109 | ///
110 | /// The HTTP URI of the InfluxDB server.
111 | public InfluxdbHttpWriterExt(Uri influxDbUri)
112 | : base(influxDbUri) {
113 | }
114 |
115 | ///
116 | /// Creates a new with the specified URI.
117 | ///
118 | /// The InfluxDB configuration.
119 | /// The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.
120 | public InfluxdbHttpWriterExt(InfluxConfig config, Int32 batchSize = 0)
121 | : base(config, batchSize) {
122 | }
123 |
124 |
125 | protected override Byte[] WriteToTransport(Byte[] bytes) {
126 | var lastBatch = LastBatch = new InfluxBatch(Batch.ToArray());
127 | FlushHistory.Add(lastBatch);
128 |
129 | Debug.WriteLine($"[HTTP] InfluxDB LineProtocol Write (count={lastBatch.Count} bytes={formatSize(bytes.Length)})");
130 | Stopwatch sw = Stopwatch.StartNew();
131 | Byte[] res = base.WriteToTransport(bytes);
132 | Debug.WriteLine($"[HTTP] Uploaded {lastBatch.Count} measurements to InfluxDB in {sw.ElapsedMilliseconds:n0}ms. :: Bytes written: {formatSize(bytes.Length)} - Response string ({formatSize(res.Length)}): {Encoding.UTF8.GetString(res)}");
133 | return res;
134 | }
135 | }
136 |
137 | ///
138 | /// An implementation used for unit testing. This writer keeps a list of all batches flushed to the writer.
139 | ///
140 | public class InfluxdbUdpWriterExt : InfluxdbUdpWriter
141 | {
142 | ///
143 | /// The list of all batches flushed by the writer.
144 | ///
145 | public List FlushHistory { get; } = new List();
146 |
147 | ///
148 | /// A copy of the last batch that was flushed by the writer.
149 | ///
150 | public InfluxBatch LastBatch { get; private set; } = new InfluxBatch();
151 |
152 |
153 | ///
154 | /// Creates a new with the specified URI.
155 | ///
156 | /// The UDP URI of the InfluxDB server.
157 | public InfluxdbUdpWriterExt(Uri influxDbUri)
158 | : base(influxDbUri) {
159 | }
160 |
161 | ///
162 | /// Creates a new with the specified URI.
163 | ///
164 | /// The InfluxDB configuration.
165 | /// The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.
166 | public InfluxdbUdpWriterExt(InfluxConfig config, Int32 batchSize = 0)
167 | : base(config, batchSize) {
168 | }
169 |
170 |
171 | protected override Byte[] WriteToTransport(Byte[] bytes) {
172 | var lastBatch = LastBatch = new InfluxBatch(Batch.ToArray());
173 | FlushHistory.Add(lastBatch);
174 |
175 | Debug.WriteLine($"[UDP] InfluxDB LineProtocol Write (count={lastBatch.Count} bytes={formatSize(bytes.Length)})");
176 | Stopwatch sw = Stopwatch.StartNew();
177 | Byte[] res = base.WriteToTransport(bytes);
178 | Debug.WriteLine($"[UDP] Uploaded {lastBatch.Count} measurements to InfluxDB in {sw.ElapsedMilliseconds:n0}ms. :: Bytes written: {formatSize(bytes.Length)} - Response string ({formatSize(res.Length)}): {Encoding.UTF8.GetString(res)}");
179 | return res;
180 | }
181 | }
182 |
183 | ///
184 | /// An implementation used for unit testing. This writer keeps a list of all batches flushed to the writer.
185 | ///
186 | public class InfluxdbJsonWriterExt : InfluxdbJsonWriter
187 | {
188 | ///
189 | /// The list of all batches flushed by the writer.
190 | ///
191 | public List FlushHistory { get; } = new List();
192 |
193 | ///
194 | /// A copy of the last batch that was flushed by the writer.
195 | ///
196 | public InfluxBatch LastBatch { get; private set; } = new InfluxBatch();
197 |
198 |
199 | ///
200 | /// Creates a new with the specified URI.
201 | ///
202 | /// The JSON URI of the InfluxDB server.
203 | public InfluxdbJsonWriterExt(Uri influxDbUri)
204 | : base(influxDbUri) {
205 | }
206 |
207 | ///
208 | /// Creates a new with the specified URI.
209 | ///
210 | /// The InfluxDB configuration.
211 | /// The maximum number of records to write per flush. Set to zero to write all records in a single flush. Negative numbers are not allowed.
212 | public InfluxdbJsonWriterExt(InfluxConfig config, Int32 batchSize = 0)
213 | : base(config, batchSize) {
214 | }
215 |
216 |
217 | protected override Byte[] WriteToTransport(Byte[] bytes) {
218 | var lastBatch = LastBatch = new InfluxBatch(Batch.ToArray());
219 | FlushHistory.Add(lastBatch);
220 |
221 | Debug.WriteLine($"[JSON] InfluxDB LineProtocol Write (count={lastBatch.Count} bytes={formatSize(bytes.Length)})");
222 | Stopwatch sw = Stopwatch.StartNew();
223 | Byte[] res = base.WriteToTransport(bytes);
224 | Debug.WriteLine($"[JSON] Uploaded {lastBatch.Count} measurements to InfluxDB in {sw.ElapsedMilliseconds:n0}ms. :: Bytes written: {formatSize(bytes.Length)} - Response string ({formatSize(res.Length)}): {Encoding.UTF8.GetString(res)}");
225 | return res;
226 | }
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/Src/Metrics.InfluxDB.Tests/InfluxdbTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Threading;
5 | using Metrics.InfluxDB;
6 | using Metrics.InfluxDB.Model;
7 | using FluentAssertions;
8 | using Xunit;
9 |
10 | namespace Metrics.InfluxDB.Tests
11 | {
12 | public class InfluxdbTests
13 | {
14 |
15 | [Fact]
16 | public void InfluxTag_CanParse_InvalidValueReturnsEmpty() {
17 | // invalid input strings
18 | InfluxTag empty = InfluxTag.Empty;
19 | String nullReason = "Because the input string should contain a single key and value separated by an equals sign.";
20 | InfluxUtils.ToInfluxTag("key").Should().Be(empty, nullReason);
21 | InfluxUtils.ToInfluxTag("key=").Should().Be(empty, nullReason);
22 | InfluxUtils.ToInfluxTag("=value").Should().Be(empty, nullReason);
23 | InfluxUtils.ToInfluxTag("key=value1=value2").Should().Be(empty, nullReason);
24 | InfluxUtils.ToInfluxTag("key,value").Should().Be(empty, nullReason);
25 | InfluxUtils.ToInfluxTag("key==").Should().Be(empty, nullReason);
26 | InfluxUtils.ToInfluxTag("==val").Should().Be(empty, nullReason);
27 | }
28 |
29 | [Fact]
30 | public void InfluxTag_CanParse_SingleFromString() {
31 | // valid input strings
32 | InfluxUtils.ToInfluxTag("key=value").Should().Be(new InfluxTag("key", "value"));
33 | InfluxUtils.ToInfluxTag("key with spaces=value with spaces").Should().Be(new InfluxTag("key with spaces", "value with spaces"));
34 | InfluxUtils.ToInfluxTag("key,with,commas=value,with,commas").Should().Be(new InfluxTag("key,with,commas", "value,with,commas"));
35 | InfluxUtils.ToInfluxTag("key\"with\"quot=value\"with\"quot").Should().Be(new InfluxTag("key\"with\"quot", "value\"with\"quot"));
36 | }
37 |
38 | [Fact]
39 | public void InfluxTag_CanParse_MultiFromCommaSeparatedString() {
40 | // comma-separated single string
41 | InfluxUtils.ToInfluxTags("key").Should().BeEmpty();
42 | InfluxUtils.ToInfluxTags("key1=value1,key2=value2").Should().BeEquivalentTo(new InfluxTag("key1", "value1"), new InfluxTag("key2", "value2"));
43 | InfluxUtils.ToInfluxTags("key1,key2=value2,key3,key4").Should().BeEquivalentTo(new InfluxTag("key2", "value2"));
44 | }
45 |
46 | [Fact]
47 | public void InfluxTag_CanParse_MultiFromStringArray() {
48 | // string[] array
49 | InfluxUtils.ToInfluxTags("key1", "key2").Should().BeEmpty();
50 | InfluxUtils.ToInfluxTags("key1=value1", "key2=value2").Should().BeEquivalentTo(new InfluxTag("key1", "value1"), new InfluxTag("key2", "value2"));
51 | InfluxUtils.ToInfluxTags("key1", "key2=value2", "key3", "key4").Should().BeEquivalentTo(new InfluxTag("key2", "value2"));
52 | }
53 |
54 | [Fact]
55 | public void InfluxTag_CanParse_FromSingleMetricTags() {
56 | InfluxUtils.ToInfluxTags(new MetricTags("key1", "key2")).Should().BeEmpty();
57 | InfluxUtils.ToInfluxTags(new MetricTags("key1=value1", "key2")).Should().BeEquivalentTo(new InfluxTag("key1", "value1"));
58 | InfluxUtils.ToInfluxTags(new MetricTags("key1", "key2=value2")).Should().BeEquivalentTo(new InfluxTag("key2", "value2"));
59 | InfluxUtils.ToInfluxTags(new MetricTags("key1=value1", "key2=value2")).Should().BeEquivalentTo(new InfluxTag("key1", "value1"), new InfluxTag("key2", "value2"));
60 | }
61 |
62 | [Fact]
63 | public void InfluxTag_CanParse_FromMultiMetricTags() {
64 | InfluxUtils.ToInfluxTags(new MetricTags("key1", "key2"), new MetricTags("key3", "key4")).Should().BeEmpty();
65 | InfluxUtils.ToInfluxTags(new MetricTags("key1=value1", "key2"), new MetricTags("key3=value3", "key4")).Should().BeEquivalentTo(new InfluxTag("key1", "value1"), new InfluxTag("key3", "value3"));
66 | InfluxUtils.ToInfluxTags(new MetricTags("key1", "key2=value2"), new MetricTags("key3", "key4=value4")).Should().BeEquivalentTo(new InfluxTag("key2", "value2"), new InfluxTag("key4", "value4"));
67 | InfluxUtils.ToInfluxTags(new MetricTags("key1=value1", "key2=value2"), new MetricTags("key3=value3", "key4=value4")).Should().BeEquivalentTo(new InfluxTag("key1", "value1"), new InfluxTag("key2", "value2"), new InfluxTag("key3", "value3"), new InfluxTag("key4", "value4"));
68 | }
69 |
70 |
71 | [Fact]
72 | public void InfluxField_SupportsValidValueTypes() {
73 | var validTypes = InfluxUtils.ValidValueTypes;
74 | foreach (var type in validTypes)
75 | InfluxUtils.IsValidValueType(type).Should().BeTrue();
76 | }
77 |
78 | [Theory]
79 | [MemberData(nameof(TagTestCasesArray))]
80 | public void InfluxTag_FormatsTo_LineProtocol(InfluxTag tag, String output) {
81 | tag.ToLineProtocol().Should().Be(output);
82 | tag.ToString().Should().Be(output);
83 | }
84 |
85 | [Theory]
86 | [MemberData(nameof(FieldTestCasesArray))]
87 | public void InfluxField_FormatsTo_LineProtocol(InfluxField field, String output) {
88 | field.ToLineProtocol().Should().Be(output);
89 | field.ToString().Should().Be(output);
90 | }
91 |
92 | [Fact]
93 | public void InfluxRecord_FormatsTo_LineProtocol() {
94 | // test values
95 | var testNow = new DateTime(2016, 6, 1, 0, 0, 0, DateTimeKind.Utc);
96 | var testTags = TagTestCases.Select(tc => tc.Tag);
97 | var testFields = FieldTestCases.Select(tc => tc.Field);
98 | var precision = InfluxConfig.Default.Precision;
99 |
100 | // expected values
101 | String expTime = InfluxLineProtocol.FormatTimestamp(testNow, precision);
102 | String expTags = String.Join(",", TagTestCases.Select(tc => tc.Output));
103 | String expFields = String.Join(",", FieldTestCases.Select(tc => tc.Output));
104 | String expOutput = String.Format("test_name,{0} {1} {2}", expTags, expFields, expTime);
105 |
106 | // assert line values match expected
107 | new InfluxRecord("name spaces", new[] { new InfluxField("field1", 123456) })
108 | .ToLineProtocol(precision).Should().Be(@"name\ spaces field1=123456i");
109 | new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) })
110 | .ToLineProtocol(precision).Should().Be(@"test_name,tag1=value1 field1=123456i");
111 | new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1"), new InfluxTag("tag2", "value2") }, new[] { new InfluxField("field1", 123456), new InfluxField("field2", true) })
112 | .ToLineProtocol(precision).Should().Be(@"test_name,tag1=value1,tag2=value2 field1=123456i,field2=True");
113 | new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", "test string") }, testNow)
114 | .ToLineProtocol(precision).Should().Be($@"test_name,tag1=value1 field1=""test string"" {expTime}");
115 | new InfluxRecord("test_name", testTags, testFields, testNow)
116 | .ToLineProtocol(precision).Should().Be(expOutput);
117 | }
118 |
119 | [Fact]
120 | public void InfluxBatch_FormatsTo_LineProtocol() {
121 | var testNow = new DateTime(2016, 6, 1, 0, 0, 0, DateTimeKind.Utc);
122 | var testTags = TagTestCases.Select(tc => tc.Tag);
123 | var testFields = FieldTestCases.Select(tc => tc.Field);
124 | var precision = InfluxConfig.Default.Precision;
125 | var expTime = InfluxLineProtocol.FormatTimestamp(testNow, precision);
126 |
127 | // test with empty batch
128 | InfluxBatch batch = new InfluxBatch();
129 | batch.ToLineProtocol(precision).Should().BeEmpty();
130 |
131 | // test with single record
132 | batch.Add(new InfluxRecord("test_name", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) }));
133 | batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(@"test_name,tag1=value1 field1=123456i");
134 | batch.Clear();
135 |
136 | // test with multiple records
137 | batch.Add(new InfluxRecord("test_name1", new[] { new InfluxTag("tag1", "value1") }, new[] { new InfluxField("field1", 123456) }));
138 | batch.Add(new InfluxRecord("test_name2", new[] { new InfluxTag("tag2", "value2") }, new[] { new InfluxField("field2", 234561) }));
139 | batch.Add(new InfluxRecord("test_name3", new[] { new InfluxTag("tag3", "value3") }, new[] { new InfluxField("field3", 345612) }, testNow));
140 | batch.Add(new InfluxRecord("test_name4", new[] { new InfluxTag("tag4", "value4") }, new[] { new InfluxField("field4", 456123) }, testNow));
141 | batch.Add(new InfluxRecord("test_name5", new[] { new InfluxTag("tag5", "value5") }, new[] { new InfluxField("field5", 561234) }, testNow));
142 |
143 | String expOutput = String.Join("\n",
144 | $@"test_name1,tag1=value1 field1=123456i",
145 | $@"test_name2,tag2=value2 field2=234561i",
146 | $@"test_name3,tag3=value3 field3=345612i {expTime}",
147 | $@"test_name4,tag4=value4 field4=456123i {expTime}",
148 | $@"test_name5,tag5=value5 field5=561234i {expTime}"
149 | );
150 |
151 | batch.ToLineProtocol(precision).Should().NotEndWith("\n").And.Be(expOutput);
152 | }
153 |
154 | [Fact]
155 | public void InfluxReport_CanAddRecords_ForGauge() {
156 | var config = new InfluxConfig("localhost", "testdb");
157 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
158 | var report = new InfluxdbHttpReport(config);
159 | var context = new DefaultMetricsContext("TestContext");
160 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
161 | var metricsData = context.DataProvider.CurrentMetricsData;
162 |
163 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
164 | writer.LastBatch.Should().BeEmpty("Because running a report with no metrics should not result in any records.");
165 |
166 | context.Gauge("test_gauge", () => 123.456, Unit.Bytes, new MetricTags("key1=value1,tag2,tag3,key4=value4"));
167 | metricsData = context.DataProvider.CurrentMetricsData;
168 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
169 | writer.LastBatch.Should().HaveCount(1);
170 |
171 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
172 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_gauge,key1=value1,key4=value4 value=123.456 {expTime}");
173 | }
174 |
175 | [Fact]
176 | public void InfluxReport_CanAddRecords_ForCounter() {
177 | var config = new InfluxConfig("localhost", "testdb");
178 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
179 | var report = new InfluxdbHttpReport(config);
180 | var context = new DefaultMetricsContext("TestContext");
181 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
182 | var metricsData = context.DataProvider.CurrentMetricsData;
183 | var counter = context.Counter("test_counter", Unit.Bytes, new MetricTags("key1=value1,tag2,tag3,key4=value4"));
184 |
185 | // add normally
186 | counter.Increment(300);
187 | metricsData = context.DataProvider.CurrentMetricsData;
188 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
189 | writer.LastBatch.Should().HaveCount(1);
190 |
191 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
192 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_counter,key1=value1,key4=value4 count=300i {expTime}");
193 |
194 | // add with set item
195 | counter.Increment("item1,item2=ival2,item3=ival3", 100);
196 | metricsData = context.DataProvider.CurrentMetricsData;
197 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
198 | writer.LastBatch.Should().HaveCount(2);
199 |
200 | expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
201 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_counter,key1=value1,key4=value4 count=400i {expTime}");
202 | writer.LastBatch[1].ToLineProtocol(precision).Should().Be($@"testcontext.test_counter,item2=ival2,item3=ival3,key1=value1,key4=value4 count=100i,percent=25 {expTime}");
203 | }
204 |
205 | [Fact]
206 | public void InfluxReport_CanAddRecords_ForMeter() {
207 | var config = new InfluxConfig("localhost", "testdb");
208 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
209 | var report = new InfluxdbHttpReport(config);
210 | var context = new DefaultMetricsContext("TestContext");
211 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
212 | var metricsData = context.DataProvider.CurrentMetricsData;
213 | var meter = context.Meter("test_meter", Unit.Bytes, TimeUnit.Seconds, new MetricTags("key1=value1,tag2,tag3,key4=value4"));
214 |
215 | // add normally
216 | meter.Mark(300);
217 | metricsData = context.DataProvider.CurrentMetricsData;
218 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
219 | writer.LastBatch.Should().HaveCount(1);
220 |
221 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
222 | writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,key1=value1,key4=value4 count=300i,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}"); ;
223 |
224 | // add with set item
225 | meter.Mark("item1,item2=ival2,item3=ival3", 100);
226 | metricsData = context.DataProvider.CurrentMetricsData;
227 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
228 | writer.LastBatch.Should().HaveCount(2);
229 |
230 | expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
231 | writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,key1=value1,key4=value4 count=400i,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}");
232 | writer.LastBatch[1].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_meter,item2=ival2,item3=ival3,key1=value1,key4=value4 count=100i,percent=25,mean_rate=").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0 {expTime}");
233 | }
234 |
235 | [Fact]
236 | public void InfluxReport_CanAddRecords_ForHistogram() {
237 | var config = new InfluxConfig("localhost", "testdb");
238 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
239 | var report = new InfluxdbHttpReport(config);
240 | var context = new DefaultMetricsContext("TestContext");
241 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
242 | var metricsData = context.DataProvider.CurrentMetricsData;
243 | var hist = context.Histogram("test_hist", Unit.Bytes, SamplingType.Default, new MetricTags("key1=value1,tag2,tag3,key4=value4"));
244 |
245 | // add normally
246 | hist.Update(300);
247 | metricsData = context.DataProvider.CurrentMetricsData;
248 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
249 | writer.LastBatch.Should().HaveCount(1);
250 |
251 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
252 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_hist,key1=value1,key4=value4 count=1i,last=300,min=300,mean=300,max=300,stddev=0,median=300,sample_size=1i,percentile_75%=300,percentile_95%=300,percentile_98%=300,percentile_99%=300,percentile_99.9%=300 {expTime}");
253 |
254 | // add with set item
255 | hist.Update(100, "item1,item2=ival2,item3=ival3");
256 | metricsData = context.DataProvider.CurrentMetricsData;
257 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
258 | writer.LastBatch.Should().HaveCount(1);
259 |
260 | expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
261 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"testcontext.test_hist,key1=value1,key4=value4 count=2i,last=100,min=100,mean=200,max=300,stddev=100,median=300,sample_size=2i,percentile_75%=300,percentile_95%=300,percentile_98%=300,percentile_99%=300,percentile_99.9%=300 {expTime}");
262 | }
263 |
264 | [Fact]
265 | public void InfluxReport_CanAddRecords_ForTimer() {
266 | var config = new InfluxConfig("localhost", "testdb");
267 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
268 | var report = new InfluxdbHttpReport(config);
269 | var context = new DefaultMetricsContext("TestContext");
270 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
271 | var metricsData = context.DataProvider.CurrentMetricsData;
272 | var timer = context.Timer("test_timer", Unit.Bytes, SamplingType.Default, TimeUnit.Seconds, TimeUnit.Seconds, new MetricTags("key1=value1,tag2,tag3,key4=value4"));
273 |
274 | // add normally
275 | timer.Record(100, TimeUnit.Seconds);
276 | metricsData = context.DataProvider.CurrentMetricsData;
277 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
278 | writer.LastBatch.Should().HaveCount(1);
279 |
280 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
281 | writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_timer,key1=value1,key4=value4 active_sessions=0i,total_time=100i,count=1i,").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0,last=100,min=100,mean=100,max=100,stddev=0,median=100,sample_size=1i,percentile_75%=100,percentile_95%=100,percentile_98%=100,percentile_99%=100,percentile_99.9%=100 {expTime}");
282 |
283 | // add with set item
284 | timer.Record(50, TimeUnit.Seconds, "item1,item2=ival2,item3=ival3");
285 | metricsData = context.DataProvider.CurrentMetricsData;
286 | report.RunReport(metricsData, hsFunc, CancellationToken.None);
287 | writer.LastBatch.Should().HaveCount(1);
288 |
289 | expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
290 | writer.LastBatch[0].ToLineProtocol(precision).Should().StartWith($@"testcontext.test_timer,key1=value1,key4=value4 active_sessions=0i,total_time=150i,count=2i,").And.EndWith($@",1_min_rate=0,5_min_rate=0,15_min_rate=0,last=50,min=50,mean=75,max=100,stddev=25,median=100,sample_size=2i,percentile_75%=100,percentile_95%=100,percentile_98%=100,percentile_99%=100,percentile_99.9%=100 {expTime}");
291 | }
292 |
293 | [Fact]
294 | public void InfluxReport_CanAddRecords_ForHealthCheck() {
295 | var config = new InfluxConfig("localhost", "testdb");
296 | var writer = new InfluxdbTestWriter(config); config.Writer = writer;
297 | var report = new InfluxdbHttpReport(config);
298 | var context = new DefaultMetricsContext("TestContext");
299 | var precision = config.Precision ?? InfluxConfig.Default.Precision;
300 | var metricsData = context.DataProvider.CurrentMetricsData;
301 |
302 | HealthChecks.UnregisterAllHealthChecks();
303 | HealthChecks.RegisterHealthCheck("Health Check 1", () => HealthCheckResult.Healthy($"Healthy check!"));
304 | HealthChecks.RegisterHealthCheck("Health Check 2", () => HealthCheckResult.Unhealthy($"Unhealthy check!"));
305 | HealthChecks.RegisterHealthCheck("Health Check 3,tag3=key3", () => HealthCheckResult.Healthy($"Healthy check!"));
306 | HealthChecks.RegisterHealthCheck("Health Check 4,tag 4=key 4", () => HealthCheckResult.Healthy($"Healthy check!"));
307 | HealthChecks.RegisterHealthCheck("Name=Health Check 5,tag5=key5", () => HealthCheckResult.Healthy($"Healthy check!"));
308 |
309 | metricsData = context.DataProvider.CurrentMetricsData;
310 | report.RunReport(metricsData, () => HealthChecks.GetStatus(), CancellationToken.None);
311 | HealthChecks.UnregisterAllHealthChecks(); // unreg first in case something below throws
312 | writer.LastBatch.Should().HaveCount(5);
313 |
314 | var expTime = InfluxLineProtocol.FormatTimestamp(metricsData.Timestamp, precision);
315 | writer.LastBatch[0].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_1 ishealthy=True,message=""Healthy check!"" {expTime}");
316 | writer.LastBatch[1].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_2 ishealthy=False,message=""Unhealthy check!"" {expTime}");
317 | writer.LastBatch[2].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_3,tag3=key3 ishealthy=True,message=""Healthy check!"" {expTime}");
318 | writer.LastBatch[3].ToLineProtocol(precision).Should().Be($@"health_checks,name=health_check_4,tag_4=key\ 4 ishealthy=True,message=""Healthy check!"" {expTime}");
319 | writer.LastBatch[4].ToLineProtocol(precision).Should().Be($@"health_checks,name=health\ check\ 5,tag5=key5 ishealthy=True,message=""Healthy check!"" {expTime}");
320 | }
321 |
322 |
323 |
324 | #region Tag and Field Test Cases and Other Static Members
325 |
326 | public static IEnumerable TagTestCases = new[] {
327 | new TagTestCase("key1", "value1", @"key1=value1"),
328 | new TagTestCase("key2 with spaces", "value2 with spaces", @"key2\ with\ spaces=value2\ with\ spaces"),
329 | new TagTestCase("key3,with,commas", "value3,with,commas", @"key3\,with\,commas=value3\,with\,commas"),
330 | new TagTestCase("key4=with=equals", "value4=with=equals", @"key4\=with\=equals=value4\=with\=equals"),
331 | new TagTestCase("key5\"with\"quot", "value5\"with\"quot", "key5\"with\"quot=value5\"with\"quot"),
332 | new TagTestCase("key6\" with,all=", "value6\" with,all=", @"key6""\ with\,all\==value6""\ with\,all\="),
333 | };
334 |
335 | public static IEnumerable FieldTestCases = new[] {
336 | new FieldTestCase("field1_int1", 100, @"field1_int1=100i"),
337 | new FieldTestCase("field1_int2", -100, @"field1_int2=-100i"),
338 | new FieldTestCase("field2_double1", 123456789.123456, @"field2_double1=123456789.123456"),
339 | new FieldTestCase("field2_double2", -123456789.123456, @"field2_double2=-123456789.123456"),
340 | new FieldTestCase("field2_double3", Math.PI, @"field2_double3=3.1415926535897931"),
341 | new FieldTestCase("field2_double4", Double.MinValue, @"field2_double4=-1.7976931348623157E+308"),
342 | new FieldTestCase("field2_double5", Double.MaxValue, @"field2_double5=1.7976931348623157E+308"),
343 | new FieldTestCase("field3_bool1", true, @"field3_bool1=True"),
344 | new FieldTestCase("field3_bool2", false, @"field3_bool2=False"),
345 | new FieldTestCase("field4_string1", "string value1", @"field4_string1=""string value1"""),
346 | new FieldTestCase("field4_string2", "string\"value2", @"field4_string2=""string\""value2"""),
347 | new FieldTestCase("field5 spaces", 100, @"field5\ spaces=100i"),
348 | new FieldTestCase("field6,commas", 100, @"field6\,commas=100i"),
349 | new FieldTestCase("field7=equals", 100, @"field7\=equals=100i"),
350 | new FieldTestCase("field8\"quote", 100, @"field8""quote=100i"),
351 | };
352 |
353 | // these must be defined after the above are defined so the variables are not null
354 | public static IEnumerable