-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nikola Tassev
committed
Jun 24, 2014
0 parents
commit fae58d3
Showing
43 changed files
with
4,701 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea/ | ||
build/ | ||
dist/ | ||
conf.json |
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,46 @@ | ||
# Client tool for collecting statistics from multiple accounts # | ||
|
||
Create a config file e.g. named `conf.json` with the following contents: | ||
|
||
{ | ||
"alias_one": {"username": "[email protected]", "password": "secret", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"}, | ||
"alias_two": {"username": "[email protected]", "password": "secret2", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"} | ||
} | ||
|
||
Please verify the accounts are pointed to the right cloud location URL. Here is a list of the current cloud location API endpoints: | ||
|
||
* https://wdc.cloudsigma.com/api/2.0/ | ||
* https://lvs.cloudsigma.com/api/2.0/ | ||
* https://zrh.cloudsigma.com/api/2.0/ | ||
|
||
Then you can invoke the stats collection using the command: | ||
|
||
$ cloudsigma_stats conf.json | ||
{ | ||
"Metrics": { | ||
"NumberOfVirtualMachines": { | ||
"alias_one": 0, | ||
"alias_two": 0 | ||
}, | ||
"NumberOfUsedCPUCores": { | ||
"alias_one": 0, | ||
"alias_two": 0 | ||
}, | ||
"MemoryUsage": { | ||
"alias_one": 0, | ||
"alias_two": 0 | ||
}, | ||
"NumberOfVMImages": { | ||
"alias_one": 1, | ||
"alias_two": 0 | ||
} | ||
}, | ||
"Cloud name": "CloudSigma" | ||
} | ||
|
||
If the exit code of the command is 0, the standard output will contain a valid JSON output. | ||
|
||
If the `cloudsigma_stats` command is executed without parameters, it prints a template for the config file. | ||
|
||
If any error occurs (invalid config file, wrong URL, wrong credentials, problem with connection), the command | ||
will exit with non-zero return code and will print an error trace on the standard output. |
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,39 @@ | ||
import json | ||
import cloudsigma | ||
import sys | ||
|
||
|
||
if len(sys.argv) <= 1: | ||
print >>sys.stderr, "Pass the config file as the first argument. \n" \ | ||
"Here is an example template for a config file. Please specify account email, password and cloud location:" | ||
print >>sys.stderr, """ | ||
{ | ||
"alias_one": {"username": "[email protected]", "password": "secret", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"}, | ||
"alias_two": {"username": "[email protected]", "password": "secret2", "api_endpoint":"https://wdc.cloudsigma.com/api/2.0/"} | ||
} | ||
""" | ||
sys.exit(-1) | ||
|
||
users = json.load(open(sys.argv[1], 'r')) | ||
|
||
metrics = { | ||
'MemoryUsage': {}, | ||
'NumberOfUsedCPUCores': {}, | ||
'NumberOfVMImages': {}, | ||
'NumberOfVirtualMachines': {}, | ||
} | ||
|
||
for alias, user in users.iteritems(): | ||
started_servers = [server for server in cloudsigma.resource.Server(**user).list_detail() if server['status'] == 'running'] | ||
drives = cloudsigma.resource.Drive(**user).list() | ||
metrics['MemoryUsage'][alias] = sum(guest['mem'] for guest in started_servers) | ||
metrics['NumberOfUsedCPUCores'][alias] = sum(guest['smp'] for guest in started_servers) | ||
metrics['NumberOfVirtualMachines'][alias] = len(started_servers) | ||
metrics['NumberOfVMImages'][alias] = len(drives) | ||
|
||
dump = { | ||
'Cloud name': 'CloudSigma', | ||
'Metrics': metrics, | ||
} | ||
|
||
print json.dumps(dump, indent=True) |
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,17 @@ | ||
# -*- mode: python -*- | ||
a = Analysis(['cloudsigma_stats.py', 'cloudsigma_stats.spec'], | ||
pathex=['/home/nikola/src/cloudsme_stats'], | ||
hiddenimports=[], | ||
hookspath=None, | ||
runtime_hooks=None) | ||
pyz = PYZ(a.pure) | ||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries + [('requests/cacert.pem', '/home/nikola/.virtualenvs/cloudsme_stats/lib/python2.7/site-packages/requests/cacert.pem', 'DATA'), ], | ||
a.zipfiles, | ||
a.datas, | ||
name='cloudsigma_stats', | ||
debug=False, | ||
strip=None, | ||
upx=True, | ||
console=True ) |
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,5 @@ | ||
*.pyc | ||
*.swp | ||
build/ | ||
dist/ | ||
src/cloudsigma.egg-info |
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 @@ | ||
include requirements.txt |
Oops, something went wrong.