diff --git a/.convert.swp b/.convert.swp new file mode 100644 index 0000000..824d470 Binary files /dev/null and b/.convert.swp differ diff --git a/.pformat.swp b/.pformat.swp new file mode 100644 index 0000000..b5c3cd1 Binary files /dev/null and b/.pformat.swp differ diff --git a/awk1 b/awk1 index 67ccf5a..c40112c 100644 --- a/awk1 +++ b/awk1 @@ -1,2 +1,2 @@ -pwrstat -status | awk '{ print "12345," $0; }' > ups +pwrstat -status | awk '{ print $0; }' > ups diff --git a/convert b/convert new file mode 100644 index 0000000..5922eb7 --- /dev/null +++ b/convert @@ -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. diff --git a/exporter b/exporter new file mode 100644 index 0000000..050704c --- /dev/null +++ b/exporter @@ -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" + } + } +} diff --git a/pformat b/pformat new file mode 100644 index 0000000..168a8c7 --- /dev/null +++ b/pformat @@ -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 diff --git a/script1.sh b/script1.sh index 05443d8..7a23f58 100755 --- a/script1.sh +++ b/script1.sh @@ -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 "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 + diff --git a/ups b/ups index 35ee880..49aa8ed 100644 --- a/ups +++ b/ups @@ -1,20 +1,20 @@ -12345, -12345,The UPS information shows as following: -12345, -12345, Properties: -12345, Model Name................... Value2200E -12345, Rating Voltage............... 230 V -12345, Rating Power................. 1320 Watt(2200 VA) -12345, -12345, Current UPS status: -12345, State........................ Normal -12345, Power Supply by.............. Utility Power -12345, Utility Voltage.............. 235 V -12345, Output Voltage............... 235 V -12345, Battery Capacity............. 100 % -12345, Remaining Runtime............ 100 min. -12345, Load......................... 0 Watt(0 %) -12345, Line Interaction............. None -12345, Test Result.................. Unknown -12345, Last Power Event............. Blackout at 2019/07/23 10:14:07 for 72 min. -12345, + +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. + diff --git a/ups.save b/ups.save new file mode 100644 index 0000000..231796b --- /dev/null +++ b/ups.save @@ -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. + diff --git a/ups.save.1 b/ups.save.1 new file mode 100644 index 0000000..49aa8ed --- /dev/null +++ b/ups.save.1 @@ -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. +