added support for edgefs-monitoring via Prometheus
Signed-off-by: Dmitry Yusupov <dmitry.yusupov@nexenta.com>
This commit is contained in:
1 parent
1a1ffdd504
commit
cae7e9a994
6 files changed
+275
-10
No files matched your search
@@ -0,0 +1,89 @@
|
||||
---
|
||||
title: Monitoring
|
||||
weight: 48
|
||||
indent: true
|
||||
---
|
||||
|
||||
# Monitoring
|
||||
|
||||
Each Rook EdgeFS cluster has some built in metrics collectors/exporters for monitoring with [Prometheus](https://prometheus.io/).
|
||||
If you do not have Prometheus running, follow the steps below to enable monitoring of Rook. If your cluster already
|
||||
contains a Prometheus instance, it will automatically discover Rooks scrape endpoint using the standard
|
||||
`prometheus.io/scrape` and `prometheus.io/port` annotations.
|
||||
|
||||
|
||||
## Prometheus Operator
|
||||
|
||||
First the Prometheus operator needs to be started in the cluster so it can watch for our requests to start monitoring Rook and respond by deploying the correct Prometheus pods and configuration.
|
||||
A full explanation can be found in the [Prometheus operator repository on GitHub](https://github.com/coreos/prometheus-operator), but the quick instructions can be found here:
|
||||
```bash
|
||||
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/v0.27.0/bundle.yaml
|
||||
```
|
||||
This will start the Prometheus operator, but before moving on, wait until the operator is in the `Running` state:
|
||||
```bash
|
||||
kubectl get pod
|
||||
```
|
||||
Once the Prometheus operator is in the `Running` state, proceed to the next section.
|
||||
|
||||
## Prometheus Instances
|
||||
|
||||
With the Prometheus operator running, we can create a service monitor that will watch the Rook cluster and collect metrics regularly.
|
||||
From the root of your locally cloned Rook repo, go the monitoring directory:
|
||||
```bash
|
||||
cd cluster/examples/kubernetes/edgefs/monitoring
|
||||
```
|
||||
|
||||
Create the service monitor as well as the Prometheus server pod and service:
|
||||
```bash
|
||||
kubectl create -f service-monitor.yaml
|
||||
kubectl create -f prometheus.yaml
|
||||
kubectl create -f prometheus-service.yaml
|
||||
```
|
||||
|
||||
Ensure that the Prometheus server pod gets created and advances to the `Running` state before moving on:
|
||||
```bash
|
||||
kubectl -n rook-edgefs get pod prometheus-rook-prometheus-0
|
||||
```
|
||||
|
||||
## Prometheus Web Console
|
||||
|
||||
Once the Prometheus server is running, you can open a web browser and go to the URL that is output from this command:
|
||||
```bash
|
||||
echo "http://$(kubectl -n rook-edgefs -o jsonpath={.status.hostIP} get pod prometheus-rook-prometheus-0):30900"
|
||||
```
|
||||
|
||||
You should now see the Prometheus monitoring website.
|
||||
|
||||

|
||||
|
||||
|
||||
Click on `Graph` in the top navigation bar.
|
||||
|
||||

|
||||
|
||||
|
||||
In the dropdown that says `insert metric at cursor`, select any metric you would like to see, for example `nedge_cluster_objects`.
|
||||
Below the `Execute` button, ensure the `Graph` tab is selected and you should now see a graph of your chosen metric over time.
|
||||
|
||||
|
||||
## Prometheus Consoles
|
||||
A guide to how you can write your own Prometheus consoles can be found on the official Prometheus site here: https://prometheus.io/docs/visualization/consoles/.
|
||||
|
||||
## Grafana Dashboards
|
||||
For feedback on the dashboards please reach out to him on the [Rook.io Slack](https://slack.rook.io).
|
||||
|
||||
> **NOTE** The dashboard only compatible with Grafana 5.0.3 or higher.
|
||||
|
||||
The following Grafana dashboard is available:
|
||||
* [EdgeFS Cluster](https://grafana.com/dashboards/9683)
|
||||
|
||||
## Teardown
|
||||
|
||||
To clean up all the artifacts created by the monitoring walkthrough, copy/paste the entire block below (note that errors about resources "not found" can be ignored):
|
||||
```bash
|
||||
kubectl delete -f service-monitor.yaml
|
||||
kubectl delete -f prometheus.yaml
|
||||
kubectl delete -f prometheus-service.yaml
|
||||
kubectl delete -f https://raw.githubusercontent.com/coreos/prometheus-operator/v0.27.0/bundle.yaml
|
||||
```
|
||||
Then the rest of the instructions in the [Prometheus Operator docs](https://github.com/coreos/prometheus-operator#removal) can be followed to finish cleaning up.
|
||||
@@ -0,0 +1,15 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: rook-prometheus
|
||||
namespace: rook-edgefs
|
||||
spec:
|
||||
type: NodePort
|
||||
ports:
|
||||
- name: web
|
||||
nodePort: 30900
|
||||
port: 9090
|
||||
protocol: TCP
|
||||
targetPort: web
|
||||
selector:
|
||||
prometheus: rook-prometheus
|
||||
@@ -0,0 +1,55 @@
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: prometheus
|
||||
namespace: rook-edgefs
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: prometheus
|
||||
namespace: rook-edgefs
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources:
|
||||
- nodes
|
||||
- services
|
||||
- endpoints
|
||||
- pods
|
||||
verbs: ["get", "list", "watch"]
|
||||
- apiGroups: [""]
|
||||
resources:
|
||||
- configmaps
|
||||
verbs: ["get"]
|
||||
- nonResourceURLs: ["/metrics"]
|
||||
verbs: ["get"]
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: prometheus
|
||||
namespace: rook-edgefs
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: prometheus
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: prometheus
|
||||
namespace: rook-edgefs
|
||||
---
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: Prometheus
|
||||
metadata:
|
||||
name: rook-prometheus
|
||||
namespace: rook-edgefs
|
||||
labels:
|
||||
prometheus: rook-prometheus
|
||||
spec:
|
||||
serviceAccountName: prometheus
|
||||
serviceMonitorSelector:
|
||||
matchLabels:
|
||||
team: rook
|
||||
resources:
|
||||
requests:
|
||||
memory: 400Mi
|
||||
@@ -0,0 +1,19 @@
|
||||
apiVersion: monitoring.coreos.com/v1
|
||||
kind: ServiceMonitor
|
||||
metadata:
|
||||
name: rook-edgefs-mgr
|
||||
namespace: rook-edgefs
|
||||
labels:
|
||||
team: rook
|
||||
spec:
|
||||
namespaceSelector:
|
||||
matchNames:
|
||||
- rook-edgefs
|
||||
selector:
|
||||
matchLabels:
|
||||
app: rook-edgefs-mgr
|
||||
rook_cluster: rook-edgefs
|
||||
endpoints:
|
||||
- port: http-metrics
|
||||
path: /metrics
|
||||
interval: 5s
|
||||
@@ -20,6 +20,7 @@ package mgr
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/pkg/capnslog"
|
||||
edgefsv1alpha1 "github.com/rook/rook/pkg/apis/edgefs.rook.io/v1alpha1"
|
||||
@@ -39,6 +40,8 @@ const (
|
||||
appName = "rook-edgefs-mgr"
|
||||
defaultServiceAccountName = "rook-edgefs-cluster"
|
||||
defaultGrpcPort = 6789
|
||||
defaultRestPort = 8080
|
||||
defaultRestSPort = 4443
|
||||
defaultMetricsPort = 8881
|
||||
|
||||
/* Volumes definitions */
|
||||
@@ -153,6 +156,16 @@ func (c *Cluster) makeMgrService(name string) *v1.Service {
|
||||
Port: int32(defaultMetricsPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "http-mgmt",
|
||||
Port: int32(defaultRestPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "https-mgmt",
|
||||
Port: int32(defaultRestSPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -186,6 +199,13 @@ func (c *Cluster) makeDeployment(name, clusterName, rookImage string, replicas i
|
||||
})
|
||||
}
|
||||
|
||||
var rookImageVer string
|
||||
rookImageComponents := strings.Split(rookImage, ":")
|
||||
if len(rookImageComponents) == 2 {
|
||||
rookImageVer = rookImageComponents[1]
|
||||
} else {
|
||||
rookImageVer = "latest"
|
||||
}
|
||||
podSpec := v1.PodTemplateSpec{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
@@ -195,7 +215,7 @@ func (c *Cluster) makeDeployment(name, clusterName, rookImage string, replicas i
|
||||
},
|
||||
Spec: v1.PodSpec{
|
||||
ServiceAccountName: c.serviceAccount,
|
||||
Containers: []v1.Container{c.mgrContainer(name, rookImage)},
|
||||
Containers: []v1.Container{c.mgmtContainer(name, "edgefs/edgefs-restapi:"+rookImageVer), c.mgrContainer("grpc", rookImage)},
|
||||
RestartPolicy: v1.RestartPolicyAlways,
|
||||
Volumes: volumes,
|
||||
HostIPC: true,
|
||||
@@ -219,6 +239,77 @@ func (c *Cluster) makeDeployment(name, clusterName, rookImage string, replicas i
|
||||
return d
|
||||
}
|
||||
|
||||
func (c *Cluster) mgmtContainer(name string, containerImage string) v1.Container {
|
||||
|
||||
runAsUser := int64(0)
|
||||
readOnlyRootFilesystem := false
|
||||
securityContext := &v1.SecurityContext{
|
||||
RunAsUser: &runAsUser,
|
||||
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
|
||||
Capabilities: &v1.Capabilities{
|
||||
Add: []v1.Capability{"SYS_NICE", "SYS_RESOURCE", "IPC_LOCK"},
|
||||
},
|
||||
}
|
||||
|
||||
volumeMounts := []v1.VolumeMount{
|
||||
{
|
||||
Name: dataVolumeName,
|
||||
MountPath: "/opt/nedge/etc.target",
|
||||
SubPath: etcVolumeFolder,
|
||||
},
|
||||
{
|
||||
Name: dataVolumeName,
|
||||
MountPath: "/opt/nedge/var/run",
|
||||
SubPath: stateVolumeFolder,
|
||||
},
|
||||
}
|
||||
|
||||
return v1.Container{
|
||||
Name: name,
|
||||
Image: containerImage,
|
||||
ImagePullPolicy: v1.PullAlways,
|
||||
Args: []string{"mgmt"},
|
||||
Env: []v1.EnvVar{
|
||||
{
|
||||
Name: "CCOW_LOG_LEVEL",
|
||||
Value: "5",
|
||||
},
|
||||
{
|
||||
Name: "DEBUG",
|
||||
Value: "alert,error,info",
|
||||
},
|
||||
{
|
||||
Name: "HOST_HOSTNAME",
|
||||
ValueFrom: &v1.EnvVarSource{
|
||||
FieldRef: &v1.ObjectFieldSelector{
|
||||
FieldPath: "spec.nodeName",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
SecurityContext: securityContext,
|
||||
Resources: c.resources,
|
||||
Ports: []v1.ContainerPort{
|
||||
{
|
||||
Name: "http-metrics",
|
||||
ContainerPort: int32(defaultMetricsPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "http-mgmt",
|
||||
ContainerPort: int32(defaultRestPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "https-mgmt",
|
||||
ContainerPort: int32(defaultRestSPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
VolumeMounts: volumeMounts,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) mgrContainer(name string, containerImage string) v1.Container {
|
||||
|
||||
runAsUser := int64(0)
|
||||
@@ -271,11 +362,6 @@ func (c *Cluster) mgrContainer(name string, containerImage string) v1.Container
|
||||
ContainerPort: int32(defaultGrpcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "http-metrics",
|
||||
ContainerPort: int32(defaultMetricsPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
VolumeMounts: volumeMounts,
|
||||
}
|
||||
|
||||
@@ -87,9 +87,10 @@ func TestPodSpec(t *testing.T) {
|
||||
assert.Equal(t, 1, len(d.Spec.Template.Spec.Volumes))
|
||||
|
||||
//check ports
|
||||
assert.Equal(t, 2, len(d.Spec.Template.Spec.Containers[0].Ports))
|
||||
assert.Equal(t, int32(6789), d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort)
|
||||
assert.Equal(t, int32(8881), d.Spec.Template.Spec.Containers[0].Ports[1].ContainerPort)
|
||||
assert.Equal(t, 3, len(d.Spec.Template.Spec.Containers[0].Ports))
|
||||
assert.Equal(t, int32(8881), d.Spec.Template.Spec.Containers[0].Ports[0].ContainerPort)
|
||||
assert.Equal(t, int32(8080), d.Spec.Template.Spec.Containers[0].Ports[1].ContainerPort)
|
||||
assert.Equal(t, int32(4443), d.Spec.Template.Spec.Containers[0].Ports[2].ContainerPort)
|
||||
|
||||
assert.Equal(t, "edgefs-datadir", d.Spec.Template.Spec.Volumes[0].Name)
|
||||
assert.Equal(t, "mgr-a", d.ObjectMeta.Name)
|
||||
@@ -116,7 +117,7 @@ func TestServiceSpec(t *testing.T) {
|
||||
s := c.makeMgrService("rook-edgefs-mgr")
|
||||
assert.NotNil(t, s)
|
||||
assert.Equal(t, "rook-edgefs-mgr", s.Name)
|
||||
assert.Equal(t, 2, len(s.Spec.Ports))
|
||||
assert.Equal(t, 4, len(s.Spec.Ports))
|
||||
}
|
||||
|
||||
func TestHostNetwork(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user