script and pformat

This commit is contained in:
samuel 2019-07-25 16:11:29 +02:00
parent dd5d596aa4
commit 7d3544f44e
10 changed files with 248 additions and 21 deletions

BIN
.convert.swp Normal file

Binary file not shown.

BIN
.pformat.swp Normal file

Binary file not shown.

2
awk1
View file

@ -1,2 +1,2 @@
pwrstat -status | awk '{ print "12345," $0; }' > ups pwrstat -status | awk '{ print $0; }' > ups

10
convert Normal file
View file

@ -0,0 +1,10 @@
State........................ Normal
Power Supply by.............. Utility Power
Utility Voltage.............. 237 V
Output Voltage............... 237 V
Battery Capacity............. 100 %
Remaining Runtime............ 100 min.
Load......................... 0 Watt(0 %)
Line Interaction............. None
Test Result.................. Unknown
Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min.

77
exporter Normal file
View file

@ -0,0 +1,77 @@
{
"properties": {
"model": {
"regex": "^\\s+Model Name\\.+ ([0-9A-Z]+)$"
},
},
"voltage": {
"regex": "^\\s+Rating Voltage\\.+ ([0-9]+) V$"
},
"wattage": {
"regex": "^\\s+Rating Power\\.+ ([0-9]+) Watt$"
}
},
"metrics": {
"state": {
"regex": "^\\s+State\\.+ ([A-Za-z ]+)$",
"index": [
"Normal",
"Power Failure"
],
"help": "The current state of the UPS.",
"type": "gauge"
},
"supply": {
"regex": "^\\s+Power Supply by\\.+ ([A-Za-z ])$",
"index": [
"Utility Power",
"Battery Power"
],
"help": "The current power source.",
"type": "gauge"
},
"in_volts": {
"regex": "^\\s+Utility Voltage\\.+ ([0-9]+) V$",
"help": "Input voltage measurement",
"type": "gauge"
},
"out_volts": {
"regex": "^\\s+Output Voltage\\.+ ([0-9]+) V$",
"help": "Output voltage measurement",
"type": "gauge"
},
"capacity": {
"regex": "^\\s+Battery Capacity\\.+ ([0-9]+) %$",
"help": "Remaining battery charge capacity.",
"type": "gauge"
},
"runtime": {
"regex": "^\\s+Remaining Runtime\\.+ ([0-9]+) ([a-z]+)\\.$",
"eval": "int(regex.group(1))*dict(min=60,sec=1).get(regex.group(2))",
"help": "Estimated remaining battery runtime in seconds.",
"type": "gauge"
},
"load": {
"regex": "^\\s+Load\\.+ ([0-9]+) Watt\\([0-9]+ %\\)$",
"help": "The current load on the UPS in watts.",
"type": "gauge"
},
"test_result": {
"regex": "^\\s+Test Result\\.+ ([A-Za-z]+)(?: at [0-9:/ ]+)$",
"index": [
"Passed",
"Failed",
"Unknown"
],
"help": "The test result of the last self test.",
"type": "gauge"
},
"test_age": {
"regex": "^\\s+Test Result\\.+ [A-Za-z]+ at ([0-9:/ ]+)$",
"eval": "int((datetime.now()-datetime.strptime(regex.group(1),'%Y/%m/%d %H:%M:%S')).total_seconds())",
"help": "The number of seconds since the last self test.",
"type": "gauge"
}
}
}

69
pformat Normal file
View file

@ -0,0 +1,69 @@
# HELP go_State.
# TYPE go_state gauge
#state _normal
# HELP go_Power_supply_by.
# TYPE go_Power_supply_by gauge
#go_utility_Power
# HELP Utility_Voltage.
# TYPE go_Utility_Voltage gauge
#go_235_V
# HELP Output_Voltage.
# TYPE Output_Voltage gauge
#go_235_V
# HELP Battery_Capacity.
# TYPE Battery_Capacity gauge
#go_100%
#battery_capacity_percentage 100
# HELP Remaining_Runtime.
# TYPE Remaining_Runtime gauge
#go_100_min
# HELP Load.
# TYPE Load gauge
#go_0_Watt_(0%)
# HELP Line_Interaction.
# TYPE Line_Interaction gauge
#go_None
# HELP Test_Result.
# TYPE Test_Result gauge
#go_Unknown
# HELP Last_Power_Event.
# TYPE Last_Power_Event gauge
#go_Blackout_at_2019/07/23_10:14:07_for_72_min#
#The followin is the prod script
ups_state {"normal"} 1
ups_battery_capacity_percentage 100
ups_Power_supply_by {"utility_power"} 1
ups_utility_voltage 235
ups_battery_capacity_percentage 100
ups_remaining_runtime_per_min 100
ups_load_watt 0
ups_load_percentage 0
ups_line_interaction {"none"} 1
ups_last_power_event {"blackout"} 1

View file

@ -1,3 +1,32 @@
pwrstat -status | grep -E 'State|Power Supply by|Utility Voltage|Output Voltage|Battery Capacity|Remaining Runtime|Load|Line Interaction|Test Result|Last Power Event' > ups pwrstat -status | grep -E 'State|Power Supply by|Utility Voltage|Output Voltage|Battery Capacity|Remaining Runtime|Load|Line Interaction|Test Result|Last Power Event' > ups
pwrstat -status "State... Normal" | grep State | sed 's/[.]*//g' | tr 'A-Z' 'a-z' | sed -e '$
state{"normal"} 1
pwrstat -status "Power Supply by... Utility Power" | grep Power Supply by | sed 's/[.]*//g' $
Power Supply by{"utility power"} 1
pwrstat -status "Utility Voltage... 237 V" | grep Utility Voltage | sed 's/[.]*//g' | tr 'A-$
Utility Voltage{"normal"} 1
pwrstat -status "Output Voltage... 237 V" | grep Output Voltage | sed 's/[.]*//g' | tr 'A-Z$
output voltage{"237"} 1
pwrstat -status "Remaining Runtime... 100 min" | grep Remaining Runtime | sed 's/[.]*//g' | $
Remaining Runtime{"100"} 1
pwrstat -status "Load" | grep Load | sed 's/[.]*//g' | t$
load{"0"} 1
pwrstat -status "Line Interaction... None" | grep Line Interaction | sed 's/[.]*//g' | t$
line interaction{"none"} 1
pwrstat -status "Test Result... Unknown" | grep Test Result | sed 's/[.]*//g' | t$
Test Result{"unknown"} 1
pwrstat -status "Last Power Event...Blackout at 2019/07/23 10:14:07 for 72 min
" | grep Last Power Event | sed 's/[.]*//g' | t$
Last Power Event{"backout"} 1

40
ups
View file

@ -1,20 +1,20 @@
12345,
12345,The UPS information shows as following: The UPS information shows as following:
12345,
12345, Properties: Properties:
12345, Model Name................... Value2200E Model Name................... Value2200E
12345, Rating Voltage............... 230 V Rating Voltage............... 230 V
12345, Rating Power................. 1320 Watt(2200 VA) Rating Power................. 1320 Watt(2200 VA)
12345,
12345, Current UPS status: Current UPS status:
12345, State........................ Normal State........................ Normal
12345, Power Supply by.............. Utility Power Power Supply by.............. Utility Power
12345, Utility Voltage.............. 235 V Utility Voltage.............. 235 V
12345, Output Voltage............... 235 V Output Voltage............... 235 V
12345, Battery Capacity............. 100 % Battery Capacity............. 100 %
12345, Remaining Runtime............ 100 min. Remaining Runtime............ 100 min.
12345, Load......................... 0 Watt(0 %) Load......................... 0 Watt(0 %)
12345, Line Interaction............. None Line Interaction............. None
12345, Test Result.................. Unknown Test Result.................. Unknown
12345, Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min. Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min.
12345,

22
ups.save Normal file
View file

@ -0,0 +1,22 @@
The UPS information shows as following:
Properties:
Model Name................... Value2200E
Rating Voltage............... 230 V
Rating Power................. 1320 Watt(2200 VA)
Current UPS status:
State........................ Normal
Power Supply by.............. Utility Power
Utility Voltage.............. 235 V
Output Voltage............... 235 V
Battery Capacity............. 100 %
Remaining Runtime............ 100 min.
Load......................... 0 Watt(0 %)
Line Interaction............. None
Test Result.................. Unknown
Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min.

20
ups.save.1 Normal file
View file

@ -0,0 +1,20 @@
The UPS information shows as following:
Properties:
Model Name................... Value2200E
Rating Voltage............... 230 V
Rating Power................. 1320 Watt(2200 VA)
Current UPS status:
State........................ Normal
Power Supply by.............. Utility Power
Utility Voltage.............. 235 V
Output Voltage............... 235 V
Battery Capacity............. 100 %
Remaining Runtime............ 100 min.
Load......................... 0 Watt(0 %)
Line Interaction............. None
Test Result.................. Unknown
Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min.