physicalmeasurement
package physicalmeasurement
import "chantico/internal/physicalmeasurement"
Index
- Constants
- Variables
- func DeleteTargetFile(ctx context.Context, physicalMeasurement *chantico.PhysicalMeasurement) *sm.ActionResult
- func UpdateState(physicalMeasurement *chantico.PhysicalMeasurement)
- func WriteFileSDTargets(path string, targets []FileSDTarget) error
- func WriteTargetFile(ctx context.Context, physicalMeasurement *chantico.PhysicalMeasurement) *sm.ActionResult
- type FileSDTarget
- type State
Constants
const ( StateInit = "init" StateRunning = "Running" StateRunningWithWarning = "Running (with warning)" StateDelete = "Delete" StateFailed = "Failed" )
Variables
var StateMachine = sm.Machine[*chantico.PhysicalMeasurement]{ Actions: map[string][]sm.ActionFunction[*chantico.PhysicalMeasurement]{ StateInit: { {Type: sm.ActionFunctionPure, Pure: sm.InitializeFinalizer[*chantico.PhysicalMeasurement]}, {Type: sm.ActionFunctionPure, Pure: WriteTargetFile}, }, StateRunning: {}, StateDelete: { {Type: sm.ActionFunctionPure, Pure: DeleteTargetFile}, {Type: sm.ActionFunctionPure, Pure: sm.RemoveFinalizer[*chantico.PhysicalMeasurement]}, }, StateFailed: {}, }, FailState: StateFailed, }
ActionMap defines the actions to execute for each state. With file_sd_configs, Prometheus automatically watches the target files for changes — no explicit reload or config merging is needed.
Functions
func DeleteTargetFile
func DeleteTargetFile( ctx context.Context, physicalMeasurement *chantico.PhysicalMeasurement, ) *sm.ActionResult
DeleteTargetFile removes the file_sd_configs target file for this PhysicalMeasurement. Prometheus will automatically stop scraping the removed targets.
func UpdateState
func UpdateState( physicalMeasurement *chantico.PhysicalMeasurement, )
func WriteFileSDTargets
func WriteFileSDTargets(path string, targets []FileSDTarget) error
WriteFileSDTargets marshals the targets to JSON and writes them to the given path.
func WriteTargetFile
func WriteTargetFile( ctx context.Context, physicalMeasurement *chantico.PhysicalMeasurement, ) *sm.ActionResult
WriteTargetFile writes a file_sd_configs JSON target file for this PhysicalMeasurement. The file is written to prometheus/targets/<name>.json. Prometheus automatically detects changes to these files and updates its scrape targets.
Types
type FileSDTarget
type FileSDTarget struct { Targets []string `json:"targets"` Labels map[string]string `json:"labels"` }
FileSDTarget represents a single target group in Prometheus file_sd_configs format. Prometheus watches these JSON files and automatically picks up changes without needing a reload or restart. See: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config
func CreateFileSDTarget
func CreateFileSDTarget(deviceId string, ip string) FileSDTarget
CreateFileSDTarget creates a file_sd_configs target entry for a PhysicalMeasurement. The labels __param_module and __param_auth are used by the SNMP exporter relabel configs in prometheus.yml to route scrapes through the correct SNMP module.
func LoadFileSDTargets
func LoadFileSDTargets(path string) ([]FileSDTarget, error)
LoadFileSDTargets reads and parses a file_sd_configs JSON file.
type State
type State string