diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5e1580..6bde011 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,12 @@
Change Log
==========
+v0.7.1
+------
+
+- Added history data metrics including total print time or total filament used.
+ Add the new `history` module in your `prometheus.yml` config. Thanks to @r4ptor #12
+
v0.7.0
------
diff --git a/README.md b/README.md
index 3cccbd6..fad22fb 100644
--- a/README.md
+++ b/README.md
@@ -28,14 +28,11 @@ These changes affect the following metrics groups
- `klipper_temperature_fan_`*
- `klipper_output_pin_`*
-
For example:
- `klipper_network_`**wlan0
**`_rx_bytes` becomes `klipper_network_rx_bytes{interface="`**wlan0
**`"}`
- `klipper_temperature_sensor_`**mtu
**`_temperature` becomes `klipper_temperature_sensor_temperature{sensor="`**mtu
**`"}`
-
-
Usage
-----
@@ -57,7 +54,7 @@ scrape_configs:
static_configs:
- targets: [ 'klipper.local:7125' ]
params:
- modules: [ "process_stats", "job_queue", "system_info", "network_stats", "directory_info", "printer_objects" ]
+ modules: [ "process_stats", "job_queue", "system_info", "network_stats", "directory_info", "printer_objects", "history" ]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
@@ -161,3 +158,4 @@ group of metrics is queried from a different Moonraker API endpoint.
| `directory_info` | | `klipper_disk_usage_available`
`klipper_disk_usage_total`
`klipper_disk_usage_used` |
| `temperature` | | `klipper_extruder_power`
`klipper_extruder_target`
`klipper_extruder_temperature`
`klipper_heater_bed_power`
`klipper_heater_bed_target`
`klipper_heater_bed_temperature`
`klipper_temperature_sensor_*_temperature` |
| `printer_objects` | | `klipper_extruder_power`
`klipper_extruder_pressure_advance`
`klipper_extruder_smooth_time`
`klipper_extruder_target`
`klipper_extruder_temperature`
`klipper_fan_rpm`
`klipper_fan_speed`
`klipper_gcode_extrude_factor`
`klipper_gcode_speed_factor`
`klipper_gcode_speed`
`klipper_heater_bed_power`
`klipper_heater_bed_target`
`klipper_heater_bed_temperature`
`klipper_output_pin_value{pin="`*pin*`"}`
`klipper_printing_time`
`klipper_print_filament_used`
`klipper_print_file_position`
`klipper_print_file_progress`
`klipper_print_gcode_progress`
`klipper_print_total_duration`
`klipper_temperature_fan_speed{fan="`*fan*`"}`
`klipper_temperature_fan_temperature{fan="`*fan*`"}`
`klipper_temperature_fan_target{fan="`*fan*`"}`
`klipper_temperature_sensor_temperature{sensor="`*sensor*`"}`
`klipper_temperature_sensor_measured_max_temp{sensor="`*sensor*`"}`
`klipper_temperature_sensor_measured_min_temp{sensor="`*sensor*`"}`
`klipper_toolhead_estimated_print_time`
`klipper_toolhead_max_accel_to_decel`
`klipper_toolhead_max_accel`
`klipper_toolhead_max_velocity`
`klipper_toolhead_print_time`
`klipper_toolhead_square_corner_velocity` |
+| `history` | | `klipper_total_jobs`
`klipper_total_time`
`klipper_total_print_time`
`klipper_total_filament_used`
`klipper_longest_job`
`klipper_longest_print`
diff --git a/collector/collector.go b/collector/collector.go
index 0d48ed3..6dfd120 100644
--- a/collector/collector.go
+++ b/collector/collector.go
@@ -186,6 +186,35 @@ func (c collector) Collect(ch chan<- prometheus.Metric) {
prometheus.GaugeValue,
float64(len(result.Result.QueuedJobs)))
}
+ // Job History
+ if slices.Contains(c.modules, "history") {
+ c.logger.Infof("Collecting history for %s", c.target)
+ result, _ := c.fetchMoonrakerHistory(c.target)
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_total_jobs", "Klipper number of total jobs.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.Jobs))
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_total_time", "Klipper total time.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.TotalTime))
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_total_print_time", "Klipper total print time.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.PrintTime))
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_total_filament_used", "Klipper total meters of filament used.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.FilamentUsed))
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_longest_job", "Klipper total longest job.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.LongestJob))
+ ch <- prometheus.MustNewConstMetric(
+ prometheus.NewDesc("klipper_longest_print", "Klipper total longest print.", nil, nil),
+ prometheus.GaugeValue,
+ float64(result.Result.JobTotals.LongestPrint))
+ }
// System Info
if slices.Contains(c.modules, "system_info") {
@@ -355,17 +384,17 @@ func (c collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
temperatureSensor,
prometheus.GaugeValue,
- sv.Temperature,
+ sv.Temperature,
sensorName)
ch <- prometheus.MustNewConstMetric(
temperatureSensorMinTemp,
prometheus.GaugeValue,
- sv.MeasuredMinTemp,
+ sv.MeasuredMinTemp,
sensorName)
ch <- prometheus.MustNewConstMetric(
temperatureSensorMaxTemp,
prometheus.GaugeValue,
- sv.MeasuredMaxTemp,
+ sv.MeasuredMaxTemp,
sensorName)
}
diff --git a/collector/history.go b/collector/history.go
new file mode 100644
index 0000000..9ee1c31
--- /dev/null
+++ b/collector/history.go
@@ -0,0 +1,49 @@
+package collector
+
+// https://moonraker.readthedocs.io/en/latest/web_api/#history-apis
+
+import (
+ "encoding/json"
+ "io/ioutil"
+
+ "net/http"
+)
+
+type MoonrakerHistoryResponse struct {
+ Result struct {
+ JobTotals struct {
+ Jobs int64 `json:"total_jobs"`
+ TotalTime float64 `json:"total_time"`
+ PrintTime float64 `json:"total_print_time"`
+ FilamentUsed float64 `json:"total_filament_used"`
+ LongestJob float64 `json:"longest_job"`
+ LongestPrint float64 `json:"longest_print"`
+ } `json:"job_totals"`
+ } `json:"result"`
+}
+
+func (c collector) fetchMoonrakerHistory(klipperHost string) (*MoonrakerHistoryResponse, error) {
+ var procStatsUrl = "http://" + klipperHost + "/server/history/totals"
+ c.logger.Debug("Collecting metrics from " + procStatsUrl)
+ res, err := http.Get(procStatsUrl)
+ if err != nil {
+ c.logger.Error(err)
+ return nil, err
+ }
+ defer res.Body.Close()
+ data, err := ioutil.ReadAll(res.Body)
+ if err != nil {
+ c.logger.Fatal(err)
+ return nil, err
+ }
+
+ var response MoonrakerHistoryResponse
+
+ err = json.Unmarshal(data, &response)
+ if err != nil {
+ c.logger.Fatal(err)
+ return nil, err
+ }
+
+ return &response, nil
+}
diff --git a/example/prometheus.yml b/example/prometheus.yml
index e73fd13..2926960 100644
--- a/example/prometheus.yml
+++ b/example/prometheus.yml
@@ -6,17 +6,17 @@ scrape_configs:
static_configs:
- targets: [ 'klipper.home.lan:7125' ]
params:
- modules: [ 'process_stats', 'network_stats', 'system_info', 'job_queue', 'directory_info', 'printer_objects' ]
+ modules: [ 'process_stats', 'network_stats', 'system_info', 'job_queue', 'directory_info', 'printer_objects', 'history' ]
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
- replacement: klipper-exporter:9101
+ replacement: study-imac.home.lan:9101
- job_name: "klipper-exporter"
scrape_interval: 5s
metrics_path: /metrics
static_configs:
- - targets: [ 'klipper-exporter:9101' ]
+ - targets: [ 'study-imac.home.lan:9101' ]
diff --git a/version.txt b/version.txt
index e7f5d1a..6425bba 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-v0.7.0
\ No newline at end of file
+v0.7.1
\ No newline at end of file