项目作者: ssube

项目描述 :
Prometheus SDK for CircuitPython/MicroPython boards
高级语言: Python
项目地址: git://github.com/ssube/prometheus_express.git
创建时间: 2019-08-17T14:01:42Z
项目社区:https://github.com/ssube/prometheus_express

开源协议:MIT License

下载


prometheus_express

A Prometheus SDK for CircuitPython and MicroPython boards, helping integrate I2C and SPI
sensors into existing Prometheus monitoring infrastructure.

  • only depends on socket
  • runs on CircuitPython 4.x and MicroPython for ESP32 and M0/M4 devices
  • runs even faster on CPython 3.x for local testing
  • API compatible with the official prometheus/client_python
  • basic HTTP server with path/method routing
  • not terribly slow (20 rps on an ESP32, 50 rps on an M4 core, 5k on an i7 core)

For those unfamiliar with Prometheus, the examples expose an HTTP server on port :8080 that serves /metrics in
a readable, plaintext format:

  1. # HELP prom_express_gas gas from the bme680 sensor
  2. # TYPE prom_express_gas gauge
  3. prom_express_gas 1060948
  4. # HELP prom_express_humidity humidity from both sensors
  5. # TYPE prom_express_humidity gauge
  6. prom_express_humidity{sensor="None"} 0
  7. prom_express_humidity{sensor="bme680"} 49.4062
  8. prom_express_humidity{sensor="si7021"} 49.7976
  9. # HELP prom_express_pressure pressure from the bme680 sensor
  10. # TYPE prom_express_pressure gauge
  11. prom_express_pressure 983.25
  12. # HELP prom_express_temperature temperature from both sensors
  13. # TYPE prom_express_temperature gauge
  14. prom_express_temperature{sensor="None"} 0
  15. prom_express_temperature{sensor="bme680"} 24.7359
  16. prom_express_temperature{sensor="si7021"} 24.3325

The Prometheus server will occasionally scrape each device, collecting sensor readings with metadata about
their source, and passing the samples on to long-term storage.

Contents

Status

Pipeline Status
Test Coverage
MIT license

Open bug count
Open issue count
Closed issue count

Maintainability
Technical debt ratio
Quality issues
LGTM Language grade: Python
LGTM Total alerts

Releases

github release link
github release version
github commits since release

PyPI release link
PyPI release version

Supported Hardware

This library is tested on:

Supported Features

HTTP Server

This module implements a very rudimentary HTTP server that almost certainly violates some part of the spec.
However, it works with Chrome, curl, and Prometheus itself. Depending on the platform, it may also work with
wrk benchmarks (known issues).

Metric Labels

Labels are stored and used to accumulate values. Missing labels are reported as None.

If a metric is constructed with labels, a default entry with all values set to None will also be reported.

Metric Types

Counter, Gauge, and Summary are implemented with labels.

Counter

Incremental values. Implements inc(value) and dec(value).

Gauge

Absolute values. Extends counter with set(value).

Summary

Individual values. Prints count and total of observe(value).

Registries

Registries may be created with a namespace: CollectorRegistry(namespace='foo')

Call registry.render() to format metrics in Prometheus’
plain text exposition format:

  1. # HELP prom_express_test_counter a test counter
  2. # TYPE prom_express_test_counter counter
  3. prom_express_test_counter 1588
  4. # HELP prom_express_test_gauge a test gauge
  5. # TYPE prom_express_test_gauge gauge
  6. prom_express_test_gauge 3887

Metrics may be registered with multiple registries.

Planned Features

  • push support: push_to_gateway
  • remaining metric types: Histogram
  • tests for API compatibility

Known Issues

OSError 3, 4, or 7

Load testing the HTTP endpoint may cause one of a variety of OSErrors, often errno 3, 4, or 7.

This is related to the Wiznet5500 driver for
ethernet FeatherWings, and may not appear on other devices:

  1. > ./wrk -c 1 -d 60s -t 1 http://server:8080/
  2. Running 1m test @ http://server:8080/
  3. 1 threads and 1 connections
  4. Thread Stats Avg Stdev Max +/- Stdev
  5. Latency 8.64ms 485.57us 12.81ms 97.75%
  6. Req/Sec 111.60 5.21 121.00 71.00%
  7. 2222 requests in 20.61s, 671.83KB read
  8. Socket errors: connect 0, read 1, write 2743, timeout 0
  9. Requests/sec: 107.82
  10. Transfer/sec: 32.60KB

Some are fatal:

  1. Connection from ('client', 8080)
  2. Accepting...
  3. Connection from ('client', 8080)
  4. Accepting...
  5. Error accepting request: [Errno 128] ENOTCONN
  6. Binding: server:8080
  7. Traceback (most recent call last):
  8. File "code.py", line 90, in <module>
  9. File "code.py", line 87, in main
  10. File "code.py", line 87, in main
  11. File "code.py", line 55, in bind
  12. File "/lib/prometheus_express/http.py", line 11, in start_http_server
  13. OSError: 4

Others require the socket to be rebound:

  1. Connection from ('client', 8080)
  2. Accepting...
  3. Error accepting request: 7
  4. Binding: server:8080
  5. Accepting...

OSError 112

Certain crashes may leak open sockets, causing the device to log an OSError 112 during startup.

The error prevents the HTTP server from binding to the ethernet device, so an HTTP watchdog on the
switch can be used to restart POE devices. The board can also be reset by calling machine.reset()
from the REPL.