***

layout: overview
slug: nemo-curator/nemo\_curator/metrics/utils
title: nemo\_curator.metrics.utils
----------------------------------

## Module Contents

### Functions

| Name                                                                                                                             | Description                                                                            |
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [`_get_all_discovery_paths`](#nemo_curator-metrics-utils-_get_all_discovery_paths)                                               | Extract all file paths from all file\_sd\_configs entries in the prometheus config.    |
| [`_is_process_running_from_pidfile`](#nemo_curator-metrics-utils-_is_process_running_from_pidfile)                               | Check if a process is running by reading its PID from a file and verifying it's alive. |
| [`_resolve_metrics_dir`](#nemo_curator-metrics-utils-_resolve_metrics_dir)                                                       | Resolve the metrics directory, defaulting to DEFAULT\_NEMO\_CURATOR\_METRICS\_PATH.    |
| [`_write_ray_default_dashboards`](#nemo_curator-metrics-utils-_write_ray_default_dashboards)                                     | Generate and write Ray's default Grafana dashboards to the dashboards directory.       |
| [`add_ray_prometheus_metrics_service_discovery`](#nemo_curator-metrics-utils-add_ray_prometheus_metrics_service_discovery)       | Add the ray prometheus metrics service discovery to the prometheus config.             |
| [`download_and_extract_prometheus`](#nemo_curator-metrics-utils-download_and_extract_prometheus)                                 | Download the prometheus tarball and extract it to the metrics directory.               |
| [`download_grafana`](#nemo_curator-metrics-utils-download_grafana)                                                               | Download the grafana tarball and extract it to the metrics directory.                  |
| [`get_prometheus_port`](#nemo_curator-metrics-utils-get_prometheus_port)                                                         | Get the port number that Prometheus is running on by reading the port file.            |
| [`is_grafana_running`](#nemo_curator-metrics-utils-is_grafana_running)                                                           | Check if Grafana is currently running for this metrics instance.                       |
| [`is_prometheus_running`](#nemo_curator-metrics-utils-is_prometheus_running)                                                     | Check if Prometheus is currently running for this metrics instance.                    |
| [`launch_grafana`](#nemo_curator-metrics-utils-launch_grafana)                                                                   | Launch the grafana server.                                                             |
| [`remove_ray_prometheus_metrics_service_discovery`](#nemo_curator-metrics-utils-remove_ray_prometheus_metrics_service_discovery) | Remove the ray prometheus metrics service discovery from the prometheus config.        |
| [`run_prometheus`](#nemo_curator-metrics-utils-run_prometheus)                                                                   | Run the prometheus server.                                                             |
| [`write_grafana_configs`](#nemo_curator-metrics-utils-write_grafana_configs)                                                     | Write the grafana configs to the grafana directory.                                    |

### API

<Anchor id="nemo_curator-metrics-utils-_get_all_discovery_paths">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils._get_all_discovery_paths(
        prometheus_config: dict
    ) -> list[str]
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Extract all file paths from all file\_sd\_configs entries in the prometheus config.
</Indent>

<Anchor id="nemo_curator-metrics-utils-_is_process_running_from_pidfile">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils._is_process_running_from_pidfile(
        pid_file_path: str
    ) -> bool
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Check if a process is running by reading its PID from a file and verifying it's alive.
</Indent>

<Anchor id="nemo_curator-metrics-utils-_resolve_metrics_dir">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils._resolve_metrics_dir(
        metrics_dir: str | None
    ) -> str
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Resolve the metrics directory, defaulting to DEFAULT\_NEMO\_CURATOR\_METRICS\_PATH.
</Indent>

<Anchor id="nemo_curator-metrics-utils-_write_ray_default_dashboards">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils._write_ray_default_dashboards(
        dashboards_path: str
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Generate and write Ray's default Grafana dashboards to the dashboards directory.
</Indent>

<Anchor id="nemo_curator-metrics-utils-add_ray_prometheus_metrics_service_discovery">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.add_ray_prometheus_metrics_service_discovery(
        ray_temp_dir: str,
        metrics_dir: str | None = None
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Add the ray prometheus metrics service discovery to the prometheus config.
</Indent>

<Anchor id="nemo_curator-metrics-utils-download_and_extract_prometheus">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.download_and_extract_prometheus(
        metrics_dir: str | None = None,
        os_type = None,
        architecture = None,
        prometheus_version = None
    ) -> str
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Download the prometheus tarball and extract it to the metrics directory.
</Indent>

<Anchor id="nemo_curator-metrics-utils-download_grafana">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.download_grafana(
        metrics_dir: str | None = None
    ) -> str
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Download the grafana tarball and extract it to the metrics directory.
</Indent>

<Anchor id="nemo_curator-metrics-utils-get_prometheus_port">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.get_prometheus_port(
        metrics_dir: str | None = None
    ) -> int
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Get the port number that Prometheus is running on by reading the port file.
</Indent>

<Anchor id="nemo_curator-metrics-utils-is_grafana_running">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.is_grafana_running(
        metrics_dir: str | None = None
    ) -> bool
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Check if Grafana is currently running for this metrics instance.
</Indent>

<Anchor id="nemo_curator-metrics-utils-is_prometheus_running">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.is_prometheus_running(
        metrics_dir: str | None = None
    ) -> bool
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Check if Prometheus is currently running for this metrics instance.
</Indent>

<Anchor id="nemo_curator-metrics-utils-launch_grafana">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.launch_grafana(
        grafana_dir: str,
        grafana_ini_path: str,
        grafana_web_port: int,
        metrics_dir: str | None = None
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Launch the grafana server.
</Indent>

<Anchor id="nemo_curator-metrics-utils-remove_ray_prometheus_metrics_service_discovery">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.remove_ray_prometheus_metrics_service_discovery(
        ray_temp_dir: str,
        metrics_dir: str | None = None
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Remove the ray prometheus metrics service discovery from the prometheus config.
</Indent>

<Anchor id="nemo_curator-metrics-utils-run_prometheus">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.run_prometheus(
        prometheus_dir: str,
        prometheus_web_port: int,
        metrics_dir: str | None = None
    ) -> None
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Run the prometheus server.
</Indent>

<Anchor id="nemo_curator-metrics-utils-write_grafana_configs">
  <CodeBlock showLineNumbers={false} wordWrap={true}>
    ```python
    nemo_curator.metrics.utils.write_grafana_configs(
        grafana_web_port: int,
        prometheus_web_port: int,
        metrics_dir: str | None = None
    ) -> str
    ```
  </CodeBlock>
</Anchor>

<Indent>
  Write the grafana configs to the grafana directory.
</Indent>
