当前位置: 首页 > article >正文

opentelemetry-collector docker安装

一、编写配置

nano /root/otelcol-config.yaml
==================================================
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
      http:
        endpoint: 0.0.0.0:4318
exporters:
  debug:
    verbosity: detailed
service:
  pipelines:
    traces:
      receivers: [otlp]
      exporters: [debug]
    metrics:
      receivers: [otlp]
      exporters: [debug]
    logs:
      receivers: [otlp]
      exporters: [debug]
==================================================

 启动

docker run -d --name opentelemetry-collector -v /root/otelcol-config.yaml:/etc/otelcol-contrib/config.yaml -p 1888:1888 -p 8888:8888 -p 8889:8889 -p 13133:13133 -p 4317:4317 -p 4318:4318 -p 55679:55679 otel/opentelemetry-collector-contrib:0.117.0

4317:4317 # OTLP gRPC receiver
4318:4318 # OTLP http receiver

编写C#客户端向collector 发送数据

安装包:

<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />

Program.cs

#region OpenTelemetry

...相关代码

#end

using OpenTelemetry.Exporter;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;


var builder = WebApplication.CreateBuilder(args);

#region OpenTelemetry
var serviceName = "demoA";
var serviceVersion = "1.0.0";

builder.Services.AddOpenTelemetry()
    .ConfigureResource(resource => resource.AddService(
        serviceName: serviceName,
        serviceVersion: serviceVersion))
    .WithTracing(tracing => tracing
        .AddSource(serviceName)
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("http://192.168.31.160:4318/v1/traces");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        }))
    .WithMetrics(metrics => metrics
        .AddMeter(serviceName)
        .AddOtlpExporter(options =>
        {
            options.Endpoint = new Uri("http://192.168.31.160:4318/v1/metrics");
            options.Protocol = OtlpExportProtocol.HttpProtobuf;
        }));

builder.Logging.AddOpenTelemetry(options => options
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(
        serviceName: serviceName,
        serviceVersion: serviceVersion))
    .AddOtlpExporter(options =>
    {
        options.Endpoint = new Uri("http://192.168.31.160:4318/v1/logs");
        options.Protocol = OtlpExportProtocol.HttpProtobuf;
    }));
#endregion

// Add services to the container.
builder.Services.AddHttpClient();

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

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseAuthorization();

app.MapControllers();

app.Run();

opentelemetry-collector容器输出:


http://www.kler.cn/a/510509.html

相关文章:

  • 基于springboot的口腔管理平台
  • 蓝桥杯备考:堆和priority queue(优先级队列)
  • 天机学堂5-XxlJobRedis
  • 1.6 从 GPT-1 到 GPT-3.5:一路的风云变幻
  • OODA循环在网络安全运营平台建设中的应用
  • 【原创】大数据治理入门(2)《提升数据质量:质量评估与改进策略》入门必看 高赞实用
  • 游戏引擎学习第84天
  • Linux stress-ng命令解读
  • vue 学习笔记 - 创建第一个项目 idea
  • 合并两个有序数组(88)合并两个有序链表(21)
  • 大模型UI:Gradio全解11——Chatbot:融合大模型的聊天机器人(4)
  • 第34天:Web开发-PHP应用鉴别修复AI算法流量检测PHP.INI通用过滤内置函数
  • 《weak_ptr源码剖析》
  • 在K8S中,业务Pod数据如何存储?
  • JavaScript系列(32)-- WebAssembly集成详解
  • 数据库高可用方案-08-多版本管理
  • owasp SQL 注入-03 (原理)
  • Python爬虫-爱奇艺电视剧数据
  • Redis的部署和操作
  • 基于poll函数实现并发处理
  • 联合体(Union)
  • 根据现代业务需求设计数据架构(三)- 数据网格(Data Mesh)
  • 数据结构 数组
  • 团体程序设计天梯赛-练习集——L1-012 计算指数
  • Netty中的NioEventloop(1)
  • vue基础代码第一篇