|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * monitoring/configuring-the-monitoring-stack.adoc |
| 4 | + |
| 5 | +[id="setting-query-log-file-for-prometheus_{context}"] |
| 6 | += Enabling the query log file for Prometheus |
| 7 | + |
| 8 | +You can configure Prometheus to log all the queries run by the engine to a log file. |
| 9 | + |
| 10 | +[WARNING] |
| 11 | +==== |
| 12 | +Since there is no support of log rotation, this feature should only be enabled temporarily to support troubleshooting. |
| 13 | +==== |
| 14 | + |
| 15 | +.Prerequisites |
| 16 | + |
| 17 | +* *If you are enabling the query log file feature for Prometheus in the `openshift-monitoring` project*: |
| 18 | +** You have access to the cluster as a user with the `cluster-admin` role. |
| 19 | +** You have created the `cluster-monitoring-config` `ConfigMap` object. |
| 20 | +* *If you are enabling the query log file feature for Prometheus in the `openshift-user-workload-monitoring` project*: |
| 21 | +** You have access to the cluster as a user with the `cluster-admin` role, or as a user with the `user-workload-monitoring-config-edit` role in the `openshift-user-workload-monitoring` project. |
| 22 | +** You have created the `user-workload-monitoring-config` `ConfigMap` object. |
| 23 | +* You have installed the OpenShift CLI (`oc`). |
| 24 | + |
| 25 | +.Procedure |
| 26 | + |
| 27 | +. Edit the `ConfigMap` object: |
| 28 | +** *To set the query log file for Prometheus in the `openshift-monitoring` project*: |
| 29 | +.. Edit the `cluster-monitoring-config` `ConfigMap` object in the `openshift-monitoring` project: |
| 30 | ++ |
| 31 | +[source,terminal] |
| 32 | +---- |
| 33 | +$ oc -n openshift-monitoring edit configmap cluster-monitoring-config |
| 34 | +---- |
| 35 | + |
| 36 | +.. Add `queryLogFile: <path>` for `prometheusK8s` under `data/config.yaml`: |
| 37 | ++ |
| 38 | +[source,yaml] |
| 39 | +---- |
| 40 | +apiVersion: v1 |
| 41 | +kind: ConfigMap |
| 42 | +metadata: |
| 43 | + name: cluster-monitoring-config |
| 44 | + namespace: openshift-monitoring |
| 45 | +data: |
| 46 | + config.yaml: | |
| 47 | + prometheusK8s: |
| 48 | + queryLogFile: <path> <1> |
| 49 | +---- |
| 50 | +<1> The path for the file you wish to log queries to. |
| 51 | + |
| 52 | +. Save the file to apply the changes. |
| 53 | + |
| 54 | ++ |
| 55 | +[WARNING] |
| 56 | +==== |
| 57 | +When changes are saved to a monitoring config map, the pods and other resources in the related project might be redeployed. The running monitoring processes in that project might also be restarted. |
| 58 | +==== |
| 59 | + |
| 60 | +. Check that the pods for the component are running. The following example lists the status of pods in the `openshift-monitoring` project: |
| 61 | ++ |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +$ oc -n openshift-monitoring get pods |
| 65 | +---- |
| 66 | ++ |
| 67 | + |
| 68 | +. Read the query log: |
| 69 | ++ |
| 70 | +[source,terminal] |
| 71 | +---- |
| 72 | +$ oc -n openshift-monitoring exec prometheus-k8s-0 -- cat <path> |
| 73 | +---- |
| 74 | ++ |
| 75 | + |
| 76 | +[NOTE] |
| 77 | +==== |
| 78 | +Do not forget to revert the setting after you have digested the required information. |
| 79 | +==== |
| 80 | + |
| 81 | +** *To set the query log file for Prometheus in the `openshift-user-workload-monitoring` project*: |
| 82 | +.. Edit the `user-workload-monitoring-config` `ConfigMap` object in the `openshift-user-workload-monitoring` project: |
| 83 | ++ |
| 84 | +[source,terminal] |
| 85 | +---- |
| 86 | +$ oc -n openshift-user-workload-monitoring edit configmap user-workload-monitoring-config |
| 87 | +---- |
| 88 | + |
| 89 | +.. Add `queryLogFile: <path>` for `prometheus` under `data/config.yaml`: |
| 90 | ++ |
| 91 | +[source,yaml] |
| 92 | +---- |
| 93 | +apiVersion: v1 |
| 94 | +kind: ConfigMap |
| 95 | +metadata: |
| 96 | + name: user-workload-monitoring-config |
| 97 | + namespace: openshift-user-workload-monitoring |
| 98 | +data: |
| 99 | + config.yaml: | |
| 100 | + prometheus: |
| 101 | + queryLogFile: <path> <1> |
| 102 | +---- |
| 103 | +<1> The path for the file you wish to log queries to. |
| 104 | + |
| 105 | +. Save the file to apply the changes. |
| 106 | ++ |
| 107 | +[NOTE] |
| 108 | +==== |
| 109 | +Configurations applied to the `user-workload-monitoring-config` `ConfigMap` object are not activated unless a cluster administrator has enabled monitoring for user-defined projects. |
| 110 | +==== |
| 111 | ++ |
| 112 | +[WARNING] |
| 113 | +==== |
| 114 | +When changes are saved to a monitoring config map, the pods and other resources in the related project might be redeployed. The running monitoring processes in that project might also be restarted. |
| 115 | +==== |
| 116 | + |
| 117 | +. Check that the pods for the component are running. The following example lists the status of pods in the `openshift-user-workload-monitoring` project: |
| 118 | ++ |
| 119 | +[source,terminal] |
| 120 | +---- |
| 121 | +$ oc -n openshift-user-workload-monitoring get pods |
| 122 | +---- |
| 123 | ++ |
| 124 | + |
| 125 | +. Read the query log: |
| 126 | ++ |
| 127 | +[source,terminal] |
| 128 | +---- |
| 129 | +$ oc -n openshift-user-workload-monitoring exec prometheus-k8s-0 -- cat <path> |
| 130 | +---- |
| 131 | ++ |
| 132 | + |
| 133 | +[NOTE] |
| 134 | +==== |
| 135 | +Do not forget to revert the setting after you have digested the required information. |
| 136 | +==== |
0 commit comments