# gRPC Monitor

- Import the `GrpcMonitor` construct from `checkly/constructs`.
- Reference [the docs for gRPC monitors](https://www.checklyhq.com/docs/constructs/grpc-monitor/) before generating any code.
- When adding `assertions`, always use `GrpcAssertionBuilder` class.
- The `request` object must include a `url` (hostname only, no scheme), `port`, and a `grpcConfig` object.
- Use `grpcConfig.mode` to choose between `'BEHAVIOR'` (invoke a unary method) and `'HEALTH'` (standard health-check service).
- In `BEHAVIOR` mode, set `grpcConfig.method` (e.g. `'package.Service/Method'`). Use `grpcConfig.serviceDefinition` (`'REFLECTION'` or `'PROTO_FILE'`) to resolve the service definition.
- In `HEALTH` mode, optionally set `grpcConfig.service` to query a specific service; omit it to query overall server health.
- Use `degradedResponseTime` and `maxResponseTime` (milliseconds) to configure response time thresholds.
- **Plan-gated properties:** `retryStrategy`, `runParallel`, and higher frequencies are not available on all plans. Check entitlements matching `UPTIME_CHECKS_*` before using these. Omit any property whose entitlement is disabled. See `npx checkly skills manage` for details.

**Reference:** https://www.checklyhq.com/docs/constructs/grpc-monitor/

```typescript
import { GrpcMonitor, GrpcAssertionBuilder } from 'checkly/constructs'

new GrpcMonitor('grpc-api-health', {
  name: 'gRPC API Health',
  activated: true,
  locations: ['us-east-1', 'eu-west-1'],
  degradedResponseTime: 2000,
  maxResponseTime: 5000,
  request: {
    url: 'grpc.example.com',
    port: 50051,
    grpcConfig: {
      mode: 'HEALTH',
      tls: true,
    },
    assertions: [
      GrpcAssertionBuilder.healthCheckStatus().equals('SERVING'),
      GrpcAssertionBuilder.responseTime().lessThan(1000),
    ],
  },
})
```

## FlatBuffers services

Only applies when the service uses FlatBuffers instead of Protobuf. Protobuf is the default; omit `grpcConfig.encoding` otherwise.

- FlatBuffers requires `BEHAVIOR` mode; `HEALTH` mode always uses Protobuf.
- Compile the `.fbs` source schema to a binary `.bfbs` schema with `flatc -b --schema --bfbs-builtins schema.fbs`. `--bfbs-builtins` preserves attributes used for streaming and nested FlatBuffers fields.
- Set `grpcConfig.encoding` to `'FLATBUFFERS'` and load the compiled schema as base64 into `bfbsContent`. Do not set `serviceDefinition` or `protoContent`; FlatBuffers has no server reflection.

```typescript
import { readFileSync } from 'node:fs'

request: {
  url: 'grpc.example.com',
  port: 443,
  grpcConfig: {
    mode: 'BEHAVIOR',
    encoding: 'FLATBUFFERS',
    bfbsContent: readFileSync('schema.bfbs').toString('base64'),
    method: 'example.Greeter/Greet',
    message: JSON.stringify({ name: 'Checkly' }),
  },
}
```
