You are browsing a read-only backup copy of Wikitech. The primary site can be found at wikitech.wikimedia.org

User:Nskaggs: Difference between revisions

From Wikitech-static
Jump to navigation Jump to search
imported>Nskaggs
(Add more random python snippets)
imported>Nskaggs
No edit summary
 
Line 236: Line 236:
</syntaxhighlight>
</syntaxhighlight>
{{Collapse bottom}}
{{Collapse bottom}}
===wmcs-openstack-usage.py===
Quick script used to help generate raw data for resource usage of WMCS cloud
{{Collapse top|wmcs-openstack-usage.py}}
<syntaxhighlight lang="python">
#!/usr/bin/env python3
import io
import subprocess




===wmcs-openstack-usage.py===
def main():
    startdate = '2021-12-01'
    enddate = '2022-01-01'
 
    f = open('usage.csv', 'w')
    f.write('Project, Instances, VCPU, MEM (GB), DISK (GB)\n')
 
    # get list of projects
    output = subprocess.run(['sudo', 'wmcs-openstack','project','list', '-f', 'value', '-c', 'ID'], stdout=subprocess.PIPE).stdout.decode('utf-8')
    projects = output.split('\n')[:-1]
 
    for project in projects:
        # gather limit stats
        output = subprocess.run(['sudo', 'wmcs-openstack','limits','show', '--project', project, '--absolute', '-f', 'value'], stdout=subprocess.PIPE).stdout.decode('utf-8')
        limits = output.split('\n')
 
        # parse out resource usage and limits
        for line in limits:
            attr = line.split(' ')[0]
            if attr == 'totalInstancesUsed':
                instances = line.split(' ')[1]
            elif attr == 'totalCoresUsed':
                cpu = line.split(' ')[1]
            elif attr == 'totalRAMUsed':
                ram = line.split(' ')[1]
                # Convert to GB
                ram = str(int(ram) / 1024)
 
        #parse stats and output as csv
        f.write(f'{project},{instances},{cpu},{ram},')
 
        # in order to get disk usage, we need to check other calls
        # gather disk used (cinder)
        output = subprocess.run(['sudo', 'wmcs-openstack','resource','usage', 'show', '--os-placement-api-version', '1.9', project, '-f', 'value'], stdout=subprocess.PIPE).stdout.decode('utf-8')
        resources = output.split('\n')
        for line in resources:
            attr = line.split(' ')[0]
            if attr == 'DISK_GB':
                disk_gb = line.split(' ')[1]
 
        f.write(f'{disk_gb}\n')
 
    f.close()
 
if __name__ == "__main__":
    main()
 
</syntaxhighlight>
{{Collapse bottom}}
 
 
===wmcs-openstack-resources.py===


Quick script used to help generate raw data for cost estimations of WMCS cloud usage
Quick script used to demonstrate raw data on resource usage of WMCS cloud





Latest revision as of 23:11, 26 January 2022

wmcs-netbox-list.py

An enhanced fork of Arturo's netbox-list.py with more fields gathered. Fetch & list WMCS server info from Netbox and generate a CSV (to later import into a spreadsheet):


wmcs-phab.py

Proof of concept to pull ticket information from phabricator to csv


wmcs-openstack-usage.py

Quick script used to help generate raw data for resource usage of WMCS cloud



wmcs-openstack-resources.py

Quick script used to demonstrate raw data on resource usage of WMCS cloud