Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster ASP.Net Core implementation of Exporter Prometheus #124

Closed
ysma500 opened this issue Jun 26, 2019 · 2 comments
Closed

Faster ASP.Net Core implementation of Exporter Prometheus #124

ysma500 opened this issue Jun 26, 2019 · 2 comments
Labels
pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package

Comments

@ysma500
Copy link
Contributor

ysma500 commented Jun 26, 2019

As a dev using ASP.Net Core MVC, I mainly use the file appsettings.json to assign different settings. We could use that file to do the heavy lifting of setting-up Prometheus Exporter.
Instead of using this method to init the Exporter:

        private TagKey CodeKey;
        private TagKey RouteKey;
        private IMeasureLong ReqMeasure;
        private IStatsRecorder statsRecorder;
        public RequestMetrics(int httpServerPort=8080)
        {
            CodeKey = TagKey.Create("status_code");
            RouteKey = TagKey.Create("route");
            // Metric type: name, description, unit
            ReqMeasure = MeasureLong.Create("measures_requests", "counter of requests", "req");
            IViewName ReqViewName = ViewName.Create("views_requests_total");
            // Counter type, default to 0 at start if wo/params
            IAggregation ReqViewType = Count.Create();
            // Build view: (IViewName name, string description, IMeasure measure, IAggregation aggregation, IReadOnlyList<ITagKey> columns)
            IView RequestView = View.Create(
                ReqViewName,
                " requests made over time",
                ReqMeasure,
                ReqViewType,
                new List<TagKey>() { RouteKey, CodeKey });

            statsRecorder = Stats.StatsRecorder;
            IViewManager viewManager = Stats.ViewManager;
            viewManager.RegisterView(RequestView);
            var exporter = new PrometheusExporter(
            new PrometheusExporterOptions()
            {
                Url = String.Format("http://+:{0}/metrics/", httpServerPort.ToString())
            },
            viewManager);

            // Starting of the prometheus provider (http server)
            exporter.Start();

        }

We could promote something like this:

"PrometheusExporterOptions": {
    "Hostname": "+",
    "ListenOnPort": "8080",
    "Path": "/",
    "AppName": [ "metrics" ],
    "Views": [
      {
        "Name": "views_requests_total",
        "Description": " requests made over time",
        "Measure": {
          "Name": "measures_requests",
          "Description": "counter of requests",
          "Unit": "req",
          "Type": "long"
        },
        "Type": "Count",
        "Tags": [
          {
            "Name": "status_code",
            "Type": "int"
          },
          {
            "Name": "route",
            "Type": "string"
          }
        ]
      }
    ]
  },

If you are interested, I could work on the parsing of the appsettings file. My json file structure might not be optimal, comments are welcomed. The only risk from this implementation is to make sure to not duplicate TagKeys considering they're declared in each of the "Views" themself.

@AlexeiScherbakov
Copy link

Something like:
services.Configure(configuration.GetSection("PrometheusExporterOptions"));

then this will be avaliable via IOptions<>

Related issue - #101

@SergeyKanzhelev SergeyKanzhelev added the pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package label Oct 28, 2019
@SergeyKanzhelev SergeyKanzhelev added this to the v0.3 milestone Oct 28, 2019
@cijothomas
Copy link
Member

Closing this issue as the stats based exporter is removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package
Projects
None yet
Development

No branches or pull requests

4 participants