设置 Prometheus Operator 以监控 .net 核心应用程序
Setup Prometheus Operator to monitor .net core app
我已经在我的 kubernetes 开发集群上成功设置了 prometheus 和 grafana(如下所示:https://itnext.io/kubernetes-monitoring-with-prometheus-in-15-minutes-8e54d1de2e13)。
为我的示例 .net 核心应用程序将此添加到 Startup.cs:
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();
我应该为 app.UseMetricServer(此处?)指定任何内容吗?
我已经应用此 yaml 来添加我要抓取的应用程序:
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
我没有在目标中看到任何收集的内容:http://localhost:9090/targets
已安装 .net 仪表板但未显示任何结果:
我需要做什么才能从我的应用程序中抓取结果 "buygroup"?
服务 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
服务监视器:
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
我想通了:
服务监控:
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
服务:
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
我已经在我的 kubernetes 开发集群上成功设置了 prometheus 和 grafana(如下所示:https://itnext.io/kubernetes-monitoring-with-prometheus-in-15-minutes-8e54d1de2e13)。
为我的示例 .net 核心应用程序将此添加到 Startup.cs:
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();
我应该为 app.UseMetricServer(此处?)指定任何内容吗?
我已经应用此 yaml 来添加我要抓取的应用程序:
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
我没有在目标中看到任何收集的内容:http://localhost:9090/targets
已安装 .net 仪表板但未显示任何结果:
我需要做什么才能从我的应用程序中抓取结果 "buygroup"?
服务 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
服务监视器:
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
我想通了:
服务监控:
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
服务:
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