czerwonk / junos_exporter

Exporter for devices running JunOS to use with https://prometheus.io/
MIT License
198 stars 81 forks source link

Enhancement: Add power usage statistics #131

Closed AKYD closed 3 years ago

AKYD commented 3 years ago

Because standards... show chassis environment pem returns no power information for some equipment types

Proposal

Add a power module (similar to the environment one) that uses the show chassis power detail... command

As far I can tell, for the following device types, we have to use different commands to extract this info:

SRX

show chassis power detail node 0 show chassis power detail node 1

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/XXX/junos">
    <multi-routing-engine-results>

        <multi-routing-engine-item>

            <re-name>node0</re-name>

            <power-usage-information>
                <power-usage-item>
                    <name>PEM 0</name>
                    <state>Online</state>
                    <pem-capacity-detail>
                        <capacity-actual>0</capacity-actual>
                        <capacity-max>0</capacity-max>
                    </pem-capacity-detail>
                    <dc-output-detail>
                        <dc-power>120</dc-power>
                        <zone>0</zone>
                        <dc-current>10</dc-current>
                        <dc-voltage>12</dc-voltage>
                        <dc-load>4</dc-load>
                    </dc-output-detail>
                </power-usage-item>
                <power-usage-item>
                    <name>PEM 1</name>
                    <state>Online</state>
                    <pem-capacity-detail>
                        <capacity-actual>0</capacity-actual>
                        <capacity-max>0</capacity-max>
                    </pem-capacity-detail>
                    <dc-output-detail>
                        <dc-power>120</dc-power>
                        <zone>0</zone>
                        <dc-current>10</dc-current>
                        <dc-voltage>12</dc-voltage>
                        <dc-load>4</dc-load>
                    </dc-output-detail> 
                </power-usage-item>
                <power-usage-system>
                    <power-usage-zone-information>
                        <zone>0</zone>
                        <capacity-actual>0</capacity-actual>
                        <capacity-max>0</capacity-max>
                        <capacity-allocated>240</capacity-allocated>
                        <capacity-remaining>0</capacity-remaining>
                        <capacity-actual-usage>240</capacity-actual-usage>
                    </power-usage-zone-information>
                    <capacity-sys-actual>0</capacity-sys-actual>
                    <capacity-sys-max>0</capacity-sys-max>
                    <capacity-sys-remaining>0</capacity-sys-remaining>
                </power-usage-system>
                <power-usage-fru-item>
                    <name>Fan Tray 0</name>
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
                <power-usage-fru-item>
                    <name>Fan Tray 1</name>
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
                <power-usage-fru-item>
                    <name>Fan Tray 2</name>
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
                <power-usage-fru-item>
                    <name>Fan Tray 3</name>
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
                <power-usage-fru-item>
                    <name>RE0/CB0</name>
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
                <power-usage-fru-item>
                    <name>FPC 0</name>  
                    <dc-power>0</dc-power>
                </power-usage-fru-item>
            </power-usage-information>
        </multi-routing-engine-item>

    </multi-routing-engine-results>
    <cli>
        <banner>{secondary:node1}</banner>
    </cli>
</rpc-reply>

{secondary:node1}

MX

Summing up all the PEM values, we get the same total as the values in power-usage-zone-information, so for MX I guess we can use the metrics from https://github.com/czerwonk/junos_exporter/issues/66 once it's implemented or use the "new" power-usage-zone-information metrics from here

show chassis power detail

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/XXX/junos">
    <power-usage-information>
        <power-usage-item>
            <name>PEM 0</name>
            <state>Online</state>
            <dc-input-detail>
                <dc-input>OK</dc-input>
                <dc-expect-feed>1</dc-expect-feed>
                <dc-actual-feed>1</dc-actual-feed>
                <reference-voltage>48.0 V input</reference-voltage>
                <actual-voltage>56000</actual-voltage>
            </dc-input-detail>
            <pem-capacity-detail>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
            </pem-capacity-detail>
            <dc-output-detail>
                <dc-power>550</dc-power>
                <zone>0</zone>
                <dc-current>10</dc-current>
                <dc-voltage>55</dc-voltage>
                <dc-load>22</dc-load>
            </dc-output-detail>
        </power-usage-item>
        <power-usage-item>
            <name>PEM 1</name>
            <state>Online</state>
            <dc-input-detail>
                <dc-input>OK</dc-input>
                <dc-expect-feed>1</dc-expect-feed>
                <dc-actual-feed>1</dc-actual-feed>
                <reference-voltage>48.0 V input</reference-voltage>
                <actual-voltage>57000</actual-voltage>
            </dc-input-detail>
            <pem-capacity-detail>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
            </pem-capacity-detail>
            <dc-output-detail>
                <dc-power>112</dc-power>
                <zone>1</zone>
                <dc-current>2</dc-current>
                <dc-voltage>56</dc-voltage>
                <dc-load>4</dc-load>
            </dc-output-detail>
        </power-usage-item>
        <power-usage-item>
            <name>PEM 2</name>
            <state>Online</state>
            <dc-input-detail>
                <dc-input>OK</dc-input>
                <dc-expect-feed>1</dc-expect-feed>
                <dc-actual-feed>1</dc-actual-feed>
                <reference-voltage>48.0 V input</reference-voltage>
                <actual-voltage>56500</actual-voltage>
            </dc-input-detail>
            <pem-capacity-detail>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
            </pem-capacity-detail>
            <dc-output-detail>
                <dc-power>336</dc-power>
                <zone>0</zone>
                <dc-current>6</dc-current>
                <dc-voltage>56</dc-voltage>
                <dc-load>13</dc-load>
            </dc-output-detail>
        </power-usage-item>
        <power-usage-item>
            <name>PEM 3</name>
            <state>Online</state>
            <dc-input-detail>
                <dc-input>OK</dc-input> 
                <dc-expect-feed>1</dc-expect-feed>
                <dc-actual-feed>1</dc-actual-feed>
                <reference-voltage>48.0 V input</reference-voltage>
                <actual-voltage>56500</actual-voltage>
            </dc-input-detail>
            <pem-capacity-detail>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
            </pem-capacity-detail>
            <dc-output-detail>
                <dc-power>56</dc-power>
                <zone>1</zone>
                <dc-current>1</dc-current>
                <dc-voltage>56</dc-voltage>
                <dc-load>2</dc-load>
            </dc-output-detail>
        </power-usage-item>
        <power-usage-system>
            <power-usage-zone-information>
                <zone>0</zone>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
                <capacity-allocated>1520</capacity-allocated>
                <capacity-remaining>920</capacity-remaining>
                <capacity-actual-usage>886</capacity-actual-usage>
            </power-usage-zone-information>
            <power-usage-zone-information>
                <zone>1</zone>
                <capacity-actual>2440</capacity-actual>
                <capacity-max>2440</capacity-max>
                <capacity-allocated>465</capacity-allocated>
                <capacity-remaining>1975</capacity-remaining>
                <capacity-actual-usage>168</capacity-actual-usage>
            </power-usage-zone-information>
            <capacity-sys-actual>4880</capacity-sys-actual>
            <capacity-sys-max>4880</capacity-sys-max>
            <capacity-sys-remaining>2895</capacity-sys-remaining>
        </power-usage-system>
        <power-usage-fru-item>
            <name>FPC 3</name>
            <dc-power>265</dc-power>
        </power-usage-fru-item>
    </power-usage-information>
    <cli>
        <banner>{master}</banner>
    </cli>
</rpc-reply>

{master}

QFX

About the same as SRX.

EX

From Juniper support:

"For EX switches we don't have a command to retrieve the exact energy consumption (the 75W that shows the command "show chassis power-budget-statistics" is the max consumption available). To estimate the real consumption we have to do it regarding Gpbs switched/routed traffic with a method called ECR (Energy Consumption Rating)"

and it basically uses a lookup table to determine that for EX2300-48T @ 90% utilization we're using 70W

For a model, the variance between 0-100% is very small, so it's easier to get the average value per device type and use that in a Prometheus recording rule if needed. I wouldn't add this mapping in the exporter

AKYD commented 3 years ago

If the idea makes sense, I can start working on it in the following days