Skip to content

Instantly share code, notes, and snippets.

@mikejoh
Last active February 9, 2023 11:40
Show Gist options
  • Save mikejoh/e54b8f29d78ead9d1e9e35353e9050f0 to your computer and use it in GitHub Desktop.
Save mikejoh/e54b8f29d78ead9d1e9e35353e9050f0 to your computer and use it in GitHub Desktop.
Monitor Calico Felix using the Prometheus Operator (Kubernetes)

Monitor Calico Felix using Prometheus Operator

Make sure you have these settings enabled in felix, in this case using enviornment variables:

FELIX_PROMETHEUSMETRICSENABLED = True
FELIX_PROMETHEUSMETRICSPORT = "9091"
FELIX_PROMETHEUSGOMETRICSENABLED = True
FELIX_PROMETHEUSPROCESSMETRICSENABLED = True

Create a Service with clusterIP set to None, the service will be used to enumerate endpoints to scrape:

apiVersion: v1
kind: Service
metadata:
  name: calico-felix-metrics
  namespace: kube-system
  labels:
    monitoring: calico-felix
spec:
  clusterIP: None
  ports:
  - port: 9091
    protocol: TCP 
    name: metrics  
  selector:
    k8s-app: calico-node

Create a ServiceMonitor to start scrape the calico-node Pods:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: calico-felix-metrics
  namespace: monitoring
spec:
  selector:
    matchLabels:
      monitoring: calico-felix
  namespaceSelector:
    matchNames:
    - kube-system
  endpoints:
  - port: metrics
    relabelings:
    - sourceLabels:
      - __meta_kubernetes_endpoint_node_name
      targetLabel: instance

Note the relabeling above, this changes the instance label to something more descriptive when querying for Calico Felix metrics.

Install the official Grafana dashboard: https://grafana.com/grafana/dashboards/12175

Links

https://docs.projectcalico.org/reference/felix/prometheus https://docs.projectcalico.org/archive/v3.18/reference/felix/configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment