예제 #1
0
def test_methods_capture_disabled(db, mock_capture_internal,
                                  mocker: MockerFixture):
    mocker.patch.object(settings, "CAPTURE_INTERNAL_METRICS", False)

    timing("foo_metric", 100, tags={"team_id": 15})
    gauge("bar_metric", 20, tags={"team_id": 15})
    incr("zeta_metric")

    mock_capture_internal.assert_not_called()
예제 #2
0
def redis_celery_queue_depth():
    from posthog.internal_metrics import gauge

    try:
        llen = get_client().llen("celery")
        gauge(f"posthog_celery_queue_depth", llen)
    except:
        # if we can't connect to statsd don't complain about it.
        # not every installation will have statsd available
        return
예제 #3
0
def test_methods_capture_enabled(db, mock_capture_internal):
    timing("foo_metric", 100, tags={"team_id": 15})
    gauge("bar_metric", 20, tags={"team_id": 15})
    incr("zeta_metric")

    mock_capture_internal.assert_any_call(
        {
            "event": "$$foo_metric",
            "properties": {
                "value": 100,
                "team_id": 15
            }
        },
        "machine_id",
        None,
        None,
        mock.ANY,
        mock.ANY,
        get_internal_metrics_team_id(),
    )

    mock_capture_internal.assert_any_call(
        {
            "event": "$$bar_metric",
            "properties": {
                "value": 20,
                "team_id": 15
            }
        },
        "machine_id",
        None,
        None,
        mock.ANY,
        mock.ANY,
        get_internal_metrics_team_id(),
    )

    mock_capture_internal.assert_any_call(
        {
            "event": "$$zeta_metric",
            "properties": {
                "value": 1
            }
        },
        "machine_id",
        None,
        None,
        mock.ANY,
        mock.ANY,
        get_internal_metrics_team_id(),
    )
예제 #4
0
def clickhouse_row_count():
    from ee.clickhouse.client import sync_execute
    from posthog.internal_metrics import gauge

    for table in CLICKHOUSE_TABLES:
        try:
            QUERY = """select count(1) freq from {table};"""
            query = QUERY.format(table=table)
            rows = sync_execute(query)[0][0]
            gauge(f"posthog_celery_clickhouse_table_row_count",
                  rows,
                  tags={"table": table})
        except:
            pass
예제 #5
0
def clickhouse_lag():
    from ee.clickhouse.client import sync_execute
    from posthog.internal_metrics import gauge

    for table in CLICKHOUSE_TABLES:
        try:
            QUERY = """select max(_timestamp) observed_ts, now() now_ts, now() - max(_timestamp) as lag from {table};"""
            query = QUERY.format(table=table)
            lag = sync_execute(query)[0][2]
            gauge("posthog_celery_clickhouse__table_lag_seconds",
                  lag,
                  tags={"table": table})
        except:
            pass
예제 #6
0
def clickhouse_part_count():
    from ee.clickhouse.client import sync_execute
    from posthog.internal_metrics import gauge

    QUERY = """
        select table, count(1) freq
        from system.parts
        group by table
        order by freq desc;
    """
    rows = sync_execute(QUERY)
    for (table, parts) in rows:
        gauge(f"posthog_celery_clickhouse_table_parts_count",
              parts,
              tags={"table": table})
예제 #7
0
def clickhouse_mutation_count():
    if is_clickhouse_enabled() and settings.EE_AVAILABLE:
        from ee.clickhouse.client import sync_execute
        from posthog.internal_metrics import gauge

        QUERY = """
            SELECT
                table,
                count(1) AS freq
            FROM system.mutations
            GROUP BY table
            ORDER BY freq DESC
        """
        rows = sync_execute(QUERY)
        for (table, muts) in rows:
            gauge(f"posthog_celery_clickhouse_table_mutations_count", muts, tags={"table": table})
    else:
        pass
예제 #8
0
def clickhouse_mutation_count():
    from ee.clickhouse.client import sync_execute
    from posthog.internal_metrics import gauge

    QUERY = """
        SELECT
            table,
            count(1) AS freq
        FROM system.mutations
        WHERE is_done = 0
        GROUP BY table
        ORDER BY freq DESC
    """
    rows = sync_execute(QUERY)
    for (table, muts) in rows:
        gauge(f"posthog_celery_clickhouse_table_mutations_count",
              muts,
              tags={"table": table})