更新时间:2023-02-16 16:12:35
我知道了:
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