2025-04-06 09:53:52 +03:00
2025-02-16 12:38:35 +02:00
2025-04-06 09:53:52 +03:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00
2025-04-06 09:53:52 +03:00
2025-02-16 12:38:35 +02:00
2025-02-16 12:38:35 +02:00

Das Simple Exporter

Das Simple metrics Exporter for Prometheus

Python Prometheus Grafana Docker

💡 Purpose

Create configurable lightweight application to collect some metrics

📃 Features

📌 Using

To use specific configuration format the app_config.CONFIG_FILE_NAME variable need to be changed. The default config file format is JSON

Application Configuration

Default config stored in ./configs/ directory in Application dir. To change its location the app_config.CONFIGS_DIR variable need to be changed.

Application config changes to take effect the application need to be restarted.

The Default Application config is:

{
  "monitor": {
    "config": {
      "debug": "false",
      "print_info": "false",
      "interval_seconds": 30,
      "uptime_update_seconds": 60,
      "port": 15200,
      "stop_file_name": "/stop",
      "response_path_separator": "|"
    }
  }
}
  • debug and print_info values need for debug purpose and used to output the debugging information into standard output.
  • interval_seconds - metrics update time in seconds. Indicates how often every metric will be touch to check if its need to be updated. Every metric have its own update interval.
  • uptime_update_seconds - the Application uptime metric update interval in seconds.
  • port - port on which the Exporter's service to be started
  • stop_file_name - if this file name appears in application's directory the Application will be stopped.
  • response_path_separator - the response path separator. Used in rest_value metric configuration.

Metrics Configuration

There are some embedded metrics in the Exporter:

  • Exporter uptime
  • System uptime
  • CPU used percents
  • Memory used percents
  • Chassis temperature
  • CPU temperature

Default config stored in ./configs/config.json file. To change it the app_config.CONFIG_METRICS_FILE_NAME variable need to be changed.

The Default Application config is (no custom metrics are configured):

{
  "monitor": {
    "instance_prefix": "",
    "metrics": {
      "disk": [],
      "health": [],
      "ping": [],
      "iface": [],
      "rest_value": [],
      "shell_value": []
    }
  }
}

instance_prefix - prefix that identifies Instance the Exporter launched on. It used to create the Metric name. May be empty.

The Exporter supports following types of metrics: Common parameters:

  • name - parameter used in every metric to identify it. Required.
  • interval - time interval in seconds the metric will be updated. Required.

Metrics Labels

From version 2.0 the Application supports Labels. See Metrics Names for details.

Internal metrics

From version 2.0 the Application supports internal metrics to collect time. See Metrics Names for details.

Disk (or mount point) Metrics

Monitors the Mount Point's sizes: total, used, free space in bytes

{
  "name": "root",
  "path": "/",
  "interval": 20
}
  • path - FS path to mount point which size will be monitored

Service Health Metrics

Monitors the Service's Health by http request: if 200 code in response - the service is up, otherwise - the service is dn

{
  "name": "google",
  "url": "https://google.com",
  "method": "GET",
  "auth": {
    "user": "",
    "pass": ""
  },
  "headers": {
    "d1": "d1",
    "d2": "d2"
  },
  "interval": 30,
  "timeout": 1
}
  • url - URL to be monitored
  • methd - method to send request
  • auth - authentication section. Optional
    • user - user name
    • pass - user password
  • headers - http headers section to be sent to the host. Optional. The header's key-value pairs will be sent as is.
  • timeout - timeout to wait for response

ICMP (Ping) Metrics

Monitors the Host Health by ping command: if ip address reachable - the service is up, otherwise - the service is dn

{
  "name": "Router",
  "ip": "192.168.0.1",
  "interval": 30,
  "count": 1
}
  • ip - IP Address or DNS name of the host
  • count - pings count

Network Interface Metrics

Monitors the Network Interface metrics: send and receive bytes

{
  "name": "Eth0",
  "iface": "eth0",
  "interval": 15
}
  • iface - system name of network interface (i.e. eth0, lo0, wlp4s0, etc.)

REST value Metrics

Gets the responses value from http request to REST service

{
  "name": "MyService",
  "url": "http://localhost:8080/api/v1/api",
  "method": "POST",
  "auth": {
    "user": "",
    "pass": ""
  },
  "headers": {
    "d1": "d1",
    "d2": "d2"
  },
  "result_type": "single",
  "result_path": "result",
  "interval": 30,
  "timeout": 2
}

Shell value Metrics

Gets the shell command executed result value

{
  "name": "shell",
  "command": "echo",
  "args": [3],
  "interval": 5
}
  • command - command to be executed
  • args - CLI arguments to be provided to the command In example above the metric will return integer value 3.

The metric names: From version 2.0 there are following metric names used

  • das_collect_time_ms - Total time spent collecting metrics in milliseconds; Labels: name, Total time spent collecting metrics [name] on [server] in milliseconds
  • das_disk_bytes - Bytes (total, used, free) on (mount_point) for (server); Labels: total, used, free, mount_point, server
  • das_service_health - Service health; Labels name, url, method, server
  • das_rest_value - Remote REST API Value; Labels name, url, method, server
  • das_shell_value - Shell Value; Labels: name, command, server
  • das_host_available - Host availability; Labels name, ip, server
  • das_net_interface_bytes - Network Interface bytes; Labels: name, server, metric=(sent|receive)
  • das_exporter - Exporter Uptime for server in seconds
  • das_uptime_seconds - System uptime on server
  • das_cpu_percent - CPU used percent on server
  • das_memory_percent - Memory used percent on server
  • das_ChassisTemperature_current - Current Chassis Temperature overall on server
  • das_CpuTemperature_current - Current CPU Temperature overall on server Note: there are no doubles in metrics names supported by Prometheus. If so the exception occurs ant the application will be stopped.

🚀 Launching the application

Use provided install.sh script to prepare application to use as service. Or use following shell commands to initialize the Python's Virtual env.

python3 -m venv .venv
. ./.venv/bin/activate
pip install -r requirements.txt
deactivate

Regular application

In application directory:

. ./.venv/bin/activate
python ./main.py

System service (preferred option)

Prepare the dasExporter.service file. Then launch commands:

sudo ln -s "$( pwd -P )/dasExporter.service" /etc/systemd/system/dasExporter.service
sudo systemctl daemon-reload
sudo systemctl start dasExporter
sudo systemctl enable dasExporter
  • sudo systemctl status dasExporter - to view service status use
  • sudo systemctl restart dasExporter - to restart the service use
  • sudo systemctl stop dasExporter - to stop the service use

Docker application

Use provided docker-compose.yaml and Dockerfile files to launch Exporter in docker container.

Make sure you provided all mounts you need to be monitored in volume section in the docker-compose.yaml file and made according changes in Disc Metrics Configuration.

Note: In Docker some functions may be unavailable.

Made by -=:dAs:=-
Description
Das Simple metrics Exporter for Prometheus
Readme GPL-3.0 131 KiB
Languages
Python 97.9%
Shell 1.3%
Dockerfile 0.8%