Creating charts for my UPS metrics - Part 2

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












Following up from my previous question




Streaming my UPS metrics for graphical viewing in bash




#!/usr/bin/env bash

[ -v METRICS_CHECK ] && set -x

API_URL="https://api.thingspeak.com/update"
UPS_PROPS=("LINEV" "LOADPCT" "TIMELEFT")
API_PARAMS=("api_key==XXXXXXXXXXXXXX")

for index in "$!UPS_PROPS[@]"
do
value=$(/sbin/apcaccess -up "$UPS_PROPS[$index]")
field=$((index + 1))
if [ "$field" -eq 2 ]
then
# bc required for floating point arithmetic
value=$(echo "$value * 6" | bc) # 600 Watt * load percent
fi
PARAM=$(printf "field%d==%s" "$field" "$value")
API_PARAMS+=("$PARAM")
done

/usr/local/bin/http "$API_URL" $API_PARAMS[@]


Updates:



  • Collects data for different metrics supported by apcaccess

  • Use a variable check for enabling debug mode

  • Split parameters sent to API URL into a different array

  • Move away from curl to use httpie

  • Custom computation for certain attributes


The shellcheck passes everything except the unquoted $API_PARAMS[@] in the last line. I am not sure that httpie would work if I quote that and pass it as a single argument.




Charts for viewing pleasure (last 600 minutes data from the time post was created):




  1. Input line voltage



    LINEV




  2. Load (in wattage) on the UPS



    LOADPCT




  3. Battery time left for the UPS



    TIMELEFT



Click the images to get live charts.







share|improve this question

















  • 1




    Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
    – Toby Speight
    Apr 17 at 7:50
















up vote
3
down vote

favorite












Following up from my previous question




Streaming my UPS metrics for graphical viewing in bash




#!/usr/bin/env bash

[ -v METRICS_CHECK ] && set -x

API_URL="https://api.thingspeak.com/update"
UPS_PROPS=("LINEV" "LOADPCT" "TIMELEFT")
API_PARAMS=("api_key==XXXXXXXXXXXXXX")

for index in "$!UPS_PROPS[@]"
do
value=$(/sbin/apcaccess -up "$UPS_PROPS[$index]")
field=$((index + 1))
if [ "$field" -eq 2 ]
then
# bc required for floating point arithmetic
value=$(echo "$value * 6" | bc) # 600 Watt * load percent
fi
PARAM=$(printf "field%d==%s" "$field" "$value")
API_PARAMS+=("$PARAM")
done

/usr/local/bin/http "$API_URL" $API_PARAMS[@]


Updates:



  • Collects data for different metrics supported by apcaccess

  • Use a variable check for enabling debug mode

  • Split parameters sent to API URL into a different array

  • Move away from curl to use httpie

  • Custom computation for certain attributes


The shellcheck passes everything except the unquoted $API_PARAMS[@] in the last line. I am not sure that httpie would work if I quote that and pass it as a single argument.




Charts for viewing pleasure (last 600 minutes data from the time post was created):




  1. Input line voltage



    LINEV




  2. Load (in wattage) on the UPS



    LOADPCT




  3. Battery time left for the UPS



    TIMELEFT



Click the images to get live charts.







share|improve this question

















  • 1




    Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
    – Toby Speight
    Apr 17 at 7:50












up vote
3
down vote

favorite









up vote
3
down vote

favorite











Following up from my previous question




Streaming my UPS metrics for graphical viewing in bash




#!/usr/bin/env bash

[ -v METRICS_CHECK ] && set -x

API_URL="https://api.thingspeak.com/update"
UPS_PROPS=("LINEV" "LOADPCT" "TIMELEFT")
API_PARAMS=("api_key==XXXXXXXXXXXXXX")

for index in "$!UPS_PROPS[@]"
do
value=$(/sbin/apcaccess -up "$UPS_PROPS[$index]")
field=$((index + 1))
if [ "$field" -eq 2 ]
then
# bc required for floating point arithmetic
value=$(echo "$value * 6" | bc) # 600 Watt * load percent
fi
PARAM=$(printf "field%d==%s" "$field" "$value")
API_PARAMS+=("$PARAM")
done

/usr/local/bin/http "$API_URL" $API_PARAMS[@]


Updates:



  • Collects data for different metrics supported by apcaccess

  • Use a variable check for enabling debug mode

  • Split parameters sent to API URL into a different array

  • Move away from curl to use httpie

  • Custom computation for certain attributes


The shellcheck passes everything except the unquoted $API_PARAMS[@] in the last line. I am not sure that httpie would work if I quote that and pass it as a single argument.




Charts for viewing pleasure (last 600 minutes data from the time post was created):




  1. Input line voltage



    LINEV




  2. Load (in wattage) on the UPS



    LOADPCT




  3. Battery time left for the UPS



    TIMELEFT



Click the images to get live charts.







share|improve this question













Following up from my previous question




Streaming my UPS metrics for graphical viewing in bash




#!/usr/bin/env bash

[ -v METRICS_CHECK ] && set -x

API_URL="https://api.thingspeak.com/update"
UPS_PROPS=("LINEV" "LOADPCT" "TIMELEFT")
API_PARAMS=("api_key==XXXXXXXXXXXXXX")

for index in "$!UPS_PROPS[@]"
do
value=$(/sbin/apcaccess -up "$UPS_PROPS[$index]")
field=$((index + 1))
if [ "$field" -eq 2 ]
then
# bc required for floating point arithmetic
value=$(echo "$value * 6" | bc) # 600 Watt * load percent
fi
PARAM=$(printf "field%d==%s" "$field" "$value")
API_PARAMS+=("$PARAM")
done

/usr/local/bin/http "$API_URL" $API_PARAMS[@]


Updates:



  • Collects data for different metrics supported by apcaccess

  • Use a variable check for enabling debug mode

  • Split parameters sent to API URL into a different array

  • Move away from curl to use httpie

  • Custom computation for certain attributes


The shellcheck passes everything except the unquoted $API_PARAMS[@] in the last line. I am not sure that httpie would work if I quote that and pass it as a single argument.




Charts for viewing pleasure (last 600 minutes data from the time post was created):




  1. Input line voltage



    LINEV




  2. Load (in wattage) on the UPS



    LOADPCT




  3. Battery time left for the UPS



    TIMELEFT



Click the images to get live charts.









share|improve this question












share|improve this question




share|improve this question








edited Apr 17 at 4:28
























asked Apr 17 at 4:13









hjpotter92

4,94611539




4,94611539







  • 1




    Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
    – Toby Speight
    Apr 17 at 7:50












  • 1




    Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
    – Toby Speight
    Apr 17 at 7:50







1




1




Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
– Toby Speight
Apr 17 at 7:50




Can you edit the titles on those charts, so they are not all "voltage"? (I know that's not part of the code, so this question isn't a review).
– Toby Speight
Apr 17 at 7:50










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










Quoting - you need double-quotes on the last line: it should be "$API_PARAMS[@]" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).



Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:



propname="$UPS_PROPS[$index]"
value=$(/sbin/apcaccess -up "$propname")
if [ "$propname" = LOADPCT ]


We can supply standard input from a string without needing an echo process, by using <<< redirection:



 # bc required for floating point arithmetic
value=$(<<<"$value * 6" bc) # 600 Watt * load percent


We can make the array 1-based, and avoid the need to have $field different from $index:



UPS_PROPS=([1]="LINEV" "LOADPCT" "TIMELEFT")





share|improve this answer





















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f192255%2fcreating-charts-for-my-ups-metrics-part-2%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    Quoting - you need double-quotes on the last line: it should be "$API_PARAMS[@]" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).



    Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:



    propname="$UPS_PROPS[$index]"
    value=$(/sbin/apcaccess -up "$propname")
    if [ "$propname" = LOADPCT ]


    We can supply standard input from a string without needing an echo process, by using <<< redirection:



     # bc required for floating point arithmetic
    value=$(<<<"$value * 6" bc) # 600 Watt * load percent


    We can make the array 1-based, and avoid the need to have $field different from $index:



    UPS_PROPS=([1]="LINEV" "LOADPCT" "TIMELEFT")





    share|improve this answer

























      up vote
      2
      down vote



      accepted










      Quoting - you need double-quotes on the last line: it should be "$API_PARAMS[@]" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).



      Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:



      propname="$UPS_PROPS[$index]"
      value=$(/sbin/apcaccess -up "$propname")
      if [ "$propname" = LOADPCT ]


      We can supply standard input from a string without needing an echo process, by using <<< redirection:



       # bc required for floating point arithmetic
      value=$(<<<"$value * 6" bc) # 600 Watt * load percent


      We can make the array 1-based, and avoid the need to have $field different from $index:



      UPS_PROPS=([1]="LINEV" "LOADPCT" "TIMELEFT")





      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        Quoting - you need double-quotes on the last line: it should be "$API_PARAMS[@]" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).



        Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:



        propname="$UPS_PROPS[$index]"
        value=$(/sbin/apcaccess -up "$propname")
        if [ "$propname" = LOADPCT ]


        We can supply standard input from a string without needing an echo process, by using <<< redirection:



         # bc required for floating point arithmetic
        value=$(<<<"$value * 6" bc) # 600 Watt * load percent


        We can make the array 1-based, and avoid the need to have $field different from $index:



        UPS_PROPS=([1]="LINEV" "LOADPCT" "TIMELEFT")





        share|improve this answer













        Quoting - you need double-quotes on the last line: it should be "$API_PARAMS[@]" (remember that the [@] makes the shell expand it into multiple words, so it won't be seen by your http program as just one).



        Instead of if [ "$field" -eq 2 ], it's clearer to compare the field name. That will help if you change the properties list in future. It may help to create a variable:



        propname="$UPS_PROPS[$index]"
        value=$(/sbin/apcaccess -up "$propname")
        if [ "$propname" = LOADPCT ]


        We can supply standard input from a string without needing an echo process, by using <<< redirection:



         # bc required for floating point arithmetic
        value=$(<<<"$value * 6" bc) # 600 Watt * load percent


        We can make the array 1-based, and avoid the need to have $field different from $index:



        UPS_PROPS=([1]="LINEV" "LOADPCT" "TIMELEFT")






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 17 at 7:47









        Toby Speight

        17.5k13489




        17.5k13489






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f192255%2fcreating-charts-for-my-ups-metrics-part-2%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Greedy Best First Search implementation in Rust

            Function to Return a JSON Like Objects Using VBA Collections and Arrays

            C++11 CLH Lock Implementation