Skip to content

Commit

Permalink
Antrea Prometheus integration (antrea-io#236)
Browse files Browse the repository at this point in the history
Integrate with Prometheus monitoring solution.
Integration of the Prometheus client into Antrea controller and agent
allows the exposure of various metrics to Prometheus server.
In addition to Antrea's own set of metrics, Prometheus client will also
expose metrics which are defined by various components which are part of
the Antrea ecosystem, e.g golang, Prometheus itself etc.
  • Loading branch information
ksamoray committed Apr 21, 2020
1 parent d9fdf59 commit f0bda31
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 26 deletions.
24 changes: 21 additions & 3 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-agent` container must be set to the same value.
#apiPort: 10350
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
antrea-cni.conflist: |
{
"cniVersion":"0.3.0",
Expand All @@ -354,12 +363,21 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-controller` container must be set to the same value.
#apiPort: 10349
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener.
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
kind: ConfigMap
metadata:
annotations: {}
labels:
app: antrea
name: antrea-config-t4m46b8f6h
name: antrea-config-kmc5g2c4d4
namespace: kube-system
---
apiVersion: v1
Expand Down Expand Up @@ -459,7 +477,7 @@ spec:
key: node-role.kubernetes.io/master
volumes:
- configMap:
name: antrea-config-t4m46b8f6h
name: antrea-config-kmc5g2c4d4
name: antrea-config
- hostPath:
path: /var/log/antrea
Expand Down Expand Up @@ -658,7 +676,7 @@ spec:
operator: Exists
volumes:
- configMap:
name: antrea-config-t4m46b8f6h
name: antrea-config-kmc5g2c4d4
name: antrea-config
- hostPath:
path: /etc/cni/net.d
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-agent` container must be set to the same value.
#apiPort: 10350
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
antrea-cni.conflist: |
{
"cniVersion":"0.3.0",
Expand All @@ -354,12 +363,21 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-controller` container must be set to the same value.
#apiPort: 10349
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener.
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
kind: ConfigMap
metadata:
annotations: {}
labels:
app: antrea
name: antrea-config-5754dg84hf
name: antrea-config-ccg2965597
namespace: kube-system
---
apiVersion: v1
Expand Down Expand Up @@ -459,7 +477,7 @@ spec:
key: node-role.kubernetes.io/master
volumes:
- configMap:
name: antrea-config-5754dg84hf
name: antrea-config-ccg2965597
name: antrea-config
- hostPath:
path: /var/log/antrea
Expand Down Expand Up @@ -658,7 +676,7 @@ spec:
operator: Exists
volumes:
- configMap:
name: antrea-config-5754dg84hf
name: antrea-config-ccg2965597
name: antrea-config
- hostPath:
path: /etc/cni/net.d
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-agent` container must be set to the same value.
#apiPort: 10350
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
antrea-cni.conflist: |
{
"cniVersion":"0.3.0",
Expand All @@ -354,12 +363,21 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-controller` container must be set to the same value.
#apiPort: 10349
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener.
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
kind: ConfigMap
metadata:
annotations: {}
labels:
app: antrea
name: antrea-config-c7579447k2
name: antrea-config-4btg5ctkgk
namespace: kube-system
---
apiVersion: v1
Expand Down Expand Up @@ -468,7 +486,7 @@ spec:
key: node-role.kubernetes.io/master
volumes:
- configMap:
name: antrea-config-c7579447k2
name: antrea-config-4btg5ctkgk
name: antrea-config
- hostPath:
path: /var/log/antrea
Expand Down Expand Up @@ -699,7 +717,7 @@ spec:
operator: Exists
volumes:
- configMap:
name: antrea-config-c7579447k2
name: antrea-config-4btg5ctkgk
name: antrea-config
- hostPath:
path: /etc/cni/net.d
Expand Down
24 changes: 21 additions & 3 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-agent` container must be set to the same value.
#apiPort: 10350
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
antrea-cni.conflist: |
{
"cniVersion":"0.3.0",
Expand All @@ -354,12 +363,21 @@ data:
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-controller` container must be set to the same value.
#apiPort: 10349
# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener.
#enablePrometheusMetrics: false
# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false
# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
kind: ConfigMap
metadata:
annotations: {}
labels:
app: antrea
name: antrea-config-428d4tg64g
name: antrea-config-cgb74bc9c7
namespace: kube-system
---
apiVersion: v1
Expand Down Expand Up @@ -459,7 +477,7 @@ spec:
key: node-role.kubernetes.io/master
volumes:
- configMap:
name: antrea-config-428d4tg64g
name: antrea-config-cgb74bc9c7
name: antrea-config
- hostPath:
path: /var/log/antrea
Expand Down Expand Up @@ -658,7 +676,7 @@ spec:
operator: Exists
volumes:
- configMap:
name: antrea-config-428d4tg64g
name: antrea-config-cgb74bc9c7
name: antrea-config
- hostPath:
path: /etc/cni/net.d
Expand Down
9 changes: 9 additions & 0 deletions build/yamls/base/conf/antrea-agent.conf
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-agent` container must be set to the same value.
#apiPort: 10350

# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
#enablePrometheusMetrics: false

# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false

# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
9 changes: 9 additions & 0 deletions build/yamls/base/conf/antrea-controller.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
# Note that if it's set to another value, the `containerPort` of the `api` port of the
# `antrea-controller` container must be set to the same value.
#apiPort: 10349

# Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener.
#enablePrometheusMetrics: false

# Enable golang metrics exposure via Prometheus.
#enablePrometheusGoMetrics: false

# Enable process metrics exposure via Prometheus.
#enablePrometheusProcessMetrics: false
14 changes: 13 additions & 1 deletion cmd/antrea-agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/vmware-tanzu/antrea/pkg/agent/controller/networkpolicy"
"github.com/vmware-tanzu/antrea/pkg/agent/controller/noderoute"
"github.com/vmware-tanzu/antrea/pkg/agent/interfacestore"
"github.com/vmware-tanzu/antrea/pkg/agent/metrics"
"github.com/vmware-tanzu/antrea/pkg/agent/openflow"
"github.com/vmware-tanzu/antrea/pkg/agent/querier"
"github.com/vmware-tanzu/antrea/pkg/agent/route"
Expand Down Expand Up @@ -161,11 +162,22 @@ func run(o *Options) error {
ovsBridgeClient,
networkPolicyController)

if o.config.EnablePrometheusMetrics {
go metrics.InitializePrometheusMetrics(
o.config.EnablePrometheusGoMetrics,
o.config.EnablePrometheusProcessMetrics,
o.config.OVSBridge, ifaceStore, ofClient)
}

agentMonitor := monitor.NewAgentMonitor(crdClient, agentQuerier)

go agentMonitor.Run(stopCh)

apiServer, err := apiserver.New(agentQuerier, networkPolicyController, o.config.APIPort)
apiServer, err := apiserver.New(
agentQuerier,
networkPolicyController,
o.config.APIPort,
o.config.EnablePrometheusMetrics)
if err != nil {
return fmt.Errorf("error when creating agent API server: %v", err)
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/antrea-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ type AgentConfig struct {
// APIPort is the port for the antrea-agent APIServer to serve on.
// Defaults to 10350.
APIPort int `yaml:"apiPort,omitempty"`
// Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
// Defaults to false.
EnablePrometheusMetrics bool `yaml:"enablePrometheusMetrics,omitempty"`
// Enable golang metrics exposure via Prometheus
// Defaults to false.
EnablePrometheusGoMetrics bool `yaml:"enablePrometheusGoMetrics,omitempty"`
// Enable process metrics exposure via Prometheus
// Defaults to false.
EnablePrometheusProcessMetrics bool `yaml:"enablePrometheusProcessMetrics,omitempty"`
}
9 changes: 9 additions & 0 deletions cmd/antrea-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ type ControllerConfig struct {
// APIPort is the port for the antrea-controller APIServer to serve on.
// Defaults to 10349.
APIPort int `yaml:"apiPort,omitempty"`
// Enable metrics exposure via Prometheus. Initializes Prometheus metrics listener
// Defaults to false.
EnablePrometheusMetrics bool `yaml:"enablePrometheusMetrics,omitempty"`
// Enable golang metrics exposure via Prometheus
// Defaults to false.
EnablePrometheusGoMetrics bool `yaml:"enablePrometheusGoMetrics,omitempty"`
// Enable process metrics exposure via Prometheus
// Defaults to false.
EnablePrometheusProcessMetrics bool `yaml:"enablePrometheusProcessMetrics,omitempty"`
}
Loading

0 comments on commit f0bda31

Please sign in to comment.