24#include <unordered_map>
55 return "not_charging";
184 auto name() const -> std::string_view
override {
return "battery"; }
185 auto collect() -> std::vector<metric>
override;
186 auto interval() const -> std::chrono::milliseconds
override {
return std::chrono::seconds(30); }
193 .description =
"Battery status metrics (charge, health, temperature)",
197 .requires_platform_support =
true
234 const std::string& unit =
"")
const;
Battery status monitoring collector implementing collector_plugin interface.
std::vector< battery_reading > get_last_readings() const
auto interval() const -> std::chrono::milliseconds override
Get the collection interval for this plugin.
battery_collector & operator=(battery_collector &&)=delete
battery_collector(battery_collector &&)=delete
~battery_collector() override=default
std::atomic< size_t > collection_errors_
std::unique_ptr< battery_info_collector > collector_
std::atomic< size_t > batteries_found_
void shutdown() override
Shutdown plugin and release resources.
std::atomic< size_t > collection_count_
auto get_statistics() const -> stats_map override
Get plugin statistics.
auto initialize(const config_map &config) -> bool override
Initialize plugin with configuration.
bool is_battery_available() const
auto name() const -> std::string_view override
Get the unique name of this plugin.
auto collect() -> std::vector< metric > override
Collect current metrics from this plugin.
auto get_metric_types() const -> std::vector< std::string > override
Get supported metric types.
battery_collector & operator=(const battery_collector &)=delete
metric create_battery_metric(const std::string &name, double value, const battery_reading &reading, const std::string &unit="") const
auto get_metadata() const -> plugin_metadata override
Get plugin metadata.
void add_battery_metrics(std::vector< metric > &metrics, const battery_reading &reading)
std::vector< battery_reading > last_readings_
auto is_available() const -> bool override
Check if this plugin is available on the current system.
battery_collector(const battery_collector &)=delete
Battery data collector using platform abstraction layer.
std::unique_ptr< platform::metrics_provider > provider_
battery_info_collector & operator=(const battery_info_collector &)=delete
battery_info_collector & operator=(battery_info_collector &&)=delete
bool is_battery_available() const
battery_info_collector(const battery_info_collector &)=delete
std::vector< battery_reading > read_all_batteries()
std::vector< battery_info > enumerate_batteries()
~battery_info_collector()
battery_info_collector(battery_info_collector &&)=delete
Pure virtual interface for metric collector plugins.
Plugin interface for metric collectors.
Adapter for metric types to support interface definitions.
std::unordered_map< std::string, double > stats_map
Type alias for statistics map.
battery_status
Current battery charging status.
@ charging
Battery is charging.
@ not_charging
Battery is not charging (plugged in but not charging)
@ discharging
Battery is discharging.
@ full
Battery is fully charged.
@ hardware
Hardware sensors (GPU, temperature, battery, power)
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
@ platform
Platform/system power domain.
std::string battery_status_to_string(battery_status status)
Convert battery_status to string representation.
Information about a battery source.
std::string serial
Battery serial number.
std::string manufacturer
Battery manufacturer.
std::string model
Battery model name.
std::string technology
Battery technology (e.g., Li-ion, Li-poly)
std::string path
Platform-specific path (e.g., /sys/class/power_supply/BAT0)
std::string name
Human-readable battery name.
std::string id
Unique battery identifier (e.g., "BAT0")
A single battery reading.
std::chrono::system_clock::time_point timestamp
Reading timestamp.
double current_amps
Current in Amps (positive=charging)
bool ac_connected
True if AC power is connected.
double temperature_celsius
Battery temperature in Celsius.
double design_capacity_wh
Original design capacity in Wh.
battery_status status
Current charging status.
int64_t cycle_count
Battery charge cycles (-1 if unavailable)
int64_t time_to_empty_seconds
Estimated time to empty (-1 if unavailable)
double full_charge_capacity_wh
Current full charge capacity in Wh.
int64_t time_to_full_seconds
Estimated time to full (-1 if unavailable)
battery_info info
Battery information.
double level_percent
Current charge percentage (0-100)
bool battery_present
Whether battery is present.
bool is_charging
True if battery is charging.
bool temperature_available
Whether temperature is available.
double current_capacity_wh
Current energy stored in Wh.
double power_watts
Current power in Watts.
double health_percent
Battery health (full_charge/design * 100)
double voltage_volts
Current voltage in Volts.
bool metrics_available
Whether metrics are available.
Basic metric structure for interface compatibility.