Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ indent_style = tab
indent_style = space
indent_size = 4

[*/metrics.py]
indent_style = space
indent_size = 4

[**.js]
indent_style = space
indent_size = 4
20 changes: 19 additions & 1 deletion octoprint_prometheus_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,13 @@ def gcodephase_hook(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=No
self.metrics.extrusion_total.inc(self.parser.extrusion_counter - self.last_extrusion_counter)
self.last_extrusion_counter = self.parser.extrusion_counter

if self.parser.e is not None:
self.metrics.current_e.set(self.parser.e)

# x_travel_print is modeled as a gauge so we can reset it after every print
self.metrics.x_travel_print.set(self.parser.x_travel)
if self.parser.x is not None:
self.metrics.current_x.set(self.parser.x)

if self.parser.x_travel > self.last_x_travel:
# x_travel_total is monotonically increasing for the lifetime of the plugin
Expand All @@ -142,6 +147,8 @@ def gcodephase_hook(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=No

# y_travel_print is modeled as a gauge so we can reset it after every print
self.metrics.y_travel_print.set(self.parser.y_travel)
if self.parser.y is not None:
self.metrics.current_y.set(self.parser.y)

if self.parser.y_travel > self.last_y_travel:
# y_travel_total is monotonically increasing for the lifetime of the plugin
Expand All @@ -150,11 +157,22 @@ def gcodephase_hook(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=No

# z_travel_print is modeled as a gauge so we can reset it after every print
self.metrics.z_travel_print.set(self.parser.z_travel)
if self.parser.z is not None:
self.metrics.current_z.set(self.parser.z)

if self.parser.z_travel > self.last_z_travel:
# z_travel_total is monotonically increasing for the lifetime of the plugin
self.metrics.z_travel_total.inc(self.parser.z_travel - self.last_z_travel)
self.last_z_travel = self.parser.z_travel
elif parse_result == "coordinate_reset":
if self.parser.x is not None:
self.metrics.current_x.set(self.parser.x)
if self.parser.y is not None:
self.metrics.current_y.set(self.parser.y)
if self.parser.z is not None:
self.metrics.current_z.set(self.parser.z)
if self.parser.e is not None:
self.metrics.current_e.set(self.parser.e)
elif parse_result == "print_fan_speed":
v = getattr(self.parser, "print_fan_speed")
if v is not None:
Expand Down Expand Up @@ -208,7 +226,7 @@ def get_update_information(self):
pip="https://github.com/tg44/OctoPrint-Prometheus-Exporter/archive/{target_version}.zip"
)
)

def is_blueprint_protected(self):
# Disable global protection, use permission system.
return False
Expand Down
6 changes: 6 additions & 0 deletions octoprint_prometheus_exporter/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,11 @@ def print_complete(self):
z_travel_total = Counter('octoprint_z_travel_total', 'Z axis travel total', registry=registry)
z_travel_print = Gauge('octoprint_z_travel_print', 'Z axis travel in this print', registry=registry)

# coordinates
current_x = Gauge('octoprint_current_x', 'Current X coordinate', registry=registry)
current_y = Gauge('octoprint_current_y', 'Current Y coordinate', registry=registry)
current_z = Gauge('octoprint_current_z', 'Current Z coordinate', registry=registry)
current_e = Gauge('octoprint_current_e', 'Current E coordinate', registry=registry)

def render(self):
return make_wsgi_app(registry=self.registry)