GithubHelp home page GithubHelp logo

direkshan-digital / aspnet-monitoring Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dockersamples/aspnet-monitoring

0.0 1.0 0.0 462 KB

Monitoring ASP.NET Fx applications in Windows Docker containers, using Prometheus

License: Apache License 2.0

C# 10.00% ASP 1.81% CSS 0.31% JavaScript 87.89%

aspnet-monitoring's Introduction

ASP.NET Monitoring

Monitoring ASP.NET Framework applications in Windows Docker containers, using Prometheus.

This sample app shows you how to export Windows and .NET Performance Counters from a Docker Windows container, run Prometheus in a Docker Windows container, and use Prometheus to monitor the ASP.NET web container:

Prometheus in a Docker Windows container

The screenshot shows a graph of the Requests / Sec IIS performance counter values, which are exported from the web container and scraped by the Prometheus container.

There are three parts to the sample:

  • exporter - a console app which publishes performance counter metrics
  • website - a WebForms app which uses the exporter
  • prometheus - the Prometheus server which stores metrics

Exporter

A .NET Framework console app which uses prometheus-net to collect performance counter metrics and expose them in a Prometheus-formatted endpoint. The exporter app adds a new set of metrics collectors which can be configured at runtime - e.g. in w3svc-collectors.json:

{
  "PerformanceCounterCollectors": [
    {
      "CategoryName": ".NET CLR Memory",
      "InstanceName": "_Global_",
      "CounterNames": [
        "Gen 0 heap size",
...

The console app is packaged in the dockersamples/aspnet-monitoring-exporter Docker image for easy distribution, but it is not meant to be used on its own. It can be packaged into your own .NET application image to export metrics without having to change your app.

Website

A sample ASP.NET WebForms website which is packaged with the exporter app. In the Dockerfile the exporter app is installed from the exporter image:

FROM dockersamples/aspnet-monitoring-exporter AS exporter
...
WORKDIR C:\aspnet-exporter
COPY --from=exporter C:\aspnet-exporter .
ENV COLLECTOR_CONFIG_PATH="w3svc-collectors.json"

That copies the exporter app binaries into the website image, and sepcifyies the config file to use - this example collects basic .NET and IIS Performance Counters.

In the startup configuration for the image, the exporter app is started in the background:

ENTRYPOINT ["powershell"]

CMD Start-Service W3SVC; `
    Invoke-WebRequest http://localhost:8090 -UseBasicParsing | Out-Null; `
    Start-Process -NoNewWindow C:\aspnet-exporter\aspnet-exporter.exe; `
    C:\ServiceMonitor.exe w3sv

When a container is run from the website image, the metrics are exposed on port 50505. That port isn't publicly exposed, so only other Docker containers in the same network can access it.

Prometheus

This packages Prometheus to run in a Docker Windows container, based on the work by Docker Captain Stefan Scherer in stefanscherer/prometheus-windows. The Dockerfile deploys Prometheus and sets some default configuration values. When you run a container from this image, you can browse to the Prometheus UI on port 9090.

Usage

Run docker-compose up -d from this directory, and that will start the web and Prometheus containers. You can browse to the website container running locally by opening the IP address with PowerShell:

$webIp = docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' aspnetmonitoring_web_1
start "http://$webIp"

Refresh the page a few times and then browse to the Prometheus container:

$promIp = docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' aspnetmonitoring_prometheus_1
start "http://$($promIp):9090"

You'll see the Prometheus UI, with all the metrics listed. These are scraped from the performance counters in the web container.

aspnet-monitoring's People

Contributors

sixeyed avatar

Watchers

James Cloos avatar

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.