title: Reading Prometheus metric using python
body: <p>I am trying to read Prometheus metrics (the cpu and memory values) of a POD in kubernetes. I have Prometheus install and everything is up using local host '<a href="http://localhost:9090/" rel="nofollow noreferrer">http://localhost:9090/</a>. I used the following code to read the CPU and memory of a pod but I have an error results = response.json()['data']['result'] , No JSON object could be decoded . IS anyone can help please ? </p>
  
  <pre><code>import datetime
  import time
  import requests  
  
  PROMETHEUS = 'http://localhost:9090/'
  
  end_of_month = datetime.datetime.today().replace(day=1).date()
  
  last_day = end_of_month - datetime.timedelta(days=1)
  duration = '[' + str(last_day.day) + 'd]'
  
  response = requests.get(PROMETHEUS + '/metrics',
    params={
      'query': 'sum by (job)(increase(process_cpu_seconds_total' + duration + '))',
      'time': time.mktime(end_of_month.timetuple())})
  results = response.json()['data']['result']
  
  print('{:%B %Y}:'.format(last_day))
  for result in results:
    print(' {metric}: {value[1]}'.format(**result))
  </code></pre>