4 Commits

Author SHA1 Message Date
github-actions[bot]
39e3b69c82 chore(main): release 0.0.5 (#6)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-12-16 04:43:57 +00:00
148994ca50 docs(readme): add link to go docs 2023-12-16 04:42:02 +00:00
436e4a4b01 feat(go): rename prom package to suitable prombat 2023-12-16 04:38:30 +00:00
24bd7d6af3 docs(readme): update example output 2023-12-16 03:23:36 +00:00
7 changed files with 32 additions and 26 deletions

View File

@@ -1,3 +1,3 @@
{ {
".": "0.0.4" ".": "0.0.5"
} }

View File

@@ -16,6 +16,7 @@ jobs:
- name: Print version - name: Print version
run: | run: |
./bin/macos-battery-exporter -v ./bin/macos-battery-exporter -v
./bin/macos-battery-exporter
lint: lint:
name: Lint name: Lint

View File

@@ -1,5 +1,12 @@
# Changelog # Changelog
## [0.0.5](https://github.com/jimeh/macos-battery-exporter/compare/v0.0.4...v0.0.5) (2023-12-16)
### Features
* **go:** rename prom package to suitable prombat ([436e4a4](https://github.com/jimeh/macos-battery-exporter/commit/436e4a4b01d96654b7012f795f2d305ca4084681))
## [0.0.4](https://github.com/jimeh/macos-battery-exporter/compare/v0.0.3...v0.0.4) (2023-12-16) ## [0.0.4](https://github.com/jimeh/macos-battery-exporter/compare/v0.0.3...v0.0.4) (2023-12-16)

View File

@@ -10,6 +10,7 @@
<p align="center"> <p align="center">
<a href="https://github.com/jimeh/macos-battery-exporter/releases"><img src="https://img.shields.io/github/v/tag/jimeh/macos-battery-exporter?label=release" alt="GitHub tag (latest SemVer)"></a> <a href="https://github.com/jimeh/macos-battery-exporter/releases"><img src="https://img.shields.io/github/v/tag/jimeh/macos-battery-exporter?label=release" alt="GitHub tag (latest SemVer)"></a>
<a href="https://pkg.go.dev/github.com/jimeh/macos-battery-exporter"><img src="https://img.shields.io/badge/%E2%80%8B-reference-387b97.svg?logo=go&logoColor=white" alt="Go Reference"></a>
<a href="https://github.com/jimeh/macos-battery-exporter/issues"><img src="https://img.shields.io/github/issues-raw/jimeh/macos-battery-exporter.svg?style=flat&logo=github&logoColor=white" alt="GitHub issues"></a> <a href="https://github.com/jimeh/macos-battery-exporter/issues"><img src="https://img.shields.io/github/issues-raw/jimeh/macos-battery-exporter.svg?style=flat&logo=github&logoColor=white" alt="GitHub issues"></a>
<a href="https://github.com/jimeh/macos-battery-exporter/pulls"><img src="https://img.shields.io/github/issues-pr-raw/jimeh/macos-battery-exporter.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests"></a> <a href="https://github.com/jimeh/macos-battery-exporter/pulls"><img src="https://img.shields.io/github/issues-pr-raw/jimeh/macos-battery-exporter.svg?style=flat&logo=github&logoColor=white" alt="GitHub pull requests"></a>
<a href="https://github.com/jimeh/macos-battery-exporter/blob/main/LICENSE"><img src="https://img.shields.io/github/license/jimeh/macos-battery-exporter.svg?style=flat" alt="License Status"></a> <a href="https://github.com/jimeh/macos-battery-exporter/blob/main/LICENSE"><img src="https://img.shields.io/github/license/jimeh/macos-battery-exporter.svg?style=flat" alt="License Status"></a>
@@ -89,19 +90,22 @@ macos-battery-exporter
macos_battery_cell_disconnect_count{serial="ZTMDHJEZ8JKMYVAJKU"} 0 macos_battery_cell_disconnect_count{serial="ZTMDHJEZ8JKMYVAJKU"} 0
# HELP macos_battery_charge_rate_amps Current charge rate in Ah. # HELP macos_battery_charge_rate_amps Current charge rate in Ah.
# TYPE macos_battery_charge_rate_amps gauge # TYPE macos_battery_charge_rate_amps gauge
macos_battery_charge_rate_amps{serial="ZTMDHJEZ8JKMYVAJKU"} -0.927 macos_battery_charge_rate_amps{serial="ZTMDHJEZ8JKMYVAJKU"} -1.004
# HELP macos_battery_charge_rate_watts Current charge rate in Wh. # HELP macos_battery_charge_rate_watts Current charge rate in Wh.
# TYPE macos_battery_charge_rate_watts gauge # TYPE macos_battery_charge_rate_watts gauge
macos_battery_charge_rate_watts{serial="ZTMDHJEZ8JKMYVAJKU"} -10.297116 macos_battery_charge_rate_watts{serial="ZTMDHJEZ8JKMYVAJKU"} -12.712648
# HELP macos_battery_count Total number of batteries.
# TYPE macos_battery_count gauge
macos_battery_count 1
# HELP macos_battery_current_capacity_amps Current charge capacity in Ah. # HELP macos_battery_current_capacity_amps Current charge capacity in Ah.
# TYPE macos_battery_current_capacity_amps gauge # TYPE macos_battery_current_capacity_amps gauge
macos_battery_current_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 1.127 macos_battery_current_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 5.39
# HELP macos_battery_current_capacity_watts Current charge capacity in Wh. # HELP macos_battery_current_capacity_watts Current charge capacity in Wh.
# TYPE macos_battery_current_capacity_watts gauge # TYPE macos_battery_current_capacity_watts gauge
macos_battery_current_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 12.518716 macos_battery_current_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 68.24818
# HELP macos_battery_current_percentage Current battery charge percentage. # HELP macos_battery_current_percentage Current battery charge percentage.
# TYPE macos_battery_current_percentage gauge # TYPE macos_battery_current_percentage gauge
macos_battery_current_percentage{serial="ZTMDHJEZ8JKMYVAJKU"} 18 macos_battery_current_percentage{serial="ZTMDHJEZ8JKMYVAJKU"} 91
# HELP macos_battery_cycle_count Current battery cycle count. # HELP macos_battery_cycle_count Current battery cycle count.
# TYPE macos_battery_cycle_count counter # TYPE macos_battery_cycle_count counter
macos_battery_cycle_count{serial="ZTMDHJEZ8JKMYVAJKU"} 15 macos_battery_cycle_count{serial="ZTMDHJEZ8JKMYVAJKU"} 15
@@ -110,7 +114,7 @@ macos_battery_cycle_count{serial="ZTMDHJEZ8JKMYVAJKU"} 15
macos_battery_design_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 6.249 macos_battery_design_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 6.249
# HELP macos_battery_design_capacity_watts Design capacity in Wh. # HELP macos_battery_design_capacity_watts Design capacity in Wh.
# TYPE macos_battery_design_capacity_watts gauge # TYPE macos_battery_design_capacity_watts gauge
macos_battery_design_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 69.413892 macos_battery_design_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 79.124838
# HELP macos_battery_fully_charged Indicates if the battery is fully charged. # HELP macos_battery_fully_charged Indicates if the battery is fully charged.
# TYPE macos_battery_fully_charged gauge # TYPE macos_battery_fully_charged gauge
macos_battery_fully_charged{serial="ZTMDHJEZ8JKMYVAJKU"} 0 macos_battery_fully_charged{serial="ZTMDHJEZ8JKMYVAJKU"} 0
@@ -125,19 +129,19 @@ macos_battery_info{built_in="true",device_name="ayzo3hgs",serial="ZTMDHJEZ8JKMYV
macos_battery_is_charging{serial="ZTMDHJEZ8JKMYVAJKU"} 0 macos_battery_is_charging{serial="ZTMDHJEZ8JKMYVAJKU"} 0
# HELP macos_battery_max_capacity_amps Design capacity in Ah. # HELP macos_battery_max_capacity_amps Design capacity in Ah.
# TYPE macos_battery_max_capacity_amps gauge # TYPE macos_battery_max_capacity_amps gauge
macos_battery_max_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 6.262 macos_battery_max_capacity_amps{serial="ZTMDHJEZ8JKMYVAJKU"} 6.271
# HELP macos_battery_max_capacity_watts Design capacity in Wh. # HELP macos_battery_max_capacity_watts Design capacity in Wh.
# TYPE macos_battery_max_capacity_watts gauge # TYPE macos_battery_max_capacity_watts gauge
macos_battery_max_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 69.558296 macos_battery_max_capacity_watts{serial="ZTMDHJEZ8JKMYVAJKU"} 79.403402
# HELP macos_battery_temperature_celsius Current battery temperature in °C. # HELP macos_battery_temperature_celsius Current battery temperature in °C.
# TYPE macos_battery_temperature_celsius gauge # TYPE macos_battery_temperature_celsius gauge
macos_battery_temperature_celsius{serial="ZTMDHJEZ8JKMYVAJKU"} 30.47 macos_battery_temperature_celsius{serial="ZTMDHJEZ8JKMYVAJKU"} 30.53
# HELP macos_battery_time_remaining_seconds Estimated time remaining until battery is fully charged or discharged. # HELP macos_battery_time_remaining_seconds Estimated time remaining until battery is fully charged or discharged.
# TYPE macos_battery_time_remaining_seconds gauge # TYPE macos_battery_time_remaining_seconds gauge
macos_battery_time_remaining_seconds{serial="ZTMDHJEZ8JKMYVAJKU"} 3540 macos_battery_time_remaining_seconds{serial="ZTMDHJEZ8JKMYVAJKU"} 14040
# HELP macos_battery_voltage_volts Current battery voltage in V. # HELP macos_battery_voltage_volts Current battery voltage in V.
# TYPE macos_battery_voltage_volts gauge # TYPE macos_battery_voltage_volts gauge
macos_battery_voltage_volts{serial="ZTMDHJEZ8JKMYVAJKU"} 11.108 macos_battery_voltage_volts{serial="ZTMDHJEZ8JKMYVAJKU"} 12.662
``` ```
### Write to File ### Write to File

10
main.go
View File

@@ -10,7 +10,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/jimeh/macos-battery-exporter/prom" "github.com/jimeh/macos-battery-exporter/prombat"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
) )
@@ -28,7 +28,7 @@ var (
) )
portFlag = flag.Int("p", 9108, "Port to run server on") portFlag = flag.Int("p", 9108, "Port to run server on")
namespaceFlag = flag.String( namespaceFlag = flag.String(
"n", prom.DefaultNamespace, "Namespace for metrics", "n", prombat.DefaultNamespace, "Namespace for metrics",
) )
logLevelFlag = flag.String("l", "info", "Log level") logLevelFlag = flag.String("l", "info", "Log level")
versionFlag = flag.Bool("v", false, "Print version and exit") versionFlag = flag.Bool("v", false, "Print version and exit")
@@ -54,12 +54,12 @@ func mainE() error {
} }
if *serverFlag { if *serverFlag {
opts := prom.ServerOptions{ opts := prombat.ServerOptions{
Bind: *bindFlag, Bind: *bindFlag,
Port: *portFlag, Port: *portFlag,
} }
return prom.RunServer( return prombat.RunServer(
*namespaceFlag, *namespaceFlag,
prometheus.DefaultRegisterer.(*prometheus.Registry), prometheus.DefaultRegisterer.(*prometheus.Registry),
opts, opts,
@@ -67,7 +67,7 @@ func mainE() error {
} }
registry := prometheus.NewRegistry() registry := prometheus.NewRegistry()
err = registry.Register(prom.NewCollector(*namespaceFlag)) err = registry.Register(prombat.NewCollector(*namespaceFlag))
if err != nil { if err != nil {
return err return err
} }

View File

@@ -1,6 +1,6 @@
//go:build darwin //go:build darwin
package prom package prombat
import ( import (
"log/slog" "log/slog"

View File

@@ -1,6 +1,6 @@
//go:build darwin //go:build darwin
package prom package prombat
import ( import (
"fmt" "fmt"
@@ -14,23 +14,17 @@ import (
const DefaultNamespace = "macos" const DefaultNamespace = "macos"
type Registry interface {
prometheus.Registerer
prometheus.Gatherer
}
type ServerOptions struct { type ServerOptions struct {
Bind string Bind string
Port int Port int
ReadTimeout time.Duration ReadTimeout time.Duration
WriteTimeout time.Duration WriteTimeout time.Duration
IdleTimeout time.Duration IdleTimeout time.Duration
Logger *slog.Logger
} }
type Server struct { type Server struct {
*http.Server *http.Server
registry Registry registry *prometheus.Registry
mux *http.ServeMux mux *http.ServeMux
} }