Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix imports and documenation on how to run the scripts #81

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

openshift-usage-scripts contains 2 scripts:

1. `openshift-usage-scripts/openshift-prometheus_metrics.py` that collects metrics from prometheus and writes those to a json file.
2. `openshift-usage-scripts/merge.py` takes the collected metrics and produces CSV OpenShift usage reports, one by namespace and other by pod.
1. `openshift-metrics/openshift-prometheus_metrics.py` that collects metrics from prometheus and writes those to a json file.
2. `openshift-metrics/merge.py` takes the collected metrics and produces CSV OpenShift usage reports, one by namespace and other by pod.

This was a fork of https://github.com/OCP-on-NERC/xdmod-openshift-scripts

Expand All @@ -22,28 +22,28 @@ endpoint. The first is through an environment variable:

```
$ export OPENSHIFT_PROMETHEUS_URL=<prometheus url>
$ python openshift-usage-scripts/openshift_prometheus_metrics.py
$ python -m openshift-metrics.openshift_prometheus_metrics.py
```

The second is directly on the command line:

```
$ python openshift-usage-scripts/openshift_prometheus_metrics.py --openshift-url <prometheus url>
$ python -m openshift-metrics.openshift_prometheus_metrics --openshift-url <prometheus url>
```

### Collecting metrics

By default the script will pull data from the day before.

```
$ python openshift_metrics/openshift_prometheus_metrics.py \
$ python -m openshift_metrics.openshift_prometheus_metrics \
--openshift-url https://thanos-querier-openshift-monitoring.apps.shift.nerc.mghpcc.org \
```

You can specify a data range to collect metrics for a time period like this:

```
$ python openshift_metrics/openshift_prometheus_metrics.py \
$ python -m openshift_metrics.openshift_prometheus_metrics \
--openshift-url https://thanos-querier-openshift-monitoring.apps.shift.nerc.mghpcc.org \
--report-start-date 2022-03-01 \
--report-end-date 2022-03-07 \
Expand All @@ -56,7 +56,7 @@ This will collect metrics from March 1st to March 7th, inclusive.
You can generate the openshift usage report by passing it multiple metrics files

```
$ python openshift_metrics/merge.py \
$ python -m openshift_metrics.merge \
metrics-2024-01-01-to-2024-01-07.json \
metrics-2024-01-08-to-2024-01-14.json \
metrics-2024-01-15-to-2024-01-16.json
Expand All @@ -67,7 +67,7 @@ This will merge the metrics and produce the openshift usage report of the period
Output file name can be specified with the `--output-file` flags. You can also pass in a bunch of files like this:

```
$ python openshift_metrics/merge.py data_2024_01/*.json
$ python -m openshift_metrics.merge data_2024_01/*.json
```

## How It Works
Expand Down
5 changes: 2 additions & 3 deletions openshift_metrics/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from datetime import datetime
import json

import utils

from metrics_processor import MetricsProcessor
from openshift_metrics import utils
from openshift_metrics.metrics_processor import MetricsProcessor

def compare_dates(date_str1, date_str2):
"""Returns true is date1 is earlier than date2"""
Expand Down
4 changes: 2 additions & 2 deletions openshift_metrics/openshift_prometheus_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

import argparse
from datetime import datetime, timedelta
from prometheus_client import PrometheusClient
import os
import sys
import json

import utils
from openshift_metrics import utils
from openshift_metrics.prometheus_client import PrometheusClient


CPU_REQUEST = 'kube_pod_resource_request{unit="cores"} unless on(pod, namespace) kube_pod_status_unschedulable'
Expand Down
Loading