1. Monitoring AI Training Jobs with Grafana Data Source on Prometheus


    To accomplish the goal of monitoring AI training jobs using Grafana with a Prometheus data source, we will create an infrastructure that consists of the following components:

    1. A Prometheus instance to gather metrics from the AI training jobs. Prometheus is an open-source systems monitoring and alerting toolkit that is widely used for gathering metrics from various systems.
    2. A Grafana instance to visualize the metrics collected by Prometheus. Grafana is an open-source platform for monitoring and observability that supports various data sources including Prometheus.

    We will be using Pulumi to provision the necessary cloud resources for setting up Prometheus and Grafana. The following Pulumi program is structured to:

    • Set up a Prometheus server that scrapes metrics.
    • Set up a Grafana instance and configure it to use Prometheus as a data source.
    • Ensure that the Grafana data source is correctly configured to link with the Prometheus server.

    Let's begin by creating the Prometheus and Grafana instances, and then configure Grafana to use Prometheus as its data source.

    import pulumi import pulumi_grafana as grafana import pulumi_aws as aws import pulumi_awsx as awsx # Create a VPC for our resources. vpc = awsx.ec2.Vpc("my-vpc") # Create security groups for Prometheus and Grafana. # Assuming that both Prometheus and Grafana are deployed within an AWS environment. prometheus_sg = aws.ec2.SecurityGroup('prometheus-sg', description='Allow inbound traffic on port 9090 for Prometheus', vpc_id=vpc.id, ingress=[ {'protocol': 'tcp', 'from_port': 9090, 'to_port': 9090, 'cidr_blocks': [""]} ] ) grafana_sg = aws.ec2.SecurityGroup('grafana-sg', description='Allow inbound traffic on port 3000 for Grafana', vpc_id=vpc.id, ingress=[ {'protocol': 'tcp', 'from_port': 3000, 'to_port': 3000, 'cidr_blocks': [""]} ] ) # Launch Prometheus instance; replace this with the actual way you want to deploy Prometheus. prometheus_instance = aws.ec2.Instance('prometheus-instance', instance_type='t3.micro', vpc_security_group_ids=[prometheus_sg.id], ami='ami-123456', # Placeholder for the correct Prometheus AMI ID. subnet_id=vpc.public_subnet_ids[0] ) # Export the Prometheus instance IP to use as the data source in Grafana. prometheus_ip = prometheus_instance.public_ip # Launch Grafana instance; replace this with the actual way you want to deploy Grafana. grafana_instance = aws.ec2.Instance('grafana-instance', instance_type='t3.micro', vpc_security_group_ids=[grafana_sg.id], ami='ami-654321', # Placeholder for the correct Grafana AMI ID. subnet_id=vpc.public_subnet_ids[0] ) # Create a Grafana data source for Prometheus. grafana_data_source = grafana.DataSource('prometheus-datasource', name='AI Training Metrics', type='prometheus', url=prometheus_ip.apply(lambda ip: f'http://{ip}:9090'), access_mode='proxy', is_default=True ) # Export the Grafana instance IP for accessing the dashboard. grafana_ip = grafana_instance.public_ip pulumi.export('prometheus_ip', prometheus_ip) pulumi.export('grafana_ip', grafana_ip)

    In this program, we define a VPC and two security groups to ensure Prometheus and Grafana can communicate over the network and that Prometheus can scrape metrics from your AI training jobs. Replace 'ami-123456' and 'ami-654321' with the actual AMI ids for the Prometheus and Grafana instances, respectively.

    Next, we create two EC2 instances in the public subnet of the VPC; one for the Prometheus server and another for the Grafana server. If you are running Prometheus in a different environment or using a managed service, you need to replace this part with an appropriate setup.

    Finally, we configure a data source in Grafana which will connect to the Prometheus instance using the IP we extracted from the instance details. The apply method is used to ensure that the consumption of the IP address is handled correctly as output from the Prometheus instance instantiation.

    After running this Pulumi program, you will get the IP addresses of both the Prometheus and Grafana instances. You can use these IPs to access your Prometheus and Grafana web interfaces.

    Note: This example presupposes that your environment is properly configured to run Pulumi with AWS credentials, and that you're comfortable modifying this program to match your specific requirements and deploying Prometheus and Grafana into your environment.