├── global.json
├── tools
└── packages.config
├── ISSUE_TEMPLATE.md
├── NuGet.config
├── version.props
├── sandbox
├── MetricsInfluxDBSandbox
│ ├── appsettings.json
│ ├── MetricsInfluxDBSandbox.csproj.DotSettings
│ ├── MetricsInfluxDBSandbox.csproj
│ ├── ApplicationsMetricsRegistry.cs
│ └── Host.cs
└── MetricsInfluxDBSandboxMvc
│ ├── appsettings.Development.json
│ ├── JustForTesting
│ ├── TestController.cs
│ ├── FileController.cs
│ ├── RandomExceptionController.cs
│ ├── RandomStatusCodeController.cs
│ ├── ToleratingController.cs
│ ├── FrustratingController.cs
│ ├── SlaTestController.cs
│ └── SatisfyingController.cs
│ ├── SandboxMetricsRegistry.cs
│ ├── Properties
│ └── launchSettings.json
│ ├── Controllers
│ ├── RandomValuesForTesting.cs
│ ├── RandomClientIdForTesting.cs
│ ├── RandomBufferGenerator.cs
│ ├── ServiceCollectionExtensions.cs
│ ├── SimpleConsoleMetricsReporter.cs
│ ├── RequestDurationForApdexTesting.cs
│ └── AppBuilderExtensions.cs
│ ├── Startup.cs
│ ├── appsettings.json
│ ├── MetricsInfluxDBSandboxMvc.csproj
│ ├── Registry.cs
│ └── Host.cs
├── src
├── Directory.Build.props
├── App.Metrics.Formatters.InfluxDB
│ ├── App.Metrics.Formatters.InfluxDB.csproj.DotSettings
│ ├── App.Metrics.Formatters.InfluxDB.csproj
│ ├── Internal
│ │ ├── InfluxDBFormatterConstants.cs
│ │ ├── ILineProtocolPoint.cs
│ │ ├── LineProtocolPoints.cs
│ │ ├── LineProtocolPointSingleValue.cs
│ │ ├── LineProtocolPointMultipleValues.cs
│ │ ├── LineProtocolPointBase.cs
│ │ ├── LineProtocolPointLegacy.cs
│ │ └── LineProtocolSyntax.cs
│ ├── MetricsInfluxDBLineProtocolOptions.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── MetricsInfluxDBLineProtocolOutputFormatter.cs
│ ├── Builder
│ │ └── MetricsInfluxDbLineProtocolFormatterBuilder.cs
│ └── MetricSnapshotInfluxDBLineProtocolWriter.cs
└── App.Metrics.Reporting.InfluxDB
│ ├── App.Metrics.Reporting.InfluxDB.csproj.DotSettings
│ ├── Client
│ ├── Constants.cs
│ ├── ILineProtocolClient.cs
│ ├── HttpPolicy.cs
│ ├── LineProtocolWriteResult.cs
│ └── DefaultLineProtocolClient.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── App.Metrics.Reporting.InfluxDB.csproj
│ ├── MetricsReportingInfluxDBOptions.cs
│ ├── InfluxDbMetricsReporter.cs
│ ├── RetentionPolicyOptions.cs
│ ├── InfluxDBOptions.cs
│ └── Builder
│ └── MetricsInfluxDbReporterBuilder.cs
├── benchmarks
├── App.Metrics.InfluxDB.Benchmarks
│ ├── Support
│ │ ├── BenchmarksAssemblyMarker.cs
│ │ └── NullTextWriter.cs
│ ├── Config
│ │ └── DefaultConfig.cs
│ ├── App.Metrics.InfluxDB.Benchmarks.csproj
│ └── BenchmarkDotNetBenchmarks
│ │ └── Formatters
│ │ └── MetricSnapshotInfluxDbLineProtocolWriterBenchmark.cs
└── App.Metrics.InfluxDB.Benchmarks.Runner
│ ├── Program.cs
│ ├── App.Metrics.InfluxDB.Benchmarks.Runner.csproj
│ └── BenchmarkDotNet.Artifacts
│ └── results
│ └── App.Metrics.InfluxDB.Benchmarks.BenchmarkDotNetBenchmarks.Formatters.MetricSnapshotInfluxDbLineProtocolWriterBenchmark-report-github.md
├── GitReleaseManager.yaml
├── test
├── App.Metrics.Reporting.InfluxDB.Facts
│ ├── App.Metrics.Reporting.InfluxDB.Facts.csproj
│ ├── TestClock.cs
│ ├── InfluxDBSettingsTests.cs
│ ├── LineProtocolSyntaxTests.cs
│ ├── RetentionPolicyOptionsTests.cs
│ ├── LineProtocolPointTests.cs
│ └── DefaultLineProtocolClientTests.cs
└── Directory.Build.props
├── stylecop.json
├── app-metrics.licenseheader
├── PULL_REQUEST_TEMPLATE.md
├── .travis.yml
├── appveyor.yml
├── .gitignore
├── .gitattributes
├── AppMetrics.ruleset
├── README.md
├── InfluxDB.sln
└── LICENSE
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "projects": [ "src", "test", "sandbox" ],
3 | "sdk": {
4 | "version": "2.1.301"
5 | }
6 | }
--------------------------------------------------------------------------------
/tools/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Before logging a new issue, please have a quick read through the [contribution guidlines](https://github.com/alhardy/AppMetrics/blob/master/CONTRIBUTING.md).
2 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/version.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 3.0.0
5 |
6 |
7 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandbox/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "MetricsOptions": {
3 | "DefaultContextLabel": "MetricsInfluxDBSandbox",
4 | "GlobalTags": { "env": "stage" },
5 | "Enabled": true,
6 | "ReportingEnabled": true
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/appsettings.Development.json:
--------------------------------------------------------------------------------
1 | {
2 | "Logging": {
3 | "IncludeScopes": false,
4 | "LogLevel": {
5 | "Default": "Debug",
6 | "System": "Information",
7 | "Microsoft": "Information"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks/Support/BenchmarksAssemblyMarker.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | namespace App.Metrics.InfluxDB.Benchmarks.Support
6 | {
7 | public class BenchmarksAssemblyMarker
8 | {
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandbox/MetricsInfluxDBSandbox.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | CSharp71
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/App.Metrics.Formatters.InfluxDB.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | CSharp71
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/App.Metrics.Reporting.InfluxDB.csproj.DotSettings:
--------------------------------------------------------------------------------
1 |
2 | CSharp71
--------------------------------------------------------------------------------
/GitReleaseManager.yaml:
--------------------------------------------------------------------------------
1 | create:
2 | include-footer: false
3 | footer-heading:
4 | footer-content:
5 | footer-includes-milestone: false
6 | milestone-replace-text:
7 | export:
8 | include-created-date-in-title: false
9 | created-date-string-format:
10 | perform-regex-removal: false
11 | regex-text:
12 | multiline-regex: false
13 | issue-labels-include:
14 | - bug
15 | - new feature
16 | - enhancement
17 | - breaking change
18 | - documentation
19 | - refactoring
20 | issue-labels-exclude:
21 | - wontfix
22 | - duplicate
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/TestController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using Microsoft.AspNetCore.Mvc;
6 |
7 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
8 | {
9 | [Route("api/[controller]")]
10 | public class TestController : Controller
11 | {
12 | [HttpGet]
13 | public IActionResult Get()
14 | {
15 | return Ok();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/test/App.Metrics.Reporting.InfluxDB.Facts/App.Metrics.Reporting.InfluxDB.Facts.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(StandardTest)
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/Client/Constants.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 |
7 | namespace App.Metrics.Reporting.InfluxDB.Client
8 | {
9 | internal static class Constants
10 | {
11 | public static readonly TimeSpan DefaultBackoffPeriod = TimeSpan.FromSeconds(30);
12 | public static readonly int DefaultFailuresBeforeBackoff = 3;
13 | public static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30);
14 | }
15 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/Client/ILineProtocolClient.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.IO;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 |
10 | namespace App.Metrics.Reporting.InfluxDB.Client
11 | {
12 | public interface ILineProtocolClient
13 | {
14 | Task WriteAsync(
15 | Stream payload,
16 | CancellationToken cancellationToken = default(CancellationToken));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/App.Metrics.Formatters.InfluxDB.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | App Metrics Formatting, formatting metrics data to InfluxDB formats e.g. Line Protocol
5 | netstandard1.6
6 | $(TargetFrameworks);net452
7 | appmetrics;influxdb
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.Runtime.CompilerServices;
6 |
7 | [assembly: InternalsVisibleTo("App.Metrics.Reporting.InfluxDB.Facts, PublicKey=00240000048000009400000006020000002400005253413100040000010001000961061aa9f970163db728a9792c1cfb7be51f2f986054c676345f9e43f95af5f3114b1962d10888a3ea1dff99bf56bce565f887cb4b004fc44ccb7335700260012a65b9cdd090e6b60c8c67c434ca49563c82c66695f8dc0776770bfaf481ef816767b7dd67d083960a6fcfe33c3c0e1cc198fe7a13b3283133d21b3435ebbb")]
--------------------------------------------------------------------------------
/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | // ACTION REQUIRED: This file was automatically added to your project, but it
3 | // will not take effect until additional steps are taken to enable it. See the
4 | // following page for additional information:
5 | //
6 | // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
7 | "$schema":
8 | "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
9 | "settings": {
10 | "documentationRules": {
11 | "companyName": "App Metrics Contributors",
12 | "xmlHeader": true
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/app-metrics.licenseheader:
--------------------------------------------------------------------------------
1 | extensions: designer.cs generated.cs
2 | extensions: .cs .cpp .h
3 | // Copyright (c) Allan hardy. All rights reserved.
4 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
5 |
6 | extensions: .cshtml
7 | @*
8 | // Copyright (c) Allan hardy. All rights reserved.
9 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
10 | *@
11 |
12 | extensions: .xml .config .xsd
13 |
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks/Config/DefaultConfig.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using BenchmarkDotNet.Configs;
6 | using BenchmarkDotNet.Diagnosers;
7 | using BenchmarkDotNet.Exporters;
8 | using BenchmarkDotNet.Jobs;
9 |
10 | namespace App.Metrics.InfluxDB.Benchmarks.Config
11 | {
12 | public class DefaultConfig : ManualConfig
13 | {
14 | public DefaultConfig()
15 | {
16 | Add(Job.Core);
17 | Add(MarkdownExporter.GitHub);
18 | Add(new MemoryDiagnoser());
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/Client/HttpPolicy.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 |
7 | namespace App.Metrics.Reporting.InfluxDB.Client
8 | {
9 | public class HttpPolicy
10 | {
11 | public HttpPolicy()
12 | {
13 | FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff;
14 | BackoffPeriod = Constants.DefaultBackoffPeriod;
15 | Timeout = Constants.DefaultTimeout;
16 | }
17 |
18 | public TimeSpan BackoffPeriod { get; set; }
19 |
20 | public int FailuresBeforeBackoff { get; set; }
21 |
22 | public TimeSpan Timeout { get; set; }
23 | }
24 | }
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks/Support/NullTextWriter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.IO;
7 | using System.Text;
8 |
9 | namespace App.Metrics.InfluxDB.Benchmarks.Support
10 | {
11 | ///
12 | /// This textwriter discards all values.
13 | ///
14 | public class NullTextWriter : TextWriter
15 | {
16 | public NullTextWriter()
17 | {
18 | }
19 |
20 | public NullTextWriter(IFormatProvider formatProvider)
21 | : base(formatProvider)
22 | {
23 | }
24 |
25 | public override Encoding Encoding => Encoding.UTF8;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/FileController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using Microsoft.AspNetCore.Http;
7 | using Microsoft.AspNetCore.Mvc;
8 |
9 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
10 | {
11 | [Route("api/[controller]")]
12 | public class FileController : Controller
13 | {
14 | [HttpPost]
15 | public IActionResult Post(IFormFile file)
16 | {
17 | return Created(new Uri("http://localhost"), 0);
18 | }
19 |
20 | [HttpPut]
21 | public IActionResult Put(IFormFile file)
22 | {
23 | return Ok();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/Client/LineProtocolWriteResult.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | namespace App.Metrics.Reporting.InfluxDB.Client
6 | {
7 | public struct LineProtocolWriteResult
8 | {
9 | public LineProtocolWriteResult(bool success)
10 | {
11 | Success = success;
12 | ErrorMessage = null;
13 | }
14 |
15 | public LineProtocolWriteResult(bool success, string errorMessage)
16 | {
17 | Success = success;
18 | ErrorMessage = errorMessage;
19 | }
20 |
21 | public string ErrorMessage { get; }
22 |
23 | public bool Success { get; }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Internal/InfluxDBFormatterConstants.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 |
7 | namespace App.Metrics.Formatters.InfluxDB.Internal
8 | {
9 | public static class InfluxDbFormatterConstants
10 | {
11 | public class LineProtocol
12 | {
13 | public static readonly Func MetricNameFormatter =
14 | (metricContext, metricName) => string.IsNullOrWhiteSpace(metricContext)
15 | ? $"{metricName}".Replace(' ', '_').ToLowerInvariant()
16 | : $"{metricContext}__{metricName}".Replace(' ', '_').ToLowerInvariant();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/SandboxMetricsRegistry.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using App.Metrics.Timer;
6 |
7 | namespace MetricsInfluxDBSandboxMvc
8 | {
9 | public static class SandboxMetricsRegistry
10 | {
11 | public const string ContextName = "Sandbox";
12 |
13 | public static readonly TimerOptions DatabaseTimer = new TimerOptions
14 | {
15 | Context = ContextName,
16 | Name = "Database Call"
17 | };
18 | }
19 | }
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:2222/",
7 | "sslPort": 0
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "launchUrl": "metrics",
15 | "environmentVariables": {
16 | "ASPNETCORE_ENVIRONMENT": "Development"
17 | }
18 | },
19 | "MetricsInfluxDBSandboxMvc": {
20 | "commandName": "Project",
21 | "launchBrowser": false,
22 | "launchUrl": "metrics",
23 | "environmentVariables": {
24 | "ASPNETCORE_ENVIRONMENT": "Development"
25 | },
26 | "applicationUrl": "http://localhost:1111"
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/MetricsInfluxDBLineProtocolOptions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using App.Metrics.Formatters.InfluxDB.Internal;
7 |
8 | namespace App.Metrics.Formatters.InfluxDB
9 | {
10 | ///
11 | /// Provides programmatic configuration for InfluxDB's LineProtocole format in the App Metrics framework.
12 | ///
13 | public class MetricsInfluxDbLineProtocolOptions
14 | {
15 | public MetricsInfluxDbLineProtocolOptions()
16 | {
17 | MetricNameFormatter = InfluxDbFormatterConstants.LineProtocol.MetricNameFormatter;
18 | }
19 |
20 | public Func MetricNameFormatter { get; set; }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Thanks for helping out :+1:
2 |
3 | Before submitting a pull request, please have a quick read through the [contribution guidlines](https://github.com/alhardy/AppMetrics/blob/master/CONTRIBUTING.md) and provide the following information, where appropriate replace the `[ ]` with a `[X]`
4 |
5 | ### The issue or feature being addressed
6 |
7 | - link to the issue/feature using it's github issue number #number (if an issue/feature does not exist, please create it first)
8 |
9 | ### Details on the issue fix or feature implementation
10 |
11 | - provide some details here
12 |
13 |
14 | ### Confirm the following
15 |
16 | - [ ] I have ensured that I have merged the latest changes from the dev branch
17 | - [ ] I have successfully run a [local build](https://github.com/alhardy/AppMetrics#how-to-build)
18 | - [ ] I have included unit tests for the issue/feature
19 | - [ ] I have included the github issue number in my commits
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/RandomExceptionController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using MetricsInfluxDBSandboxMvc.Controllers;
6 | using Microsoft.AspNetCore.Mvc;
7 |
8 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
9 | {
10 | [Route("api/[controller]")]
11 | public class RandomExceptionController : Controller
12 | {
13 | private readonly RandomValuesForTesting _randomValuesForTesting;
14 |
15 | public RandomExceptionController(RandomValuesForTesting randomValuesForTesting)
16 | {
17 | _randomValuesForTesting = randomValuesForTesting;
18 | }
19 |
20 | [HttpGet]
21 | public void Get()
22 | {
23 | throw _randomValuesForTesting.NextException();
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Reporting.InfluxDB/App.Metrics.Reporting.InfluxDB.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Provides InfluxDB reporting capability to App Metrics
5 | netstandard1.6
6 | $(TargetFrameworks);net452
7 | appmetrics;reporting;influxdb
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/RandomStatusCodeController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using MetricsInfluxDBSandboxMvc.Controllers;
6 | using Microsoft.AspNetCore.Mvc;
7 |
8 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
9 | {
10 | [Route("api/[controller]")]
11 | public class RandomStatusCodeController : Controller
12 | {
13 | private readonly RandomValuesForTesting _randomValuesForTesting;
14 |
15 | public RandomStatusCodeController(RandomValuesForTesting randomValuesForTesting)
16 | {
17 | _randomValuesForTesting = randomValuesForTesting;
18 | }
19 |
20 | [HttpGet]
21 | public IActionResult Get()
22 | {
23 | return StatusCode(_randomValuesForTesting.NextStatusCode());
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/Program.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Reflection;
7 | using App.Metrics.InfluxDB.Benchmarks.Support;
8 | using BenchmarkDotNet.Running;
9 |
10 | namespace App.Metrics.InfluxDB.Benchmarks.Runner
11 | {
12 | public class Program
13 | {
14 | public static void Main(string[] args)
15 | {
16 | ConsoleKeyInfo keyInfo;
17 |
18 | do
19 | {
20 | BenchmarkSwitcher.FromAssembly(typeof(BenchmarksAssemblyMarker).GetTypeInfo().Assembly).Run(args);
21 |
22 | Console.WriteLine("Press ESC to quit, otherwise any key to continue...");
23 |
24 | keyInfo = Console.ReadKey(true);
25 | }
26 | while (keyInfo.Key != ConsoleKey.Escape);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/RandomValuesForTesting.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Collections.Generic;
7 |
8 | namespace MetricsInfluxDBSandboxMvc.Controllers
9 | {
10 | public class RandomValuesForTesting
11 | {
12 | private static readonly List Exceptions =
13 | new List { new ArgumentException(), new ArithmeticException(), new InvalidCastException(), new NullReferenceException() };
14 |
15 | private static readonly Random Rnd = new Random();
16 | private static readonly List StatusCodes = new List { 200, 401, 401, 404, 403, 500, 500, 500 };
17 |
18 | public Func NextException => () => Exceptions[Rnd.Next(0, Exceptions.Count - 1)];
19 |
20 | public Func NextStatusCode => () => StatusCodes[Rnd.Next(0, StatusCodes.Count)];
21 | }
22 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | notifications:
2 | email:
3 | recipients:
4 | - al_hardy@live.com.au
5 |
6 | language: csharp
7 | dotnet: 2.0.0-preview1-005977
8 | os:
9 | # - osx
10 | - linux
11 | before_script:
12 | - chmod a+x ./build.sh
13 | script:
14 | - ./build.sh
15 |
16 | # .NET CLI require Ubuntu 14.04
17 | sudo: required
18 | dist: trusty
19 | env:
20 | global:
21 | - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
22 | - DOTNET_CLI_TELEMETRY_OPTOUT: 1
23 | addons:
24 | apt:
25 | packages:
26 | - gettext
27 | - libcurl4-openssl-dev
28 | - libicu-dev
29 | - libssl-dev
30 | - libunwind8
31 |
32 | # .NET CLI require OSX 10.10
33 | # osx_image: xcode7.1
34 | # before_install:
35 | # - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi
36 |
37 | mono:
38 | - 4.6.0
39 |
40 | cache:
41 | directories:
42 | - src/packages
43 | - tools
--------------------------------------------------------------------------------
/test/App.Metrics.Reporting.InfluxDB.Facts/TestClock.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Globalization;
7 |
8 | namespace App.Metrics.Reporting.InfluxDB.Facts
9 | {
10 | public sealed class TestClock : IClock
11 | {
12 | public event EventHandler Advanced;
13 |
14 | public long Nanoseconds { get; private set; }
15 |
16 | public long Seconds => TimeUnit.Nanoseconds.ToSeconds(Nanoseconds);
17 |
18 | public DateTime UtcDateTime => new DateTime(Nanoseconds / 100L, DateTimeKind.Utc);
19 |
20 | public void Advance(TimeUnit unit, long value)
21 | {
22 | Nanoseconds += unit.ToNanoseconds(value);
23 | Advanced?.Invoke(this, EventArgs.Empty);
24 | }
25 |
26 | public string FormatTimestamp(DateTime timestamp) { return timestamp.ToString("yyyy-MM-ddTHH:mm:ss.ffffK", CultureInfo.InvariantCulture); }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/test/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | netcoreapp2.1
6 | $(DeveloperBuildTest)
7 | $(StandardTest);netcoreapp2.1
8 | $(StandardTest);net461
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/RandomClientIdForTesting.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Security.Claims;
8 | using Microsoft.AspNetCore.Http;
9 |
10 | namespace MetricsInfluxDBSandboxMvc.Controllers
11 | {
12 | public static class RandomClientIdForTesting
13 | {
14 | private static readonly Random Rnd = new Random();
15 |
16 | public static void SetTheFakeClaimsPrincipal(HttpContext context)
17 | {
18 | context.User =
19 | new ClaimsPrincipal(
20 | new List
21 | {
22 | new ClaimsIdentity(
23 | new[]
24 | {
25 | new Claim("client_id", $"client-{Rnd.Next(1, 10)}")
26 | })
27 | });
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/ToleratingController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.Threading.Tasks;
6 | using MetricsInfluxDBSandboxMvc.Controllers;
7 | using Microsoft.AspNetCore.Mvc;
8 |
9 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
10 | {
11 | [Route("api/[controller]")]
12 | public class ToleratingController : Controller
13 | {
14 | private readonly RequestDurationForApdexTesting _durationForApdexTesting;
15 |
16 | public ToleratingController(RequestDurationForApdexTesting durationForApdexTesting)
17 | {
18 | _durationForApdexTesting = durationForApdexTesting;
19 | }
20 |
21 | [HttpGet]
22 | public async Task Get()
23 | {
24 | var duration = _durationForApdexTesting.NextToleratingDuration;
25 |
26 | await Task.Delay(duration, HttpContext.RequestAborted);
27 |
28 | return duration;
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/FrustratingController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.Threading.Tasks;
6 | using MetricsInfluxDBSandboxMvc.Controllers;
7 | using Microsoft.AspNetCore.Mvc;
8 |
9 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
10 | {
11 | [Route("api/[controller]")]
12 | public class FrustratingController : Controller
13 | {
14 | private readonly RequestDurationForApdexTesting _durationForApdexTesting;
15 |
16 | public FrustratingController(RequestDurationForApdexTesting durationForApdexTesting)
17 | {
18 | _durationForApdexTesting = durationForApdexTesting;
19 | }
20 |
21 | [HttpGet]
22 | public async Task Get()
23 | {
24 | var duration = _durationForApdexTesting.NextFrustratingDuration;
25 |
26 | await Task.Delay(duration, HttpContext.RequestAborted);
27 |
28 | return duration;
29 | }
30 | }
31 | }
--------------------------------------------------------------------------------
/test/App.Metrics.Reporting.InfluxDB.Facts/InfluxDBSettingsTests.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using FluentAssertions;
7 | using Xunit;
8 |
9 | namespace App.Metrics.Reporting.InfluxDB.Facts
10 | {
11 | // ReSharper disable InconsistentNaming
12 | public class InfluxDbSettingsTests
13 | // ReSharper restore InconsistentNaming
14 | {
15 | [Fact]
16 | public void Can_generate_influx_write_endpoint()
17 | {
18 | var settings = new InfluxDbOptions
19 | {
20 | Database = "testdb",
21 | BaseUri = new Uri("http://localhost"),
22 | RetentionPolicy = "defaultrp",
23 | Consistenency = "consistency"
24 | };
25 |
26 | settings.Endpoint.Should().Be("write?db=testdb&rp=defaultrp&consistency=consistency");
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Internal/ILineProtocolPoint.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.IO;
6 |
7 | namespace App.Metrics.Formatters.InfluxDB.Internal
8 | {
9 | ///
10 | /// Defines a point (a ligne), which can be written in Line Protocol format.
11 | ///
12 | internal interface ILineProtocolPoint
13 | {
14 | ///
15 | /// Write this point as a line protocol item.
16 | ///
17 | /// Text writer to write the line to.
18 | ///
19 | /// true to let the point write the timestamp by itself, false to not write the timestamp at the end of the row.
20 | /// You will have to write the timestamp by yourself of let the server receive the line and use its own timer as a timestamp.
21 | ///
22 | void Write(TextWriter textWriter, bool writeTimestamp = true);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Startup.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using Microsoft.AspNetCore.Builder;
6 | using Microsoft.AspNetCore.Hosting;
7 | using Microsoft.AspNetCore.Mvc;
8 | using Microsoft.Extensions.Configuration;
9 | using Microsoft.Extensions.DependencyInjection;
10 |
11 | namespace MetricsInfluxDBSandboxMvc
12 | {
13 | public class Startup
14 | {
15 | private const bool HaveAppRunSampleRequests = true;
16 |
17 | public Startup(IConfiguration configuration) { Configuration = configuration; }
18 |
19 | public IConfiguration Configuration { get; }
20 |
21 | public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
22 | {
23 | app.UseTestStuff(lifetime, HaveAppRunSampleRequests);
24 |
25 | app.UseMvc();
26 | }
27 |
28 | public void ConfigureServices(IServiceCollection services)
29 | {
30 | services.AddTestStuff();
31 |
32 | services.AddMvc().AddMetrics();
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks/App.Metrics.InfluxDB.Benchmarks.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | netcoreapp2.1
7 | $(TargetFrameworks);net461
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/SlaTestController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Linq;
7 | using System.Threading.Tasks;
8 | using App.Metrics;
9 | using Microsoft.AspNetCore.Mvc;
10 |
11 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
12 | {
13 | [Route("api/[controller]")]
14 | public class SlaTestController : Controller
15 | {
16 | private static readonly Random Rnd = new Random();
17 | private readonly IMetrics _metrics;
18 |
19 | public SlaTestController(IMetrics metrics) { _metrics = metrics; }
20 |
21 | [HttpGet]
22 | [Route("timer")]
23 | public async Task GetTimer()
24 | {
25 | using (_metrics.Measure.Timer.Time(SandboxMetricsRegistry.DatabaseTimer, new MetricTags("client_id", HttpContext.User.Claims.First(c => c.Type == "client_id").Value)))
26 | {
27 | await Task.Delay(Rnd.Next(350), HttpContext.RequestAborted);
28 | }
29 |
30 | return Ok();
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/App.Metrics.InfluxDB.Benchmarks.Runner.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | netcoreapp2.1
7 | $(TargetFrameworks);net461
8 | exe
9 | true
10 | true
11 | false
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "MetricsOptions": {
3 | "DefaultContextLabel": "MetricsInfluxDBSandboxMvc",
4 | "Enabled": true
5 | },
6 | "MetricsWebTrackingOptions": {
7 | "ApdexTrackingEnabled": true,
8 | "ApdexTSeconds": 0.1,
9 | "IgnoredHttpStatusCodes": [ 404 ],
10 | "IgnoredRoutesRegexPatterns": [],
11 | "OAuth2TrackingEnabled": true
12 | },
13 | "MetricEndpointsOptions": {
14 | "MetricsEndpointEnabled": true,
15 | "MetricsTextEndpointEnabled": true,
16 | "PingEndpointEnabled": true,
17 | "EnvironmentInfoEndpointEnabled": true
18 | },
19 | "MetricsReportingInfluxDbOptions": {
20 | "InfluxDb": {
21 | "BaseUri": "http://127.0.0.1:32768",
22 | "Database": "appmetricssandbox"
23 | //"Consistenency": "",
24 | //"UserName": "",
25 | //"Password": "",
26 | //"RetentionPolicy": ""
27 | },
28 | "HttpPolicy": {
29 | "BackoffPeriod": "0:0:30",
30 | "FailuresBeforeBackoff": 5,
31 | "Timeout": "0:0:40"
32 | },
33 | "ReportInterval": "0:0:1"
34 | },
35 | "Logging": {
36 | "IncludeScopes": false,
37 | "LogLevel": {
38 | "Default": "Warning"
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandbox/MetricsInfluxDBSandbox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | netcoreapp2.1;net461
7 | exe
8 | latest
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | Always
29 | PreserveNewest
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Internal/LineProtocolPoints.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Linq;
8 |
9 | namespace App.Metrics.Formatters.InfluxDB.Internal
10 | {
11 | internal class LineProtocolPoints
12 | {
13 | private readonly List _points = new List();
14 |
15 | public void Add(ILineProtocolPoint point)
16 | {
17 | if (point == null)
18 | {
19 | return;
20 | }
21 |
22 | _points.Add(point);
23 | }
24 |
25 | public void Write(TextWriter textWriter, bool writeTimestamp = true)
26 | {
27 | if (textWriter == null)
28 | {
29 | return;
30 | }
31 |
32 | var points = _points.ToList();
33 |
34 | foreach (var point in points)
35 | {
36 | point.Write(textWriter, writeTimestamp);
37 | textWriter.Write('\n');
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/RandomBufferGenerator.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 |
7 | namespace MetricsInfluxDBSandboxMvc.Controllers
8 | {
9 | public class RandomBufferGenerator
10 | {
11 | private readonly int _maxBufferSize;
12 | private readonly Random _random = new Random();
13 | private readonly byte[] _seedBuffer;
14 |
15 | public RandomBufferGenerator(int maxBufferSize)
16 | {
17 | _maxBufferSize = maxBufferSize;
18 | _seedBuffer = new byte[maxBufferSize];
19 |
20 | _random.NextBytes(_seedBuffer);
21 | }
22 |
23 | public byte[] GenerateBufferFromSeed()
24 | {
25 | var size = _random.Next(_maxBufferSize);
26 | var randomWindow = _random.Next(0, size);
27 | var buffer = new byte[size];
28 |
29 | Buffer.BlockCopy(_seedBuffer, randomWindow, buffer, 0, size - randomWindow);
30 | Buffer.BlockCopy(_seedBuffer, 0, buffer, size - randomWindow, randomWindow);
31 |
32 | return buffer;
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 1.0.{build}
2 | image: Visual Studio 2017
3 | init:
4 | - git config --global core.autocrlf input
5 | environment:
6 | COVERALLS_REPO_TOKEN:
7 | secure: OCt+hLolAEzMwIL35182sjpOu9GcwPRUkPHBsCdGSMnoIiWByMrcoDsVIqciM0C3
8 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
9 | DOTNET_CLI_TELEMETRY_OPTOUT: true
10 | CoverWith: OpenCover
11 | PreReleaseSuffix: alpha
12 | GitUser:
13 | secure: zAdAOUUof3XGDsdOBRYg7J7wZS44iL4VjI/MVGw+JnU=
14 | GitOwner:
15 | secure: n6W5JZ7Q/xfZC7b2k3+ORA==
16 | GitPassword:
17 | secure: fHangGPAk14u3V1eP3kg5EdekQoKdOsKC0F/A1mvh9IODHCZ92FGjfWb0U2aQ8bu
18 | build_script:
19 | - ps: .\build.ps1 -Target AppVeyor
20 | test: off
21 | artifacts:
22 | - path: artifacts/packages/*.nupkg
23 | - path: artifacts/coverage/*.xml
24 | - path: artifacts/test-results/*.trx
25 | - path: artifacts/resharper-reports/*.xml
26 | - path: artifacts/resharper-reports/*.html
27 | - path: artifacts/coverage/coverage.dcvr
28 | deploy:
29 | - provider: NuGet
30 | server: https://www.myget.org/F/appmetrics/api/v2/package
31 | api_key:
32 | secure: gIAiACgNj+JzXyLLTe3rLxZyrAB9RpC8Lw81xEjdOLXqotprqEwGiFWRipEqkpps
33 | skip_symbols: true
34 | symbol_server: https://www.myget.org/F/appmetrics/symbol
35 | skip_commits:
36 | files:
37 | - '**/*.md'
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/ServiceCollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using App.Metrics.AspNetCore.Tracking;
7 | using MetricsInfluxDBSandboxMvc.Controllers;
8 | using Microsoft.Extensions.Options;
9 |
10 | // ReSharper disable CheckNamespace
11 | namespace Microsoft.Extensions.DependencyInjection
12 | // ReSharper restore CheckNamespace
13 | {
14 | public static class ServiceCollectionExtensions
15 | {
16 | public static IServiceCollection AddTestStuff(this IServiceCollection services)
17 | {
18 | services.AddTransient>(
19 | serviceProvider => { return apdexTSeconds => new RequestDurationForApdexTesting(apdexTSeconds); });
20 |
21 | services.AddSingleton();
22 |
23 | services.AddTransient(
24 | serviceProvider =>
25 | {
26 | var optionsAccessor = serviceProvider.GetRequiredService>();
27 | return new RequestDurationForApdexTesting(optionsAccessor.Value.ApdexTSeconds);
28 | });
29 |
30 | return services;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System.Runtime.CompilerServices;
6 |
7 | [assembly: InternalsVisibleTo("App.Metrics.InfluxDB.Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001000961061aa9f970163db728a9792c1cfb7be51f2f986054c676345f9e43f95af5f3114b1962d10888a3ea1dff99bf56bce565f887cb4b004fc44ccb7335700260012a65b9cdd090e6b60c8c67c434ca49563c82c66695f8dc0776770bfaf481ef816767b7dd67d083960a6fcfe33c3c0e1cc198fe7a13b3283133d21b3435ebbb")]
8 | [assembly: InternalsVisibleTo("App.Metrics.Reporting.InfluxDB, PublicKey=00240000048000009400000006020000002400005253413100040000010001000961061aa9f970163db728a9792c1cfb7be51f2f986054c676345f9e43f95af5f3114b1962d10888a3ea1dff99bf56bce565f887cb4b004fc44ccb7335700260012a65b9cdd090e6b60c8c67c434ca49563c82c66695f8dc0776770bfaf481ef816767b7dd67d083960a6fcfe33c3c0e1cc198fe7a13b3283133d21b3435ebbb")]
9 | [assembly: InternalsVisibleTo("App.Metrics.Reporting.InfluxDB.Facts, PublicKey=00240000048000009400000006020000002400005253413100040000010001000961061aa9f970163db728a9792c1cfb7be51f2f986054c676345f9e43f95af5f3114b1962d10888a3ea1dff99bf56bce565f887cb4b004fc44ccb7335700260012a65b9cdd090e6b60c8c67c434ca49563c82c66695f8dc0776770bfaf481ef816767b7dd67d083960a6fcfe33c3c0e1cc198fe7a13b3283133d21b3435ebbb")]
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/MetricsInfluxDBSandboxMvc.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | exe
7 | netcoreapp2.1;net461
8 | latest
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | Always
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Registry.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using App.Metrics;
6 | using App.Metrics.Histogram;
7 |
8 | namespace MetricsInfluxDBSandboxMvc
9 | {
10 | public static class Registry
11 | {
12 | #pragma warning disable SA1401 // Fields must be private
13 |
14 | public static HistogramOptions One = new HistogramOptions
15 | {
16 | Name = "test1",
17 | MeasurementUnit = Unit.Bytes,
18 | Context = "test"
19 | };
20 |
21 | public static HistogramOptions Three = new HistogramOptions
22 | {
23 | Name = "test3",
24 | MeasurementUnit = Unit.Bytes,
25 | Context = "test"
26 | };
27 |
28 | public static HistogramOptions Two = new HistogramOptions
29 | {
30 | Name = "test2",
31 | MeasurementUnit = Unit.Bytes,
32 | Context = "test"
33 | };
34 | #pragma warning restore SA1401 // Fields must be private
35 | }
36 | }
--------------------------------------------------------------------------------
/benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/BenchmarkDotNet.Artifacts/results/App.Metrics.InfluxDB.Benchmarks.BenchmarkDotNetBenchmarks.Formatters.MetricSnapshotInfluxDbLineProtocolWriterBenchmark-report-github.md:
--------------------------------------------------------------------------------
1 | ``` ini
2 |
3 | BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17763.292 (1809/October2018Update/Redstone5)
4 | Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
5 | .NET Core SDK=2.1.301
6 | [Host] : .NET Core 2.1.7 (CoreCLR 4.6.27129.04, CoreFX 4.6.27129.04), 64bit RyuJIT
7 | Core : .NET Core 2.1.7 (CoreCLR 4.6.27129.04, CoreFX 4.6.27129.04), 64bit RyuJIT
8 |
9 | Job=Core Runtime=Core
10 |
11 | ```
12 | | Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen 0/1k Op | Gen 1/1k Op | Gen 2/1k Op | Allocated Memory/Op |
13 | |-------------------------------- |---------:|----------:|----------:|---------:|------:|--------:|------------:|------------:|------------:|--------------------:|
14 | | WriteSingleValuePoint_Legacy | 558.0 ns | 11.067 ns | 25.206 ns | 549.2 ns | 1.00 | 0.00 | 0.1478 | - | - | 624 B |
15 | | WriteSingleValuePoint | 288.3 ns | 5.704 ns | 8.881 ns | 286.4 ns | 0.51 | 0.03 | 0.0725 | - | - | 304 B |
16 | | | | | | | | | | | | |
17 | | WriteMultipleValuesPoint_Legacy | 991.9 ns | 19.413 ns | 31.348 ns | 984.6 ns | 1.00 | 0.00 | 0.2012 | - | - | 848 B |
18 | | WriteMultipleValuesPoint | 352.8 ns | 6.631 ns | 6.202 ns | 353.1 ns | 0.36 | 0.01 | 0.0873 | - | - | 368 B |
19 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/SimpleConsoleMetricsReporter.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.IO;
7 | using System.Text;
8 | using System.Threading;
9 | using System.Threading.Tasks;
10 | using App.Metrics;
11 | using App.Metrics.Filters;
12 | using App.Metrics.Formatters;
13 | using App.Metrics.Formatters.Ascii;
14 | using App.Metrics.Reporting;
15 |
16 | namespace MetricsInfluxDBSandboxMvc.Controllers
17 | {
18 | public class SimpleConsoleMetricsReporter : IReportMetrics
19 | {
20 | private readonly IMetricsOutputFormatter _defaultMetricsOutputFormatter = new MetricsTextOutputFormatter();
21 |
22 | ///
23 | public IFilterMetrics Filter { get; set; }
24 |
25 | ///
26 | public TimeSpan FlushInterval { get; set; }
27 |
28 | ///
29 | public IMetricsOutputFormatter Formatter { get; set; }
30 |
31 | ///
32 | public async Task FlushAsync(MetricsDataValueSource metricsData, CancellationToken cancellationToken = default)
33 | {
34 | Console.WriteLine("Metrics Report");
35 | Console.WriteLine("-------------------------------------------");
36 |
37 | using (var stream = new MemoryStream())
38 | {
39 | await _defaultMetricsOutputFormatter.WriteAsync(stream, metricsData, cancellationToken);
40 |
41 | var output = Encoding.UTF8.GetString(stream.ToArray());
42 |
43 | Console.WriteLine(output);
44 | }
45 |
46 | return true;
47 | }
48 | }
49 | }
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/JustForTesting/SatisfyingController.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Linq;
7 | using System.Threading.Tasks;
8 | using App.Metrics;
9 | using MetricsInfluxDBSandboxMvc.Controllers;
10 | using Microsoft.AspNetCore.Mvc;
11 |
12 | namespace MetricsInfluxDBSandboxMvc.JustForTesting
13 | {
14 | [Route("api/[controller]")]
15 | public class SatisfyingController : Controller
16 | {
17 | private readonly RequestDurationForApdexTesting _durationForApdexTesting;
18 |
19 | public static Random Rnd { get; } = new Random();
20 |
21 | private readonly IMetrics _metrics;
22 |
23 | public SatisfyingController(IMetrics metrics, RequestDurationForApdexTesting durationForApdexTesting)
24 | {
25 | _metrics = metrics ?? throw new ArgumentNullException(nameof(metrics));
26 | _durationForApdexTesting = durationForApdexTesting;
27 | }
28 |
29 | [HttpGet]
30 | public async Task Get()
31 | {
32 | var duration = _durationForApdexTesting.NextSatisfiedDuration;
33 |
34 | foreach (var i in Enumerable.Range(1, 3))
35 | {
36 | var tags = new MetricTags($"key{i}", $"value{i}");
37 |
38 | _metrics.Measure.Histogram.Update(Registry.One, tags, Rnd.Next(1, 500));
39 | _metrics.Measure.Histogram.Update(Registry.Two, tags, Rnd.Next(1, 500));
40 | _metrics.Measure.Histogram.Update(Registry.Three, tags, Rnd.Next(1, 500));
41 | }
42 |
43 | await Task.Delay(duration, HttpContext.RequestAborted);
44 |
45 | return duration;
46 | }
47 | }
48 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #OS junk files
2 | [Tt]humbs.db
3 | *.DS_Store
4 | *.orig
5 |
6 | #Visual Studio files
7 | *.[Oo]bj
8 | *.user
9 | *.aps
10 | *.pch
11 | *.vspscc
12 | *.vssscc
13 | *_i.c
14 | *_p.c
15 | *.ncb
16 | *.suo
17 | *.tlb
18 | *.tlh
19 | *.bak
20 | *.[Cc]ache
21 | *.ilk
22 | *.log
23 | *.lib
24 | *.sbr
25 | *.sdf
26 | *.opensdf
27 | *.unsuccessfulbuild
28 | ipch/
29 | [Oo]bj/
30 | [Bb]in
31 | Ankh.NoLoad
32 | *.vsmdi
33 | *.lock.json
34 |
35 | #Tooling
36 | .idea
37 | _ReSharper*/
38 | *.resharper
39 | [Tt]est[Rr]esult*
40 | *.sass-cache
41 |
42 | #Subversion files
43 | .svn
44 |
45 | # Office Temp Files
46 | ~$*
47 |
48 | #ncrunch
49 | *ncrunch*
50 | *crunch*.local.xml
51 |
52 | #Test files
53 | *.testsettings
54 |
55 | #Build
56 | BuildOutput
57 | BuildOutput/*
58 | WebPublish
59 | WebPublish/*
60 |
61 | #Cake
62 | tools/*
63 | !tools/packages.config
64 |
65 | .vs
66 |
67 | # visual studio database projects
68 | *.dbmdl
69 | logs/*
70 | .vs/*
71 | *.project.lock.json
72 |
73 | #Temp folders
74 | temp/
75 |
76 | #Tools and packages
77 | .nuget
78 | .nuget/*
79 | artifacts
80 | artifacts/*
81 | packages
82 | packages/*
83 | *.lock.json
84 |
85 | #BenchMarkDotNet
86 | BDN.Generated
87 | BDN.Generated/*
88 | scripts/BenchMarkDotNet.Artifacts
89 | scripts/BenchMarkDotNet.Artifacts/*
90 | **/BenchMarkDotNet.Artifacts/*
91 | !/benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/BenchMarkDotNet.Artifacts/*
92 | /benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/BenchMarkDotNet.Artifacts/*.log
93 | /benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/BenchMarkDotNet.Artifacts/results/*.csv
94 | /benchmarks/App.Metrics.InfluxDB.Benchmarks.Runner/BenchMarkDotNet.Artifacts/results/*.html
95 |
96 | #NDepend
97 | *.ndproj
98 | NDependOut/*
99 |
100 | #DotCover
101 | Session/*
102 | Session.html
103 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandboxMvc/Controllers/RequestDurationForApdexTesting.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 |
7 | namespace MetricsInfluxDBSandboxMvc.Controllers
8 | {
9 | public class RequestDurationForApdexTesting
10 | {
11 | private const int MaxRequestDurationFactor = 1000;
12 | private const int MinRequestDuration = 25;
13 | private static readonly Random Rnd = new Random();
14 |
15 | public RequestDurationForApdexTesting(double apdexTSeconds)
16 | {
17 | SatisfiedMinMilliseconds = MinRequestDuration;
18 | SatisfiedMaxMilliseconds = (int)(apdexTSeconds * 1000);
19 |
20 | ToleratingMinMilliseconds = SatisfiedMaxMilliseconds + 1;
21 | ToleratingMaxMilliseconds = 4 * SatisfiedMaxMilliseconds;
22 |
23 | FrustratingMinMilliseconds = ToleratingMaxMilliseconds + 1;
24 | FrustratingMaxMilliseconds = ToleratingMaxMilliseconds + MaxRequestDurationFactor;
25 | }
26 |
27 | public int FrustratingMaxMilliseconds { get; }
28 |
29 | public int FrustratingMinMilliseconds { get; }
30 |
31 | public int NextFrustratingDuration => Rnd.Next(FrustratingMinMilliseconds, FrustratingMaxMilliseconds);
32 |
33 | public int NextSatisfiedDuration => Rnd.Next(SatisfiedMinMilliseconds, SatisfiedMaxMilliseconds);
34 |
35 | public int NextToleratingDuration => Rnd.Next(ToleratingMinMilliseconds, ToleratingMaxMilliseconds);
36 |
37 | public int SatisfiedMaxMilliseconds { get; }
38 |
39 | public int SatisfiedMinMilliseconds { get; }
40 |
41 | public int ToleratingMaxMilliseconds { get; }
42 |
43 | public int ToleratingMinMilliseconds { get; }
44 | }
45 | }
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Internal/LineProtocolPointSingleValue.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.IO;
7 |
8 | namespace App.Metrics.Formatters.InfluxDB.Internal
9 | {
10 | ///
11 | /// Represents a line protocol point with a single field.
12 | ///
13 | internal class LineProtocolPointSingleValue : LineProtocolPointBase, ILineProtocolPoint
14 | {
15 | public LineProtocolPointSingleValue(
16 | string measurement,
17 | string fieldName,
18 | object fieldValue,
19 | MetricTags tags,
20 | DateTime? utcTimestamp = null)
21 | : base(measurement, tags, utcTimestamp)
22 | {
23 | if (string.IsNullOrEmpty(fieldName))
24 | {
25 | throw new ArgumentException("Field name must be specified and be non-empty");
26 | }
27 |
28 | FieldName = fieldName;
29 | FieldValue = fieldValue;
30 | }
31 |
32 | public string FieldName { get; }
33 |
34 | public object FieldValue { get; }
35 |
36 | public void Write(TextWriter textWriter, bool writeTimestamp = true)
37 | {
38 | if (textWriter == null)
39 | {
40 | throw new ArgumentNullException(nameof(textWriter));
41 | }
42 |
43 | WriteCommon(textWriter);
44 |
45 | textWriter.Write(' ');
46 | textWriter.Write(LineProtocolSyntax.EscapeName(FieldName));
47 | textWriter.Write('=');
48 | textWriter.Write(LineProtocolSyntax.FormatValue(FieldValue));
49 |
50 | if (!writeTimestamp)
51 | {
52 | return;
53 | }
54 |
55 | WriteTimestamp(textWriter);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/sandbox/MetricsInfluxDBSandbox/ApplicationsMetricsRegistry.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using App.Metrics.Apdex;
6 | using App.Metrics.Counter;
7 | using App.Metrics.Gauge;
8 | using App.Metrics.Histogram;
9 | using App.Metrics.Meter;
10 | using App.Metrics.Timer;
11 |
12 | namespace MetricsInfluxDBSandbox
13 | {
14 | public static class ApplicationsMetricsRegistry
15 | {
16 | public static ApdexOptions ApdexOne => new ApdexOptions
17 | {
18 | Name = "apdex_one"
19 | };
20 |
21 | public static CounterOptions CounterOne => new CounterOptions
22 | {
23 | Name = "counter_one"
24 | };
25 |
26 | public static GaugeOptions GaugeOne => new GaugeOptions
27 | {
28 | Name = "gauge_one"
29 | };
30 |
31 | public static HistogramOptions HistogramOne => new HistogramOptions
32 | {
33 | Name = "histogram_one"
34 | };
35 |
36 | public static MeterOptions MeterOne => new MeterOptions
37 | {
38 | Name = "meter_one"
39 | };
40 |
41 | public static TimerOptions TimerOne => new TimerOptions
42 | {
43 | Name = "timer_one"
44 | };
45 | }
46 | }
--------------------------------------------------------------------------------
/test/App.Metrics.Reporting.InfluxDB.Facts/LineProtocolSyntaxTests.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using App.Metrics.Formatters.InfluxDB.Internal;
7 | using FluentAssertions;
8 | using Xunit;
9 |
10 | namespace App.Metrics.Reporting.InfluxDB.Facts
11 | {
12 | public class LineProtocolSyntaxTests
13 | {
14 | [Theory]
15 | [InlineData("test=", "test\\=")]
16 | [InlineData("test ", "test\\ ")]
17 | [InlineData("test,", "test\\,")]
18 | [InlineData("te=st", "te\\=st")]
19 | [InlineData("te st", "te\\ st")]
20 | [InlineData("te,st", "te\\,st")]
21 | public void Can_escape_name(string nameOrKey, string expected)
22 | {
23 | LineProtocolSyntax.EscapeName(nameOrKey).Should().Be(expected);
24 | }
25 |
26 | [Fact]
27 | public void Can_format_timespan()
28 | {
29 | var value = TimeSpan.FromMinutes(1);
30 |
31 | LineProtocolSyntax.FormatValue(value).Should().Be("60000");
32 | }
33 |
34 | [Fact]
35 | public void Can_format_timestamp()
36 | {
37 | var dateTime = new DateTime(2017, 01, 01, 1, 1, 1, DateTimeKind.Utc);
38 | LineProtocolSyntax.FormatTimestamp(dateTime).Should().Be("1483232461000000000");
39 | }
40 |
41 | [Theory]
42 | [InlineData(1, "1i")]
43 | [InlineData((sbyte)1, "1i")]
44 | [InlineData((byte)1, "1i")]
45 | [InlineData((short)1, "1i")]
46 | [InlineData((ushort)1, "1i")]
47 | [InlineData((uint)1, "1i")]
48 | [InlineData((long)1, "1i")]
49 | [InlineData((ulong)1, "1i")]
50 | [InlineData((float)1, "1")]
51 | [InlineData((double)1, "1")]
52 | [InlineData(true, "t")]
53 | [InlineData(false, "f")]
54 | public void Can_format_value(object value, string expected)
55 | {
56 | LineProtocolSyntax.FormatValue(value).Should().Be(expected);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/test/App.Metrics.Reporting.InfluxDB.Facts/RetentionPolicyOptionsTests.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using Xunit;
7 |
8 | namespace App.Metrics.Reporting.InfluxDB.Facts
9 | {
10 | public class RetentionPolicyOptionsTests
11 | {
12 | [Fact]
13 | public void TryApplyDefaultRetentionPolicy()
14 | {
15 | RetentionPolicyOptions options = new RetentionPolicyOptions();
16 |
17 | bool result = options.TryApply(out var clause);
18 |
19 | Assert.False(result);
20 | Assert.Null(clause);
21 | }
22 |
23 | [Theory]
24 | [InlineData(null,null,null,null,false,null)]
25 | [InlineData(65, null, null, null, true, "WITH DURATION 65m")]
26 | [InlineData(null, 3, null, null, true, "WITH REPLICATION 3")]
27 | [InlineData(null, null, 60, null, true, "WITH SHARD DURATION 60m")]
28 | [InlineData(null, null, null, "any Name", true, "WITH NAME \"any%20Name\"")]
29 | [InlineData(65, 3, 60, "any Name", true, "WITH DURATION 65m REPLICATION 3 SHARD DURATION 60m NAME \"any%20Name\"")]
30 |
31 | public void TryApplyRetentionPolicy(
32 | int? duration,
33 | int? replication,
34 | int? shardDuration,
35 | string name,
36 | bool expected,
37 | string expectedClause)
38 | {
39 | RetentionPolicyOptions options =
40 | new RetentionPolicyOptions
41 | {
42 | Name = name,
43 | Duration = duration.HasValue ? TimeSpan.FromMinutes(duration.Value) : (TimeSpan?)null ,
44 | Replication = replication,
45 | ShardDuration = shardDuration.HasValue ? TimeSpan.FromMinutes(shardDuration.Value) : (TimeSpan?)null
46 | };
47 |
48 | bool result = options.TryApply(out var clause);
49 |
50 | Assert.Equal(expected, result);
51 | Assert.Equal(expectedClause, clause);
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/src/App.Metrics.Formatters.InfluxDB/Internal/LineProtocolPointMultipleValues.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright (c) App Metrics Contributors. All rights reserved.
3 | //
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.IO;
8 | using System.Linq;
9 |
10 | namespace App.Metrics.Formatters.InfluxDB.Internal
11 | {
12 | ///
13 | /// Represents a line procol point with multiple fields.
14 | ///
15 | internal class LineProtocolPointMultipleValues : LineProtocolPointBase, ILineProtocolPoint
16 | {
17 | public LineProtocolPointMultipleValues(
18 | string measurement,
19 | IEnumerable fieldsNames,
20 | IEnumerable