GithubHelp home page GithubHelp logo

Comments (1)

gabriellima09 avatar gabriellima09 commented on September 26, 2024

Solved by using the following configs:

Program.cs

using App.Metrics;
using App.Metrics.AspNetCore;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseKestrel(options => 
{
   options.AllowSynchronousIO = true;
});

builder.Services
    .AddControllers()
    .AddMetrics();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
    
builder.Services.AddAppMetricsHealthPublishing();
builder.Services.AddAppMetricsSystemMetricsCollector();

builder.Host
        .ConfigureMetricsWithDefaults(builder =>
                {
                    builder.Report.ToInfluxDb(options =>
                    {
                        options.InfluxDb.Database = "demo";
                        options.InfluxDb.BaseUri = new Uri("http://127.0.0.1:8086");
                        options.InfluxDb.UserName = "user";
                        options.InfluxDb.Password = "123";
                        options.InfluxDb.CreateDataBaseIfNotExists = true;
                        options.FlushInterval = TimeSpan.FromSeconds(5);
                    });
                })
            .UseMetrics();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.MapControllers();

app.UseMetricsAllEndpoints();
app.UseMetricsAllMiddleware();

app.Run();

.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>MyProject</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="App.Metrics.AspNetCore.All" Version="4.2.0" />
    <PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="4.2.0" />
    <PackageReference Include="App.Metrics.Graphite" Version="4.2.0" />
    <PackageReference Include="App.Metrics.InfluxDB" Version="4.2.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
  </ItemGroup>

</Project>

docker-compose.yml

version: '3'
services:

  influxdb:
    image: influxdb:1.8
    container_name: influxdb
    restart: always
    ports:
    - 8086:8086
    environment:
    - INFLUXDB_DB=demo
    - INFLUXDB_USER=user
    - INFLUXDB_ADMIN_ENABLED=true
    - INFLUXDB_ADMIN_USER=admin
    - INFLUXDB_ADMIN_PASSWORD=123
    volumes:
    - influxdb:/var/lib/influxdb

  grafana:
    container_name: "grafana"
    image: "grafana/grafana:latest"
    restart: always
    ports:
    - 3000:3000
    volumes:
    - grafana:/var/lib/grafana

volumes:
  influxdb:
  grafana:

OBS: On Grafana datasource config you use the container_name to set it up and on dotnet app use the localhost IP 127.0.0.1

from appmetrics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.