This documentation provides a step-by-step guide on how to monitor the Timoni project in a production environment, leveraging its features and capabilities effectively.

Configuring Monitoring

To enable monitoring capabilities in Timoni, you need to configure the monitoring settings within your CUE configuration files. This allows you to integrate with Prometheus for enhanced visibility into your application.

  1. Add Monitoring Configuration
    In your templates/config.cue file, configure the monitoring parameters as follows:

    #Config: {
       monitoring: {
          enabled:  *false | bool
          interval: *15 | int & >=5 & <=3600
       }
    }
    

    This configuration allows you to enable or disable monitoring and set the interval at which metrics should be scraped by Prometheus. Adjust the enabled flag and interval according to your monitoring needs.

    Source: docs/cue/module/custom-resources.md

Building and Deploying with Monitoring

After you have set up the monitoring configuration, follow these steps to build and deploy your application:

  1. Build the Application
    Use the Makefile provided in the Timoni repository to build your application:

    make build
    

    This command compiles the Go code and prepares your binaries for deployment.

  2. Deploying Your Application
    Deploy the application to your Kubernetes cluster, ensuring that the newly added monitoring configuration is included during deployment.

    kubectl apply -f path/to/your/deployment.yaml
    

    Make sure that your deployment can access the Prometheus service to send metrics.

Note: Avoid using -mod=vendor in your Go build command as it is not supported in this project ecosystem.

Monitoring with Prometheus

To verify that the monitoring is operational:

  1. Access Prometheus
    Use the Prometheus UI to check if your application metrics are being scraped. Navigate to http://:9090/targets and ensure your application appears in the list of targets.

  2. Query Metrics
    Query your application metrics in the Prometheus UI. For example, you might want to visualize the request counts:

    sum(rate(http_requests_total[1m])) by (method)
    

    This PromQL query gives insight into the total number of HTTP requests over time, aggregated by the request method.

Custom Job Status Monitoring

Timoni supports monitoring of custom jobs that are created as part of your deployment. The custom job status can be defined to track the successful completion of specific operations.

type customJobStatusReader struct {
    genericStatusReader engine.StatusReader
}

func (j *customJobStatusReader) ReadStatus(ctx context.Context, reader engine.ClusterReader, resource object.ObjMetadata) (*event.ResourceStatus, error) {
    return j.genericStatusReader.ReadStatus(ctx, reader, resource)
}

This code snippet defines how to read the status of custom jobs, allowing you to integrate job monitoring into your overall application health check.

Source: internal/runtime/job_wait.go

Conclusion

By following these steps and utilizing the configuration options available in Timoni, you can effectively monitor your applications in production, providing the necessary visibility and data to maintain application health and performance. Ensure all configurations are well documented in your README.md file to facilitate ease of access and knowledge sharing within your team.

Source: docs/cue/module/custom-resources.md