Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UNL-CMS-scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Steiner
UNL-CMS-scripts
Commits
9e506f39
Commit
9e506f39
authored
1 year ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
Fix varnish cloudwatch, add IMDSv2 tokens.
parent
0a0f93a8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
varnishstat-to-cloudwatch.py
+7
-4
7 additions, 4 deletions
varnishstat-to-cloudwatch.py
with
7 additions
and
4 deletions
varnishstat-to-cloudwatch.py
+
7
−
4
View file @
9e506f39
#!/usr/bin/python
#!/usr/bin/python
import
boto3
import
boto3
import
urllib2
#
import urllib2
import
json
import
json
import
requests
import
sys
import
sys
#import re
#import re
#import tempfile
#import tempfile
...
@@ -25,7 +26,7 @@ def main():
...
@@ -25,7 +26,7 @@ def main():
previous_data
=
None
previous_data
=
None
metrics
=
{}
metrics
=
{}
while
True
:
while
True
:
current_data
=
json
.
loads
(
subprocess
.
check_output
([
'
varnishstat
'
,
'
-j
'
,
'
-1
'
,
'
-f
'
,
'
MAIN.client_req
'
,
'
-f
'
,
'
MAIN.cache_hit
'
]))
current_data
=
json
.
loads
(
subprocess
.
check_output
([
'
varnishstat
'
,
'
-j
'
,
'
-1
'
,
'
-f
'
,
'
MAIN.client_req
'
,
'
-f
'
,
'
MAIN.cache_hit
'
]))
[
'
counters
'
]
if
previous_data
:
if
previous_data
:
metric_data
=
[]
metric_data
=
[]
for
key
in
current_data
:
for
key
in
current_data
:
...
@@ -56,8 +57,10 @@ def main():
...
@@ -56,8 +57,10 @@ def main():
# Returns the region the instance is currently running in (eg: 'us-east')
# Returns the region the instance is currently running in (eg: 'us-east')
def
get_region
():
def
get_region
():
instance_info
=
urllib2
.
urlopen
(
'
http://169.254.169.254/2018-09-24/dynamic/instance-identity/document/
'
).
read
()
session_token
=
requests
.
put
(
'
http://169.254.169.254/latest/api/token
'
,
headers
=
{
'
X-aws-ec2-metadata-token-ttl-seconds
'
:
60
}).
text
instance_info
=
json
.
loads
(
instance_info
)
instance_info
=
requests
.
get
(
'
http://169.254.169.254/2018-09-24/dynamic/instance-identity/document/
'
,
headers
=
{
'
X-aws-ec2-metadata-token
'
:
session_token
}).
json
()
#instance_info = urllib2.urlopen('http://169.254.169.254/2018-09-24/dynamic/instance-identity/document/').read()
#instance_info = json.loads(instance_info)
return
instance_info
[
'
region
'
]
return
instance_info
[
'
region
'
]
# Returns the instance_id of this VM.
# Returns the instance_id of this VM.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment