Created
August 1, 2023 10:40
-
-
Save kadoshita/3c3aed4958f27e92f41fe7ce129893cb to your computer and use it in GitHub Desktop.
OMURONのUPSのデータをPrometheusのtextfile collector用のフォーマットに変換するPowerShellスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LogFileDir="C:\Program Files (x86)\PowerAct Pro(Master Agent)\Datalog\2\" | |
function GetLatestFileName(){ | |
return (Get-ChildItem -Path $LogFileDir*.csv | Sort-Object LastWriteTime -Descending)[0].FullName | |
} | |
function GetLastRow(){ | |
$filename = GetLatestFileName | |
return (Get-Content $filename)[-1] | |
} | |
$UNIX_EPOCH = Get-Date("1970/1/1 0:0:0 GMT") | |
$row = ((GetLastRow) -split ",") | |
$inputVoltage = $row[1] | |
$outputVoltage = $row[2] | |
$inputHertz = $row[3] | |
$outputHertz = $row[4] | |
$loadCapacity = $row[5] | |
$temperature = $row[6] | |
$backupTime = $row[7] | |
$batteryVoltage = $row[8] | |
$batteryCapacity = $row[9] | |
$logfilename="ups.prom" | |
Set-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_input_voltage $inputVoltage`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_output_voltage $outputVoltage`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_input_hertz $inputHertz`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_output_hertz $outputHertz`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_load_capacity $loadCapacity`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_temperature $temperature`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_backup_time $backupTime`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_battery_voltage $batteryVoltage`n" | |
Add-Content -Path $logfilename -Encoding Ascii -NoNewline -Value "ups_battery_capacity $batteryCapacity`n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment