Skip to content

Commit

Permalink
Adding prometheus endpoint in tron
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanElsaban committed Mar 4, 2024
1 parent 0671979 commit 3e23199
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements-minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ipython
Jinja2>=3.1.2
lockfile
moto
prometheus-client==0.20.0
psutil
py-bcrypt
pyasn1
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ oauthlib==3.1.0
parso==0.7.0
pexpect==4.7.0
pickleshare==0.7.5
prometheus-client==0.20.0
prompt-toolkit==3.0.38
psutil==5.6.6
ptyprocess==0.6.0
Expand Down
1 change: 1 addition & 0 deletions tests/api/resource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def test__init__(self):
b"metrics",
b"status",
b"events",
b"prom-metrics",
b"",
]
assert set(expected_children) == set(self.resource.children)
Expand Down
2 changes: 2 additions & 0 deletions tron/api/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import traceback

import staticconf
from prometheus_client.twisted import MetricsResource as MetricsResourceProm

from tron.config.static_config import get_config_watcher
from tron.config.static_config import NAMESPACE
Expand Down Expand Up @@ -500,6 +501,7 @@ def __init__(self, mcp):
self.putChild(b"status", StatusResource(mcp))
self.putChild(b"events", EventsResource())
self.putChild(b"metrics", MetricsResource())
self.putChild(b"prom-metrics", MetricsResourceProm())
self.putChild(b"", self)

@AsyncResource.bounded
Expand Down
7 changes: 7 additions & 0 deletions tron/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from twisted.internet.defer import logError

import tron.metrics as metrics
import tron.prom_metrics as prom_metrics
from tron import __version__
from tron.actioncommand import ActionCommand
from tron.config.schema import ConfigFieldSelectorSource
Expand Down Expand Up @@ -90,7 +91,13 @@ def report_resources(self, decrement: bool = False) -> None:
Update internal resource utilization statistics of all tronjobs running for this task's Tron master.
"""
# TODO(TRON-1612): these should eventually be Prometheus metrics
# these should be replaced with gauges in prometheus
multiplier = -1 if decrement else 1
# prometheus gauges
prom_metrics.tron_cpu_gauge.inc(self.task_config.cpus * multiplier)
prom_metrics.tron_memory_gauge.inc(self.task_config.memory * multiplier)
prom_metrics.tron_disk_gauge.inc(self.task_config.disk * multiplier)

metrics.count("tron.mesos.cpus", self.task_config.cpus * multiplier)
metrics.count("tron.mesos.mem", self.task_config.memory * multiplier)
metrics.count("tron.mesos.disk", self.task_config.disk * multiplier)
Expand Down
6 changes: 6 additions & 0 deletions tron/prom_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from prometheus_client import Gauge


tron_cpu_gauge = Gauge("tron.k8s.cpus")
tron_memory_gauge = Gauge("tron.k8s.mem")
tron_disk_gauge = Gauge("tron.k8s.disk")

0 comments on commit 3e23199

Please sign in to comment.