设置Prometheus Operator监视.net核心应用 [英] Setup Prometheus Operator to monitor .net core app

查看:258
本文介绍了设置Prometheus Operator监视.net核心应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的kubernetes开发集群上成功设置了prometheus和grafana(以下操作:





已安装.net仪表板,但未显示任何结果:





要从中抓取结果,我该怎么办我的应用 buygroup?



服务Yaml:

  apiVersion: v1 
类型:服务
元数据:
名称:buygroup
标签:
名称:buygroup
规范:
类型:NodePort
选择器:
app.kubernetes.io/实例:buygroup
app.kubernetes.io/名称:buygroup
端口:
-名称:http
端口:80
nodePort:30601
targetPort:http

服务监视器:

  api版本:Monitoring.coreos.com/v1 
类型:ServiceMonitor
元数据:
名称:Monitoring-团购
名称空间:监视
标签:
应用程序:buygroup
规范:
选择器:
matchLabels:
#目标应用服务
应用程序:buygroup
端点:$ b​​ $ b-间隔:15s
路径:/ metrics
端口:http
namespace选择器:
matchNames:
-buygroup-命名空间


解决方案

我知道了:



ServiceMonitor:

  apiVersion:monitoring.coreos.com/v1 
类型:ServiceMonitor
元数据:
名称:prometheus-operator-buygroup
命名空间:监视
标签:
应用程序:prometheus-operator-buygroup
版本:prometheus-operator
规范:
选择器:
matchLabel:
#目标应用程序服务
app.kubernetes.io/实例:buygroup
应用程序.kubernetes.io /名称:buygroup
端点:$ b​​ $ b-间隔:15s
路径:/ metrics
端口:http
na mespaceSelector:
任意:true

服务:

  api版本:v1 
类型:服务
元数据:
名称:prometheus-operator-buygroup
标签:
应用程序:buygroup
app.kubernetes.io/实例:buygroup
app.kubernetes.io/名称:buygroup
规格:
类型:ClusterIP
端口:
-名称:http
协议:TCP
端口:80
目标端口:http
选择器:
应用程序:buygroup
app.kubernetes.io/实例:buygroup
app.kubernetes.io/名称:buygroup


I have successfully setup prometheus and grafana on my kubernetes dev cluster (following this: https://itnext.io/kubernetes-monitoring-with-prometheus-in-15-minutes-8e54d1de2e13).

Added this to Startup.cs for my sample .net core app:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        var counter = Metrics.CreateCounter("PathCounter", "Counts requests to endpoints", new CounterConfiguration
        {
            LabelNames = new[] { "method", "endpoint" }
        });
        app.Use((context, next) =>
        {
            counter.WithLabels(context.Request.Method, context.Request.Path).Inc();
            return next();
        });
        app.UseMetricServer();

Should I specify anything for app.UseMetricServer(HERE?);

I've applied this yaml to add my app to be scraped:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: buygroup
  labels:
    app: buygroup
    release: prom
spec:
  namespaceSelector:
    any: true
  selector:
    matchLabels:
      app: buygroup
  endpoints:
  - port: web
    interval: 10s

I don't see anything collected in Targets under: http://localhost:9090/targets

Installed .net dashboard but shows no results:

What do I have to do to have results scraped from my app "buygroup"?

Service yaml:

apiVersion: v1
kind: Service
metadata:
  name: buygroup
  labels:
    name: buygroup
spec:
  type: NodePort
  selector:
    app.kubernetes.io/instance: buygroup
    app.kubernetes.io/name: buygroup
  ports:
  - name: http
    port: 80
    nodePort: 30601
    targetPort: http

Service Monitor:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: monitoring-buygroup
  namespace: monitoring
  labels:
    app: buygroup
spec:
  selector:
    matchLabels:
      # Target app service
      app: buygroup
  endpoints:
  - interval: 15s
    path: /metrics
    port: http
  namespaceSelector:
    matchNames:
    - buygroup-namespace

解决方案

I figured it out:

ServiceMonitor:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: prometheus-operator-buygroup
  namespace: monitoring
  labels:
    app: prometheus-operator-buygroup
    release: prometheus-operator
spec:
  selector:
    matchLabels:
      # Target app service
      app.kubernetes.io/instance: buygroup
      app.kubernetes.io/name: buygroup
  endpoints:
  - interval: 15s
    path: /metrics
    port: http
  namespaceSelector:
    any: true

Service:

apiVersion: v1
kind: Service
metadata:
  name: prometheus-operator-buygroup
  labels:
    app: buygroup
    app.kubernetes.io/instance: buygroup
    app.kubernetes.io/name: buygroup
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: http
  selector:
    app: buygroup
    app.kubernetes.io/instance: buygroup
    app.kubernetes.io/name: buygroup

这篇关于设置Prometheus Operator监视.net核心应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆