跳转到主要内容

Kubernetes中Flux的自定义指标导出器

项目描述

Flux Metrics API

All Contributors

PyPI

这是为Kubernetes创建一个可以直接从Flux领导者代理pod运行的指标API的实验。我们在创建了prometheus-flux并希望有一个更简约的设计后创建了它。我不确定它是否真的能工作,但这值得一试!

用法

安装

您可以从PyPI或从源安装

$ python -m venv env
$ source env/bin/activate
$ pip install flux-metrics-api

# or

$ git clone https://github.com/converged-computing/flux-metrics-api
$ cd flux-metrics-api
$ pip install .
# you can also do "pip install -e ."

这将安装可执行文件到您的路径中,这可能是在您的本地用户bin中

$ which flux-metric-api
/home/vscode/.local/bin/flux-metrics-api

注意,提供的.devcontainer包含一个VSCode的环境,其中您有Flux可以安装并使用它!

启动

您需要在Flux实例中运行,因为我们需要连接到代理句柄。

$ flux start --test-size=4

然后启动服务器。这将使用默认端口和主机(0.0.0.0:8443),如果您想自定义,也可以。

$ flux-metrics-api start

# customize the port or host
$ flux-metrics-api start --port 9000 --host 127.0.0.1

SSL

如果您想使用ssl(端口443),您可以提供证书和密钥文件的路径

$ flux-metrics-api start --ssl-certfile /etc/certs/tls.crt --ssl-keyfile /etc/certs/tls.key

我们可能在pod内部运行的完整命令示例

$ flux-metrics-api start --port 8443 --ssl-certfile /etc/certs/tls.crt --ssl-keyfile /etc/certs/tls.key --namespace flux-operator --service-name custom-metrics-apiserver

即时自定义指标!

如果您想提供自定义指标,您可以在外部文件中编写一个函数,我们将读取它并将其添加到服务器中。一般来说

  • 函数的名称将是自定义指标的名称
  • 您期望的唯一参数是Flux句柄
  • 您需要在函数内部进行导入以使其在作用域内

这很可能可以进一步改进,但现在是一个起点!我们提供了一个示例文件。作为一个例子

$ flux-metrics-api start --custom-metric ./example/custom-metrics.py

然后测试它

$ curl -s http://localhost:8443/apis/custom.metrics.k8s.io/v1beta2/namespaces/flux-operator/metrics/my_custom_metric_name | jq
{
  "items": [
    {
      "metric": {
        "name": "my_custom_metric_name"
      },
      "value": 4,
      "timestamp": "2023-06-01T01:39:08+00:00",
      "windowSeconds": 0,
      "describedObject": {
        "kind": "Service",
        "namespace": "flux-operator",
        "name": "custom-metrics-apiserver",
        "apiVersion": "v1beta2"
      }
    }
  ],
  "apiVersion": "custom.metrics.k8s.io/v1beta2",
  "kind": "MetricValueList",
  "metadata": {
    "selfLink": "/apis/custom.metrics.k8s.io/v1beta2"
  }
}

查看--help以了解其他可用选项。

端点

指标

GET /apis/custom.metrics.k8s.io/v1beta2/namespaces//metrics/<metric_name>

以下是一个获取"node_up_count"指标的示例

 curl -s http://localhost:8443/apis/custom.metrics.k8s.io/v1beta2/namespaces/flux-operator/metrics/node_up_count | jq
{
  "items": [
    {
      "metric": {
        "name": "node_up_count"
      },
      "value": 2,
      "timestamp": "2023-05-31T04:44:57+00:00",
      "windowSeconds": 0,
      "describedObject": {
        "kind": "Service",
        "namespace": "flux-operator",
        "name": "custom-metrics-apiserver",
        "apiVersion": "v1beta2"
      }
    }
  ],
  "apiVersion": "custom.metrics.k8s.io/v1beta2",
  "kind": "MetricValueList",
  "metadata": {
    "selfLink": "/apis/custom.metrics.k8s.io/v1beta2"
  }
}

以下指标受支持

  • node_up_count:MiniCluster中上线的节点数量
  • node_free_count:MiniCluster中空闲的节点数量
  • node_cores_free_count:MiniCluster中空闲的节点核心数量
  • node_cores_up_count:MiniCluster中上线的节点核心数量
  • job_queue_state_new_count:队列中新的作业数量
  • job_queue_state_depend_count:状态为"depend"的队列中作业的数量
  • job_queue_state_priority_count:状态为"priority"的队列中作业的数量
  • job_queue_state_sched_count:状态为"sched"的队列中作业的数量
  • job_queue_state_run_count:状态为"run"的队列中作业的数量
  • job_queue_state_cleanup_count:状态为"cleanup"的队列中作业的数量
  • job_queue_state_inactive_count:状态为"inactive"的队列中作业的数量

Docker

我们有一个docker容器,您可以自定义以满足您的需求,但它的主要目的是演示。您可以自己构建,或者使用我们的构建。

$ docker build -t flux_metrics_api .
$ docker run -it -p 8443:8443 flux_metrics_api

或者

$ docker run -it -p 8443:8443 ghcr.io/converged-computing/flux-metrics-api

开发

请注意,这是用Python实现的,但(我在此之后发现)我们也可以使用Go。特别是,我发现这个仓库对查看规范格式很有用。

您可以在http://localhost:8443/metrics/打开浏览器以查看指标!

😁️ 贡献者 😁️

我们使用all-contributors工具生成下面的贡献者图形。

Vanessasaurus
Vanessasaurus

💻

许可

HPCIC DevTools在MIT许可下分发。所有新的贡献都必须在此许可下进行。

有关详细信息,请参阅LICENSECOPYRIGHTNOTICE

SPDX-License-Identifier: (MIT)

LLNL-CODE- 842614

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪一个,请了解有关安装包的更多信息。

源代码分发

flux-metrics-api-0.0.11.tar.gz (17.5 kB 查看哈希值)

上传时间 源代码

构建分发

flux_metrics_api-0.0.11-py3-none-any.whl (17.9 kB 查看哈希值)

上传时间 Python 3

支持者