Reviewed-on: #4 v.2.0: Refactored all metrics Added labels Added self measured metrics Updated README.md
Das Simple Exporter
Das Simple metrics Exporter for Prometheus
💡 Purpose
Create configurable lightweight application to collect some metrics
📃 Features
- lightweight and system resources friendly
- configurable application
- configurable metrics to be collected
- supported several metric types
- hot reload metrics if configuration changed
- could be used as regular application, as systemctl service or a Docker application
- supports JSON, PROPERTIES and YAML configuration formats
- internal metrics to show how time spent on update every other metrics
- metrics labels support
📌 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": "|"
}
}
}
debugandprint_infovalues 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 startedstop_file_name- if this file name appears in application's directory the Application will be stopped.response_path_separator- the response path separator. Used inrest_valuemetric 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 monitoredmethd- method to send requestauth- authentication section. Optionaluser- user namepass- 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 hostcount- 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
}
url- URL to be monitoredmethd- method to send requestauth- authentication section. Optionaluser- user namepass- user password
headers- http headers section to be sent to the host. Optional. The header's key-value pairs will be sent as is.result_type- type of result. Thesingletype supported yet.result_path- path to result value in response JSON separated byapp_config.RESPONSE_PATH_SEPARATORcharacter. Could be configured in Application config.timeout- timeout to wait for response
Shell value Metrics
Gets the shell command executed result value
{
"name": "shell",
"command": "echo",
"args": [3],
"interval": 5
}
command- command to be executedargs- 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 millisecondsdas_disk_bytes- Bytes (total, used, free) on (mount_point) for (server); Labels: total, used, free, mount_point, serverdas_service_health- Service health; Labels name, url, method, serverdas_rest_value- Remote REST API Value; Labels name, url, method, serverdas_shell_value- Shell Value; Labels: name, command, serverdas_host_available- Host availability; Labels name, ip, serverdas_net_interface_bytes- Network Interface bytes; Labels: name, server, metric=(sent|receive)das_exporter- Exporter Uptime for server in secondsdas_uptime_seconds- System uptime on serverdas_cpu_percent- CPU used percent on serverdas_memory_percent- Memory used percent on serverdas_ChassisTemperature_current- Current Chassis Temperature overall on serverdas_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 usesudo systemctl restart dasExporter- to restart the service usesudo 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.