{"id":28378048,"url":"https://github.com/robusta-dev/prometrix","last_synced_at":"2025-06-26T21:32:19.867Z","repository":{"id":184838830,"uuid":"672506677","full_name":"robusta-dev/prometrix","owner":"robusta-dev","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-09T10:42:06.000Z","size":206,"stargazers_count":19,"open_issues_count":6,"forks_count":3,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-22T03:52:46.057Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robusta-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-30T10:18:45.000Z","updated_at":"2025-06-09T10:42:10.000Z","dependencies_parsed_at":"2023-07-30T15:21:24.630Z","dependency_job_id":"ed1e9a01-d173-4269-beaa-fc399b5f1269","html_url":"https://github.com/robusta-dev/prometrix","commit_stats":null,"previous_names":["kotlickya/prometheus-kubernetes-cli","kotlickya/prometrix","robusta-dev/prometrix"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robusta-dev/prometrix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robusta-dev%2Fprometrix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robusta-dev%2Fprometrix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robusta-dev%2Fprometrix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robusta-dev%2Fprometrix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robusta-dev","download_url":"https://codeload.github.com/robusta-dev/prometrix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robusta-dev%2Fprometrix/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262145187,"owners_count":23265886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-30T01:35:29.667Z","updated_at":"2025-06-26T21:32:19.861Z","avatar_url":"https://github.com/robusta-dev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Prometrix - Unified Prometheus Client\n======================================================\n\nOverview\n--------\n\nThis Python package provides a unified Prometheus client that can be used to connect to and query various types of Prometheus instances. The package is based on the [prometheus-api-client](https://pypi.org/project/prometheus-api-client/)  package , which serves as the foundation for our extended functionality.\n\nThe prometrix package enhances the prometheus-api-client by adding vendor-specific authentication methods and other features to handle authorization and signatures for all supported clients. This ensures a secure and seamless connection to the various types of Prometheus instances.\n1.  Coralogix\n2.  GKE (Google Kubernetes Engine)\n3.  Azure\n4.  EKS (Amazon Elastic Kubernetes Service)\n5.  Thanos\n6.  Victoria Metrics\n\nThe main function, `get_custom_prometheus_connect`, allows you to create a custom Prometheus client based on the provided configuration. The configurations for special Prometheus versions are defined through specific classes, each extending the base `PrometheusConfig` class.\n\nInstallation\n------------\n\nYou can install the package using pip:\n\n```\npip install prometrix\n```\n\nUsage\n-----\n\n### Importing the package\n\n```\nfrom prometrix import get_custom_prometheus_connect\nfrom prometrix.config import (\n    PrometheusConfig,\n    AWSPrometheusConfig,\n    CoralogixPrometheusConfig,\n    VictoriaMetricsPrometheusConfig,\n    AzurePrometheusConfig,\n    PrometheusApis,\n)\n```\n\n### Creating a Custom Prometheus Client\n\nTo create a custom Prometheus client, you need to pass the appropriate configuration to the `get_custom_prometheus_connect` function. The function returns an instance of the `CustomPrometheusConnect` class that represents the client.\n\n```\n# Create a custom Prometheus client for Coralogix Prometheus\ncoralogix_config = CoralogixPrometheusConfig(\n    url=\"https://coralogix-prometheus.example.com\",\n    prometheus_token=\"YOUR_CORALOGIX_PROMETHEUS_TOKEN\",\n    additional_labels={\"job\": \"coralogix-prometheus\"},\n)\ncoralogix_client = get_custom_prometheus_connect(coralogix_config)\n\n# Create a custom Prometheus client for GKE Prometheus\ngke_config = PrometheusConfig(\n    url=\"https://gke-prometheus.example.com\",\n    disable_ssl=False,\n    headers={\"Authorization\": \"Bearer YOUR_GKE_PROMETHEUS_TOKEN\"},\n    additional_labels={\"job\": \"gke-prometheus\"},\n)\ngke_client = get_custom_prometheus_connect(gke_config)\n\n# Create a custom Prometheus client for Azure Prometheus\nazure_config = AzurePrometheusConfig(\n    url=\"https://azure-prometheus.example.com\",\n    disable_ssl=False,\n    headers={\"Authorization\": \"Bearer YOUR_AZURE_PROMETHEUS_TOKEN\"},\n    azure_resource=\"YOUR_AZURE_RESOURCE\",\n    azure_metadata_endpoint=\"https://azure-metadata.example.com\",\n    azure_token_endpoint=\"https://azure-token.example.com\",\n    azure_client_id=\"YOUR_AZURE_CLIENT_ID\",\n    azure_tenant_id=\"YOUR_AZURE_TENANT_ID\",\n    azure_client_secret=\"YOUR_AZURE_CLIENT_SECRET\",\n    additional_labels={\"job\": \"azure-prometheus\"},\n)\nazure_client = get_custom_prometheus_connect(azure_config)\n```\n\nSimilar configuration and creation can be done for EKS, Thanos, and Victoria Metrics Prometheus.\n\n\u003e **_NOTE:_** You need to replace the placeholder values (e.g., YOUR_CORALOGIX_PROMETHEUS_TOKEN) with your actual credentials and endpoints.\n\n### Supported APIs\n\nThe `prometrix` package extends the prometheus-api-client class PrometheusConnect with the following additional functionality:\n\n```\nget_prometheus_flags(self) -\u003e Optional[Dict]\n```\nThis function allows you to receive the configured flags from Prometheus. It returns a dictionary containing the flags and their respective values set in the Prometheus instance.\n\n```\ncheck_prometheus_connection(self, params: dict = None)\n```\nThe `check_prometheus_connection` function enables you to check the connection status with the Prometheus instance. You can pass an optional dictionary of parameters to customize the connection check. This function returns true if it is able to connect.\n\n\n```\nsafe_custom_query_range\n```\n\nThe `safe_custom_query_range` function retrieves time-series data from Prometheus over a specified range. It returns the queried data in JSON format or raises an exception if the request fails.\n\n**Differences between `custom_query_range` and `safe_custom_query_range`:**\n- `custom_query_range` is a feature of the `prometheus_api_client` library, utilized internally by Prometrix.\n- `safe_custom_query_range` returns the entire `data` dictionary from the Prometheus query response, whereas `custom_query_range` only returns the `result` section.\n\n```\nsafe_custom_query\n```\nThe `safe_custom_query` function executes a single-point Prometheus query and returns the result in JSON format. It throws an exception in the event of an error.\n\n**Differences between `custom_query` and `safe_custom_query`:**\n- `custom_query` is part of the `prometheus_api_client` library, used internally by Prometrix.\n- `safe_custom_query` returns the complete `data` dictionary of the Prometheus query response, in contrast to `custom_query`, which only returns the `result` section.\n\n\nContributing\n------------\n\nIf you'd like to contribute to this package, please follow the guidelines specified in the CONTRIBUTING.md file in the repository.\n\nReleasing\n----------\n\nTo release a new version, bump the version number in pyproject.toml and run:\n\n```\npoetry publish --build --username=\u003cusername\u003e --password=\u003cpassword\u003e\n```\n\nWe're planning to automate this with GitHub actions but it hasn't been fully setup or tested yet.\n\nLicense\n-------\n\nThis project is licensed under the MIT License - see the LICENSE.md file for details.\n\nAcknowledgments\n---------------\n\nThis package was inspired by the need to have a flexible and generic Prometheus client that can be easily extended to connect with different Prometheus types. Special thanks to the Prometheus team and the open-source community for their contributions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobusta-dev%2Fprometrix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobusta-dev%2Fprometrix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobusta-dev%2Fprometrix/lists"}