Commit Graph

55 Commits

Author SHA1 Message Date
Jérôme LOYET
ce77333416 add dynamic labels 2025-01-17 05:56:27 +01:00
Jérôme LOYET
5ede83bcb7 add raw_expression 2025-01-01 09:01:41 +01:00
Christoph Petrausch
6bd07d1e22 Merge pull request #161 from fatpat/expr_int/float
improve expr float() and int() to handle strings
2024-12-31 22:23:54 +01:00
Jérôme LOYET
e18dc0b9ce improve expr float() and int() to handle strings 2024-12-30 09:54:28 +01:00
Jérôme LOYET
d28d6cd818 make error_value global to metric
* fail if both metric.error_value and
  metric.string_value_mapping.error_value are set
* mark metric.string_value_mapping.error_value as deprecated
2024-12-30 09:53:12 +01:00
Christoph Petrausch
4b0085b8cc Merge pull request #156 from fatpat/update-expr
update expr to 1.16.9
2024-12-27 20:05:03 +01:00
Jérôme LOYET
6ff26135b2 update expr to 1.16.9
- update minimal go version from 1.16 to 1.18 (like expr)
- update test from go 1.16 to 1.23
2024-12-27 08:39:41 +01:00
Alf-Rune Siqveland
95bbd81f7d feat: Add configuration option to enable/disable profiling metrics
Added a new configuration `enable_profiling_metrics` which
enable/disable the default runtime metrics exported by the Prometheus
client package.

BREAKING CHANGE: Changed default behavior to exclude runtime metrics.
        Enable with enable_profiling_metrics configuration option.
Signed-off-by: Alf-Rune Siqveland <alf.rune@siqveland.no>
2024-08-18 12:44:23 +02:00
Christian Schneider
cd459836a6 Improved error reporting. 2024-03-25 10:15:05 +01:00
Christian Schneider
9f92116fe3 Support multiple configs per input metric.
When generating metric values using expression evaluation, there are new
use-cases for more than one configuration for each sensor value.
Expressions are more flexible than aggregation rules in Prometheus, so
it makes sense to derive multiple metrics from the same sensor input.
2024-03-25 10:15:05 +01:00
Christian Schneider
f380bea81d Support metrics from arithmetic expressions.
This change adds the new metric config option `expression` which can
define a complex expression to calculate the final metric value. The
expression is evaluated using github.com/antonmedv/expr as the engine,
see expr-lang.org/docs/v1.9/Language-Definition for a language overview.
In addition, some basic functions are available during evaluation: now,
int, float, round, ceil, floor, abs, min, max.

For each evaluation, the expression gets:
- the current MQTT value
- the last MQTT value
- the result of the last evaluation
- the elapsed time since the last evaluation

Expressions allow more flexibility to derive metrics from sensor inputs
which are very hard or even impossible to do in Prometheus, for example,
integrate continuous values over time, filter extreme or zero values, or
non-linear scaling. The last value, result, and timestamp are preserved
even between restarts of mqtt2prometheus. This means that expressions
can be used to produce continuous time series over a long time range.

To make upstream integration easier, the code depends on the rather old
v1.8.9 of github.com/antonmedv/expr, which is available in the main repo
of all supported Debian versions.
2024-03-25 10:15:05 +01:00
Christian Schneider
84ed960831 Restrict to Go 1.14 functionality 2024-02-05 21:56:40 +01:00
Christian Schneider
4943c97963 Add option to enforce strict monotonicy in metrics.
This change adds the new option `force_monotonicy` to metric
configurations. It is intended for almost-but-not-really monotinic
sources, such as counters which reset when the sensor is restarted.

When this option is set to `true`, the source metric value is regularly
written to disk. This allows us to detect and compensate counter resets
even between restarts. When a reset is detected, the last value before
the reset becomes the new offset, which is added to the metric value
going forth.  The result is a strictly monotonic time series, like an
ever increasing counter.
2024-02-05 21:04:52 +01:00
yan
9da7b1b379 Handle json payload in metric_per_topic mode 2024-02-05 21:04:52 +01:00
Alexander Bakker
6d695bdbf4 Rename received_messages metric to be more conventional
This patch renames the ``received_messages`` metric to
``mqtt2prometheus_received_messages_total``, making it a bit more in
line with conventional Prometheus metric naming.

I also slightly adjusted the descriptions.
2024-02-05 21:04:52 +01:00
Will Moss
f03d0841f4 Remove incorrect errors from SensorNameFilter
This commit reorganizes the logic in parseMetric to have it take in a MetricConfig so that the extractor can find the config and properly handle the case when there's no config found.
2023-01-03 21:44:05 -08:00
Will Moss
173eebe9be Check for specifying both *_per_topic_config in config 2023-01-01 11:48:09 -08:00
alessandro negrin
ae387c23ae tests 2022-11-30 10:02:48 +01:00
alessandro negrin
a76297e47c optional ts in metrics 2022-11-30 10:02:48 +01:00
alessandro negrin
e76641898a scale as a multiplier 2022-11-29 16:18:03 +01:00
alessandro negrin
d077874127 scale as unsigned float; tests for values from string or boolean 2022-11-29 10:33:55 +01:00
alessandro negrin
740352bc00 scaling option for MQTT values 2022-11-28 18:39:39 +01:00
Christoph Petrausch
25115cf80a Fix struct tags 2021-12-25 08:34:56 +01:00
michey
4f1b56fe2f Add way to change default separator for json pathes 2021-12-24 23:39:43 +03:00
Christoph Petrausch
3b436b2d81 Merge pull request #54 from chr4/chore/strict-yaml-unmarshal
Use UnmarshalStrict for config file to catch config errors
2021-03-14 20:54:22 +01:00
Chris Aumann
366c38c791 Use UnmarshalStrict for config file to catch config errors 2021-03-14 14:09:53 +01:00
Chris Aumann
6ab535ebe1 Use upstream DefaultExpiration for go-cache 2021-03-14 13:26:10 +01:00
Christoph Petrausch
30a2180cfa Add mqtt2prometheus_connected gauge to represent connection state 2021-03-12 21:22:27 +01:00
weboo
d5ee3e68f9 support for TLS client certificates 2021-03-12 21:51:57 +09:00
Christoph Petrausch
3bd83c1d9b Add more tests 2021-03-08 20:44:53 +01:00
Chris Aumann
5b0603c32d Make GroupValue() more resilient 2021-03-06 18:39:02 +01:00
Christoph Petrausch
24df81ed32 Add fuzzing 2021-02-14 20:47:41 +01:00
Christoph Petrausch
e5cc73f9b2 Refactor cache datastructure to use a key per metric instead of a key per device
This should resolve #26
2021-01-23 22:09:33 +01:00
Christoph Petrausch
ab0f600bfd Add unittests for parser 2020-11-08 22:50:07 +01:00
Christoph Petrausch
be4af9ff5e Refactor metric extraction from MQTT
This commit allows to extract the metric name from the topic path. Now
it can be configured if all metrics are in a object in a certain topic
or if every topic contains exactly one metric. However, currently these
modes can not be mixed.

This should solve !26

TODO:
* Update documentation
* Add unit tests
2020-11-08 22:01:36 +01:00
Christoph Petrausch
126e13428b Use go.uber.org/zap for logging
As mentioned in https://github.com/hikhvar/mqtt2prometheus/issues/23, we
do not use any logging framework at all. This was fine for getting the
exporter startet. However, with inreasing load the logging must be
configureable. This PR is a start to replace all instances of
"log.Printf" with the zap logger. The current configuration parameters
are the log level and the log format (console, json). We might expose
the log configuration to the config file. But I think this is overkill
for the current state of the exporter.
2020-10-29 20:58:28 +01:00
Christoph Petrausch
800b8c0cc5 Append source topic to metrics 2020-07-18 18:28:52 +02:00
Christoph Petrausch
f13c36ab4a Breaking: Don't append + automatically to the topic 2020-07-18 18:17:29 +02:00
Christoph Petrausch
29eb9250f6 Moved to gojsonq to support nested paths 2020-07-18 18:03:49 +02:00
Christoph Petrausch
5680206095 Support arbitrary position of device id in topic
The device firmware tasmota places the device ID in the middle of the
topic path. To support those devices to this commit introduce the
device_id_regex configuration. The old behavior of the last element of
the topic path is unchanged.
2020-07-18 18:02:17 +02:00
Christoph Petrausch
ec23d61881 Rename RegexpFilter to use it for device id extraction too 2020-07-18 18:02:17 +02:00
Christoph Petrausch
627c52669a Update hack config 2020-07-16 14:42:38 +02:00
Mansour Behabadi
7b5796b042 Add sensor name filter config 2020-05-22 00:42:49 +10:00
Mansour Behabadi
1ac6f71fa3 Fix typo 2020-05-03 18:29:15 +10:00
Mansour Behabadi
6e6113efba Remove unused regex 2020-05-03 18:15:31 +10:00
Mansour Behabadi
13c47b498d Parse more value types
* Parse bools as 0 for false and 1 for true
* Allow mapping between string and float values
2020-05-03 18:11:09 +10:00
Christoph Petrausch
77f0cbcc30 Merge pull request #3 from AchMenz/master
fixed wrong cache behavior (was always 2 minutes)
2020-03-17 20:36:51 +01:00
AchMenz
550dec1c42 fixed default time 2020-03-17 17:43:55 +01:00
AchMenz
0953fbf647 fixed default time 2020-03-17 17:41:04 +01:00
Paul Rogalinski-Pinter
1f5ee67214 make an attempt to parse string floats 2020-03-11 22:51:45 +01:00