-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASIC temperature sensors support #2267
Closed
padmanarayana
wants to merge
1
commit into
sonic-net:master
from
padmanarayana:asic_sens_sonic_image
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
117 changes: 117 additions & 0 deletions
117
platform/broadcom/sonic-platform-modules-dell/common/asic_sensors.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#! /usr/bin/python | ||
# Retrieve the maximum number of thermal sensors supported on | ||
# the ASIC from the flex counter DB and print the readings | ||
# along wtih the average. | ||
|
||
import swsssdk | ||
import json | ||
import sys | ||
import os | ||
import pickle | ||
from subprocess import Popen, PIPE | ||
|
||
# temp files to cache constants | ||
SENSORS_DIR = "/tmp/dell/sensors" | ||
SWITCH_OID = "switch_oid" | ||
MAX_SENSORS = "max_sensors" | ||
|
||
# Load a value from a given file | ||
def load_from_file(file): | ||
if os.path.isfile(file): | ||
try: | ||
value = pickle.load(open(file, 'r')) | ||
except IOError as e: | ||
print e.errno, e | ||
sys.exit(e.errno) | ||
return value | ||
|
||
# Dump a value into a given file | ||
def dump_to_file(file, value): | ||
if value: | ||
try: | ||
pickle.dump(value, open(file, 'w')) | ||
except IOError as e: | ||
print e.errno, e | ||
sys.exit(e.errno) | ||
|
||
# Get the switch OID should the ASIC support sensors | ||
def get_switch_sensors_oid(): | ||
switch_oid_file = SENSORS_DIR + "/" + SWITCH_OID | ||
|
||
# Check if we saved it in the tmp file already | ||
if os.path.isfile(switch_oid_file): | ||
return load_from_file(switch_oid_file) | ||
|
||
if not os.path.exists(SENSORS_DIR): | ||
try: | ||
os.makedirs(SENSORS_DIR) | ||
except IOError as e: | ||
print e.errno, e | ||
sys.exit(1) | ||
|
||
# Retrieve the switch oid from the flex counter DB | ||
# and save it in the file cache | ||
proc = Popen("docker exec -i database redis-cli \ | ||
--raw -n 5 KEYS FLEX_COUNTER_TABLE:SWITCH_SENSORS*", \ | ||
stdout=PIPE, stderr=PIPE, shell=True) | ||
out, err = proc.communicate() | ||
|
||
for key in out.splitlines() or [None]: | ||
if key: | ||
id = key.replace('FLEX_COUNTER_TABLE:SWITCH_SENSORS:oid:', '') | ||
if id: | ||
dump_to_file(switch_oid_file, id) | ||
return id | ||
return None | ||
|
||
# Get the number of sensor values that will be dumped to counters DB | ||
def get_switch_max_sensors(sensors): | ||
max_sensors_file = SENSORS_DIR + "/" + MAX_SENSORS | ||
|
||
if os.path.isfile(max_sensors_file): | ||
return load_from_file(max_sensors_file) | ||
|
||
temp_list = [sensors[key] for key in sensors | ||
if key.startswith('SAI_SWITCH_ATTR_TEMP_')] | ||
max_sensors = len(temp_list) | ||
if max_sensors: | ||
dump_to_file(max_sensors_file, max_sensors) | ||
return max_sensors | ||
|
||
return 0 | ||
|
||
# Print the ASIC sensors from the counter DB | ||
def print_asic_sensors(): | ||
|
||
countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') | ||
countersdb.connect(countersdb.COUNTERS_DB) | ||
|
||
id = get_switch_sensors_oid() | ||
if id: | ||
sensors = countersdb.get_all(countersdb.COUNTERS_DB, | ||
'COUNTERS:oid:' + id) | ||
max_sensors = get_switch_max_sensors(sensors) | ||
|
||
average_temp = sensors.get('SAI_SWITCH_ATTR_AVERAGE_TEMP') | ||
max_temp = sensors.get('SAI_SWITCH_ATTR_MAX_TEMP') | ||
temp_list = [] | ||
|
||
# Retrieve the list of individual sensor values | ||
for i in range(max_sensors): | ||
temp_list.append(sensors.get('SAI_SWITCH_ATTR_TEMP_%d' % i)) | ||
|
||
if (average_temp is not None) and \ | ||
(max_temp is not None) and \ | ||
(temp_list is not None): | ||
print '\nBCM Internal: ' \ | ||
+ str(average_temp) + ' C' \ | ||
+ ' (max ' + str(max_temp) + ' C)' \ | ||
+ ' (' + ' '.join(str(x) for x in temp_list) + ' C)' | ||
else: | ||
print '\nBCM Internal: ' + 'NA' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you provide a sample output here? |
||
|
||
else: | ||
print '\nBCM Internal: ' + 'NA' | ||
|
||
countersdb.close(countersdb.COUNTERS_DB) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json is not used