mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-10-21 13:31:19 +00:00
fixup! fixup! [ADD] monitoring_prometheus_queue_job
This commit is contained in:
1 parent
47add4311f
commit
a369050b04
4 files changed
+53
-2
No files matched your search
@@ -1,2 +1,2 @@
|
|||||||
from . import controllers
|
|
||||||
from . import models
|
from . import models
|
||||||
|
from . import controllers
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
from . import ir_http
|
from . import ir_http
|
||||||
from . import prometheus_metric
|
|
||||||
from . import prometheus_gatherer
|
from . import prometheus_gatherer
|
||||||
|
from . import prometheus_metric
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Copyright 2016-2021 Camptocamp SA
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class PrometheusMetric(models.Model):
|
||||||
|
"""Store the metrics gathered by ``prometheus.gatherer``.
|
||||||
|
|
||||||
|
A record is stored per metric name/labels combination, because a single
|
||||||
|
metric name can be reported several times with different labels (e.g.
|
||||||
|
one gauge value per queue job state and channel).
|
||||||
|
"""
|
||||||
|
|
||||||
|
_name = "prometheus.metric"
|
||||||
|
_description = "Prometheus Metric"
|
||||||
|
|
||||||
|
name = fields.Char(required=True, index=True)
|
||||||
|
documentation = fields.Char()
|
||||||
|
# JSON-serialized dict, used both to publish the metric and as part of
|
||||||
|
# the uniqueness key alongside ``name``.
|
||||||
|
labels = fields.Char(default="{}")
|
||||||
|
value = fields.Float(required=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _labels_key(labels):
|
||||||
|
return json.dumps(labels or {}, sort_keys=True)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _update_metric(self, metric):
|
||||||
|
"""Create or update the record matching ``metric``, return it."""
|
||||||
|
labels_key = self._labels_key(metric.get("labels"))
|
||||||
|
record = self.search(
|
||||||
|
[("name", "=", metric["name"]), ("labels", "=", labels_key)],
|
||||||
|
limit=1,
|
||||||
|
)
|
||||||
|
values = {
|
||||||
|
"name": metric["name"],
|
||||||
|
"documentation": metric.get("documentation", ""),
|
||||||
|
"labels": labels_key,
|
||||||
|
"value": metric["value"],
|
||||||
|
}
|
||||||
|
if record:
|
||||||
|
record.write(values)
|
||||||
|
else:
|
||||||
|
record = self.create(values)
|
||||||
|
return record
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_prometheus_metric_system,prometheus.metric system,model_prometheus_metric,base.group_system,1,1,1,1
|
||||||
|