Tuesday, October 25, 2016

Prometheus: creating and deleting silences

the following can be used to create, delete and get silence items from a prometheus server.

get all silences (including expired ones) curl http://localhost:9093/api/v1/silences

delete a specific silence - curl http://localhost:9093/api/v1/silence/6b61b918-4aa3-4c8e-b0bf-985ff334c598 -XDELETE

create a silence - curl http://localhost:9093/api/v1/silences -XPOST {"matchers":[{"name":"c","value":"c"}],"createdBy":"ami@rounds.com","startsAt":"2016-10-25T14:03:00.000Z","endsAt":"2016-10-25T18:03:00.000Z","comment":"c"}

Wednesday, June 15, 2016

Stopping docker containers with signals

excellent article here:
https://www.ctl.io/developers/blog/post/gracefully-stopping-docker-containers/

Monday, June 13, 2016

Concatenating commands in docker-compsoe

So sometimes you want to concatenate multiple commands in one `command` directive in your docker-compose script. Trying to use && or ; didn't work for me. But this did:

 command: bash -c "command1 && command2  etc"

Sunday, June 12, 2016

Python: Sane version comparison with LooseVersion

 class Version(LooseVersion):  
 """Wrap distutils.version.LooseVersion with support for null versions."""  
    def __init__(self, version):  
      """Init."""  
      LooseVersion.__init__(self, str(version or 0))  
    def __cmp__(self, other):  
      """Compare."""  
      if not isinstance(other, LooseVersion):  
        other = Version(other)  
      return LooseVersion.__cmp__(self, other)  

Wednesday, June 8, 2016

BigQuery: split into percentiles with NTH and Quantiles

SELECT
  sent.push_system,
  AVG(timestamp_to_sec(acked._t) - timestamp_to_sec(sent._t)) as avg_ttl,
  NTH(100, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p10th,
  NTH(200, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p20th,
  NTH(300, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p30th,
  NTH(400, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p40th,
  NTH(500, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p50th,
  NTH(600, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p60th,
  NTH(700, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p70th,
  NTH(800, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p80th,
  NTH(900, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p90th,
  NTH(950, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p95th,
  NTH(990, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p99th,
  NTH(999, QUANTILES((TIMESTAMP_TO_USEC(acked._t) - TIMESTAMP_TO_USEC(sent._t))/1e6, 1001)) AS p99_9th,
  COUNT(DISTINCT sent.rguid) AS sent,
  COUNT(DISTINCT acked.rguid) AS acked
FROM(
  SELECT
    JSON_EXTRACT_SCALAR(others, '$.push_notification_rguid') AS rguid,
    JSON_EXTRACT_SCALAR(others, '$.push_notification_system') AS push_system,
    target.device.id AS device_id,
    timestamp as _t
  FROM
    [rounds_events.server_events_20160607]
  WHERE
    event_name='pushnotif_sent' ) AS sent
JOIN (
  SELECT push_notification.platform,
    JSON_EXTRACT_SCALAR(others, '$.push_notification_rguid') AS rguid,
    JSON_EXTRACT_SCALAR(others, '$.push_notification_system') AS push_system,
    target.device.id AS device_id,
    timestamp as _t
  FROM
    [rounds_events.server_events_20160607]
  WHERE
    event_name='pushnotif_ack') as acked
ON acked.rguid=sent.rguid
  WHERE
    sent.push_system='ricapi' AND sent.rguid CONTAINS 'trigger_action' AND acked.push_notification.platform='gcm'
GROUP BY
sent.push_system