Database metrics

We can collect TCP metrics after we run the MongoDB database for ratings:v2. As we did in the previous section, here, we'll create an instance, handler, and a rule to collect metrics. Let's get started:

  1. Define a configuration for the sent and receive bytes from a server to a client:
# Script : 05-create-metric-instance.yaml

apiVersion: config.istio.io/v1alpha2
kind: instance
metadata:
name: mongosentbytes
...
params:
value: connection.sent.bytes | 0 # uses a TCP-specific attribute
dimensions:
source_service: source.workload.name | "unknown"
source_version: source.labels["version"] | "unknown"
destination_version: destination.labels["version"] | "unknown"
...
metadata:
name: mongoreceivedbytes
...
  1. Create a handler for bytes sent and received for the MongoDb database service:
$ kubectl -n istio-system apply -f 05-create-metric-instance.yaml
instance.config.istio.io/mongosentbytes created
instance.config.istio.io/mongoreceivedbytes created
  1. Configure a Prometheus handler in order to generate MongoDB sent and received byte instances:
# Script : 06-create-prometheus-handler.yaml

apiVersion: config.istio.io/v1alpha2
kind: handler
metadata:
name: mongohandler
spec:
compiledAdapter: prometheus
params:
metrics:
- name: mongo_sent_bytes # Prometheus metric name
# Mixer instance name (fully-qualified)
instance_name: mongosentbytes.instance.istio-system
kind: COUNTER
label_names:
- source_service
- source_version
- destination_version
# Prometheus metric name
- name: mongo_received_bytes
# Mixer instance name (fully-qualified)
instance_name: mongoreceivedbytes.instance.istio-system
kind: COUNTER
label_names:
- source_service
- source_version
- destination_version
  1. Create a Prometheus handler:
$ kubectl -n istio-system apply -f 06-create-prometheus-handler.yaml
handler.config.istio.io/mongohandler created
  1. Define a rule to send the sent and received metrics instances to the Prometheus handler:
# Script : 07-create-rule-to-send-metric-to-prometheus.yaml

apiVersion: config.istio.io/v1alpha2
kind: rule
metadata:
name: mongoprom
spec:
match: context.protocol == "tcp"
&& destination.service.host == "mongodb.istio-lab.svc.cluster.local"
actions:
- handler: mongohandler
instances:
- mongoreceivedbytes
- mongosentbytes
  1. Create a rule:
$ kubectl -n istio-system apply -f 07-create-rule-to-send-metric-to-prometheus.yaml
rule.config.istio.io/mongoprom created
  1. Switch back to your Prometheus UI (http://prometheus.istio.io), type istio_mongo_received_bytes, and click Execute. You will see the value of the received bytes from the MongoDB service:

  1. Repeat the same for istio_mongo_sent_bytes. Note that these metrics collections were defined outside the application through the pushdown configuration of the Istio instance, handler, and rule primitives.

If a database provides Prometheus-enabled metric collection, it is easier to integrate with Istio using a Prometheus handler. This was just an example of TCP metrics that are available through connection metrics. 

The purpose of this exercise was to show you that Istio has a built-in mechanism that we can use to collect data using predefined attributes. We can use them to create an instance, allow that instance to be handled through a predefined handler, and generate a rule to execute the handler to generate and collect metrics. This is done at the Mixer level.

Next, we will explore distributed tracing and the different backend adapters that are available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.171.121