Giter Club home page Giter Club logo

cpm_exporter's Introduction

CPM Exporter

CPM Exporter is a Python script that reads Counts Per Minute (CPM) data from a Geiger counter device and exposes it as a Prometheus metric. This tool is useful for monitoring radiation levels and integrating the data with Prometheus-based monitoring systems.

In this case, this script is used with the following device: GQ GME-300E Plus

Features

  • Reads CPM data from a Geiger counter device via serial communication
  • Exposes CPM data as a Prometheus metric
  • Configurable sleep interval between data retrievals
  • Logging for easy troubleshooting

Requirements

  • Python 3.x
  • pyserial
  • prometheus_client

Installation

  1. Clone this repository or download the cpm_metrics.py script.
  2. Install the required Python packages:
pip install pyserial prometheus_client

Usage

Run the script with:

python cpm_metrics.py [sleep_interval]
  • sleep_interval (optional): Time in seconds between data retrievals. Defaults to 60 seconds if not specified.

Configuration

The script uses the following constants, which can be modified in the code if needed:

  • SERIAL_PORT: The serial port for the Geiger counter device (default: '/dev/cpm')
  • SERIAL_BAUDRATE: The baud rate for serial communication (default: 57600)
  • SERIAL_TIMEOUT: Timeout for serial operations in seconds (default: 3)
  • DEFAULT_SLEEP_INTERVAL: Default sleep interval between data retrievals in seconds (default: 60)

Prometheus Integration

The script starts a Prometheus HTTP server on port 8000. The CPM data is exposed as a Gauge metric named geiger_cpm with the description "Counts per minute from Geiger counter".

To scrape this metric with Prometheus, add the following job to your Prometheus configuration:

scrape_configs:
  - job_name: 'cpm_exporter'
    static_configs:
      - targets: ['localhost:8000']

Logging

The script logs information, warnings, and errors to the console. The log format includes timestamps and log levels for easy debugging.

Error Handling

The script includes error handling for various scenarios, including:

  • Invalid sleep interval input
  • Failure to start the Prometheus server
  • Serial communication errors
  • Unexpected errors during execution

In case of critical errors, the script will log the error and exit with a non-zero status code.

License

This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.

cpm_exporter's People

Contributors

thron2002 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.