-
Notifications
You must be signed in to change notification settings - Fork 799
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
Remove gauge metric #1055
Comments
I can set the cost to 0, and bypass it that way, but it will still result in metric that is no longer needed being preserved and thus over time, consuming space. :/ |
Hello, this sounds like the use case for a custom collector: https://prometheus.github.io/client_python/collector/custom/. You will only add metrics for the nodes that you want to include in the output so no extra series will be left around. |
@csmarchbanks thanks for the hint, |
That would work by running your get_node and other logic during each scrape and only having from prometheus_client.core import GaugeMetricFamily, REGISTRY
from prometheus_client.registry import Collector
class CustomCollector(Collector):
def collect(self):
cost_metric = GaugeMetricFamily("cost_metric ",
"Cost of running an instance for 1 hour",
["node_name", "instance_type"],
)
node_names = get_nodes()
for node_name in node_names:
node_info = get_node_info(node_name)
# ... collect label info, etc... from your code.
if cost is not None:
cost_metric.labels(node_name=node_name, instance_type=instance_type).set(cost)
yield cost_metric
REGISTRY.register(CustomCollector()) |
@csmarchbanks |
@csmarchbanks I have implemented an exporter as suggested. What I mean by that is as follows: |
same problem, any suggestion? |
Hi all,
I have written a custom exporter for calculating the cost of using a node in AWS.
Here is how it works:
Lets assume I have 3 nodes, each costs 5$/ 1h, when I plot using grafana the sum(cost_metric{}) i get 15$ (3x5$). Lets say after 2 hours one of the nodes get deleted (autoscaling). In that case the total cost should drop to 10$.
The problem is that in my case the metric is preserved and even though the node has been deleted the cost is kept and thus it displays 15$ instead of dropping to 10$
How would I go about saving that problem?
I tried
I collected previous and current nodes in form of dict and then wanted to removed the ones that arent existing, the issue is that :
The text was updated successfully, but these errors were encountered: