|
| 1 | +# Prometheus Extractor for Energy Consumption Metrics |
| 2 | + |
| 3 | +This document provides information on using the Prometheus extractor to gather energy consumption metrics in cASO. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Prometheus extractor queries a Prometheus instance to retrieve energy consumption metrics and generates `EnergyRecord` objects that can be published through cASO's messenger system. |
| 8 | + |
| 9 | +## Configuration |
| 10 | + |
| 11 | +To use the Prometheus extractor, add the following configuration to your `caso.conf` file: |
| 12 | + |
| 13 | +```ini |
| 14 | +[DEFAULT] |
| 15 | +# Add prometheus to your list of extractors |
| 16 | +extractor = nova,cinder,prometheus |
| 17 | +
|
| 18 | +[prometheus] |
| 19 | +# Prometheus server endpoint URL |
| 20 | +prometheus_endpoint = http://localhost:9090 |
| 21 | +
|
| 22 | +# PromQL query to retrieve energy consumption in kWh |
| 23 | +# This is the default query - customize it based on your Prometheus metrics |
| 24 | +prometheus_query = sum(rate(node_energy_joules_total[5m])) * 300 / 3600000 |
| 25 | +
|
| 26 | +# Timeout for Prometheus API requests (in seconds) |
| 27 | +prometheus_timeout = 30 |
| 28 | +``` |
| 29 | + |
| 30 | +## Customizing the PromQL Query |
| 31 | + |
| 32 | +The default query assumes you have a metric called `node_energy_joules_total` that tracks energy consumption in joules. The query: |
| 33 | + |
| 34 | +1. Calculates the rate of energy consumption over 5 minutes |
| 35 | +2. Multiplies by 300 (5 minutes in seconds) to get total joules |
| 36 | +3. Divides by 3,600,000 to convert from joules to kWh |
| 37 | + |
| 38 | +You should customize this query based on your specific Prometheus metrics and requirements. |
| 39 | + |
| 40 | +### Example Queries |
| 41 | + |
| 42 | +**For IPMI power metrics:** |
| 43 | +```promql |
| 44 | +sum(ipmi_power_watts) * 5 * 60 / 1000 / 3600 |
| 45 | +``` |
| 46 | + |
| 47 | +**For RAPL energy metrics:** |
| 48 | +```promql |
| 49 | +sum(rate(node_rapl_package_joules_total[5m])) * 300 / 3600000 |
| 50 | +``` |
| 51 | + |
| 52 | +**For Scaphandre metrics:** |
| 53 | +```promql |
| 54 | +sum(rate(scaph_host_power_microwatts[5m])) * 300 / 1000000 / 3600 |
| 55 | +``` |
| 56 | + |
| 57 | +## Energy Record Format |
| 58 | + |
| 59 | +The Prometheus extractor generates `EnergyRecord` objects with the following fields: |
| 60 | + |
| 61 | +- `uuid`: Unique identifier for the record |
| 62 | +- `measurement_time`: Timestamp when the measurement was taken |
| 63 | +- `site_name`: Name of the site (from configuration) |
| 64 | +- `user_id`: User identifier (optional for energy records) |
| 65 | +- `group_id`: Project/group identifier |
| 66 | +- `user_dn`: User Distinguished Name (optional) |
| 67 | +- `fqan`: Fully Qualified Attribute Name (VO mapping) |
| 68 | +- `energy_consumption`: Energy consumption value (in kWh) |
| 69 | +- `energy_unit`: Unit of measurement (default: "kWh") |
| 70 | +- `compute_service`: Service name (from configuration) |
| 71 | + |
| 72 | +## Integration with Messengers |
| 73 | + |
| 74 | +Energy records can be published through any cASO messenger, just like other record types: |
| 75 | + |
| 76 | +```ini |
| 77 | +[DEFAULT] |
| 78 | +messengers = ssm,logstash |
| 79 | +``` |
| 80 | + |
| 81 | +The records will be serialized as JSON with field mapping according to the accounting standards. |
| 82 | + |
| 83 | +## Testing |
| 84 | + |
| 85 | +To test your Prometheus extractor configuration: |
| 86 | + |
| 87 | +1. Verify Prometheus is accessible from cASO |
| 88 | +2. Test your PromQL query directly in Prometheus |
| 89 | +3. Run cASO with the `--dry-run` option to preview records without publishing |
| 90 | +4. Check the logs for any errors or warnings |
| 91 | + |
| 92 | +## Example |
| 93 | + |
| 94 | +Here's a complete example configuration: |
| 95 | + |
| 96 | +```ini |
| 97 | +[DEFAULT] |
| 98 | +extractor = prometheus |
| 99 | +site_name = MY-SITE |
| 100 | +service_name = MY-SITE-CLOUD |
| 101 | +messengers = ssm |
| 102 | +
|
| 103 | +[prometheus] |
| 104 | +prometheus_endpoint = http://prometheus.example.com:9090 |
| 105 | +prometheus_query = sum(rate(node_energy_joules_total[5m])) * 300 / 3600000 |
| 106 | +prometheus_timeout = 30 |
| 107 | +
|
| 108 | +[ssm] |
| 109 | +output_path = /var/spool/apel/outgoing/openstack |
| 110 | +``` |
| 111 | + |
| 112 | +## Troubleshooting |
| 113 | + |
| 114 | +**No records extracted:** |
| 115 | +- Verify Prometheus is accessible |
| 116 | +- Check that your query returns results in Prometheus UI |
| 117 | +- Ensure the time range (extract_from/extract_to) covers periods with data |
| 118 | + |
| 119 | +**Connection timeout:** |
| 120 | +- Increase `prometheus_timeout` value |
| 121 | +- Check network connectivity to Prometheus |
| 122 | +- Verify Prometheus is not overloaded |
| 123 | + |
| 124 | +**Invalid query results:** |
| 125 | +- Ensure your query returns numeric values |
| 126 | +- Check the query format matches PromQL syntax |
| 127 | +- Verify the metrics exist in your Prometheus instance |
0 commit comments