// Module included in the following assemblies:
//
// * observability/monitoring/shiftstack-prometheus-configuration.adoc

:_mod-docs-content-type: PROCEDURE
[id="monitoring-configuring-shiftstack-scraping_{context}"]
= Collecting cluster metrics from the federation endpoint

You can employ the federation endpoint of your {product-title} cluster to make metrics available to a {rhoso-first} cluster to practice pull-based monitoring.

.Prerequisites

- You have administrative access to {rhoso} and the tenant cluster that is running on it.
- Telemetry is enabled in the {rhoso} environment.
- The Cluster Observability Operator is installed on your cluster.
- The monitoring stack for your cluster is configured.
- Your cluster has its federation endpoint exposed.

.Procedure

. Connect to your cluster by using a username and password; do not log in by using a `kubeconfig` file that was generated by the installation program.

. To retrieve a token from the {product-title} cluster, run the following command on it:
+
[source,terminal]
----
$ oc whoami -t
----

. Make the token available as a secret in the `openstack` namespace in the {rhoso} management cluster by running the following command:
+
[source,terminal]
----
$ oc -n openstack create secret generic ocp-federated --from-literal=token=<the_token_fetched_previously>
----

. To get the Prometheus federation route URL from your {product-title} cluster, run the following command:
+
[source,terminal]
----
$ oc -n openshift-monitoring get route prometheus-k8s-federate -ojsonpath={'.status.ingress[].host'}
----

. Write a manifest for a scrape configuration and save it as a file called `cluster-scrape-config.yaml`. As an example:
+
[source,yaml]
----
apiVersion: monitoring.rhobs/v1alpha1
kind: ScrapeConfig
metadata:
  labels:
    service: metricStorage
  name: sos1-federated
  namespace: openstack
spec:
  params:
    'match[]':
    - '{__name__=~"kube_node_info|kube_persistentvolume_info|cluster:master_nodes"}' # <1>
  metricsPath: '/federate'
  authorization:
    type: Bearer
    credentials:
      name: ocp-federated # <2>
      key: token
  scheme: HTTPS # or HTTP
  scrapeInterval: 30s # <3>
  staticConfigs:
  - targets:
    - prometheus-k8s-federate-openshift-monitoring.apps.openshift.example # <4>
----
<1> Add metrics here. In this example, only the metrics `kube_node_info`, `kube_persistentvolume_info`, and `cluster:master_nodes` are requested.
<2> Insert the previously generated secret name here.
<3> Limit scraping to fewer than 1000 samples for each request with a maximum frequency of once every 30 seconds.
<4> Insert the URL you fetched previously here. If the endpoint is HTTPS and uses a custom certificate authority, add a `tlsConfig` section after it.

. While connected to the {rhoso} management cluster, apply the manifest by running the following command:
+
[source,terminal]
----
$ oc apply -f cluster-scrape-config.yaml
----

After the config propagates, the cluster metrics are accessible for querying in the {product-title} UI in RHOSO.
