Configurer les recommandations de types de machines
Cette page explique comment afficher et modifier la configuration de vos recommandations de type de machine. Vous pouvez modifier les types de machines recommandés afin que les recommandations générées n'incluent que les séries de machines de votre choix.
Vous pouvez également modifier les métriques utilisées pour générer des recommandations de mémoire afin d'améliorer leur précision. Les modifications apportées à la configuration sont appliquées au niveau du projet.
Si ce n'est pas déjà fait, configurez l'authentification.
L'authentification est le processus permettant de valider votre identité pour accéder aux services et aux API Trusted Cloud by S3NS .
Pour exécuter du code ou des exemples depuis un environnement de développement local, vous pouvez vous authentifier auprès de Compute Engine en sélectionnant l'une des options suivantes :
Ce rôle prédéfini contient les autorisations requises pour modifier les recommandations de type de machine. Pour connaître les autorisations exactes requises, développez la section Autorisations requises :
Autorisations requises
Les autorisations suivantes sont requises pour modifier les recommandations de type de machine :
Affichez la configuration de la recommandation de type de machine :
recommender.computeInstanceMachineTypeRecommenderConfig.get
dans le projet.
Modifiez la configuration de la recommandation de type de machine :
recommender.computeInstanceMachineTypeRecommenderConfig.update
sur le projet
Vous pouvez obtenir la configuration actuelle des recommandations de type de machine pour votre projet à l'aide de Google Cloud CLI.
gcloud
Pour obtenir les paramètres de configuration actuels, utilisez la commande gcloud beta recommender recommender-config describe et utilisez google.compute.instance.MachineTypeRecommender comme ID de l'outil de recommandation :
Si vous souhaitez enregistrer la configuration dans un fichier local pour pouvoir la modifier et l'importer ultérieurement, exécutez la commande suivante :
La configuration vous permet de personnaliser les paramètres suivants :
preferred_machine_types : recommandations de types de machines que vous recevez.
memory_metrics : comment les métriques de mémoire sont utilisées pour générer des recommandations.
Options pour les recommandations de types de machines
Vous pouvez spécifier les types de machines pour lesquels vous souhaitez recevoir des recommandations en définissant le paramètre preferred_machine_types sur l'une des valeurs suivantes :
DEFAULT : la valeur par défaut est STANDARD_AND_CUSTOM.
STANDARD_AND_CUSTOM : recommande la meilleure correspondance parmi les types de machines standards et personnalisés.
STANDARD_ONLY : recommande la meilleure correspondance parmi les types de machines standards uniquement.
Options pour les recommandations de mémoire
Pour les métriques de mémoire utilisées pour générer les recommandations, vous pouvez définir les valeurs suivantes :
MEMORY_METRICS_DEFAULT : utilisez les métriques par défaut pour générer des recommandations.
MEMORY_METRICS_ALL : utilisez toutes les métriques disponibles pour générer des recommandations.
MONITORING_AGENT_ONLY : n'utilisez que les métriques collectées par l'agent Ops Cloud Monitoring.
Si vous n'utilisez pas l'agent Ops et que vous préférez ne pas recevoir de recommandations concernant la mémoire, utilisez la valeur MEMORY_AGENT_ONLY pour les désactiver.
Pour obtenir des recommandations plus précises sur l'utilisation de la mémoire, utilisez l'agent Ops.
Mettre à jour la configuration d'un projet
Pour mettre à jour la configuration de vos recommandations de types de machines, modifiez les valeurs de configuration et importez la nouvelle configuration pour votre projet.
Vous pouvez modifier les types de machines préférés, les métriques de mémoire utilisées pour les recommandations, ou les deux valeurs dans la même requête.
Une fois la nouvelle configuration importée, la prise en compte de la modification prend environ 48 heures. Pendant ce temps, toutes les recommandations générées utilisent la configuration précédente.
ZONE : zone pour laquelle vous souhaitez obtenir la configuration actuelle.
LOCAL_FILE_PATH_AND_NAME : chemin d'accès au fichier JSON contenant la configuration actuelle.
ETAG : valeur etag de la configuration actuelle.
Vous trouverez cette valeur dans le résultat de la commande précédente.
Dans votre fichier de configuration, spécifiez uniquement l'objet recommenderGenerationConfig avec les paramètres de configuration mis à jour. Si vous avez enregistré la configuration dans un fichier local, assurez-vous de copier la valeur etag, puis supprimez tous les champs, à l'exception de la valeur recommenderGenerationConfig.
Par exemple, pour obtenir des recommandations avec des types de machines standards uniquement, utilisez le fichier de configuration suivant :
Si la commande aboutit, elle renvoie un corps de réponse semblable à celui-ci, qui indique la nouvelle configuration avec les paramètres que vous venez de modifier.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/19 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/19 (UTC)."],[[["\u003cp\u003eThis page guides users on how to customize machine type recommendations at the project level, allowing them to control which machine series are suggested and how memory metrics are used in generating these recommendations.\u003c/p\u003e\n"],["\u003cp\u003eTo modify machine type recommendations, users need the "Compute Recommender Admin" IAM role, which grants the necessary permissions to view and update the recommendation configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration of machine type recommendations involves three main steps: retrieving the current configuration in JSON format, editing this configuration to specify preferred machine types and memory metrics, and uploading the updated file.\u003c/p\u003e\n"],["\u003cp\u003eUsers can specify their preferences for machine type recommendations, choosing between standard and custom types, or standard types only, and can also define how memory metrics are utilized, even opting to rely solely on the Cloud Monitoring Ops Agent or disabling memory recommendations.\u003c/p\u003e\n"],["\u003cp\u003eAfter uploading a new configuration, it takes approximately 48 hours for the changes to take effect, and during this time, the system will continue to use the previous settings for generating any recommendations.\u003c/p\u003e\n"]]],[],null,["*** ** * ** ***\n\n|\n| **Preview**\n|\n|\n| This product or feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA products and features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page describes how to view and modify the configuration of your machine\ntype recommendations. You can modify which machine types are recommended,\nso the generated recommendations only include your preferred machine series.\nYou can also change the metrics used to generate memory recommendations to\nimprove the accuracy of the recommendations. The changes to the configuration\nare applied at the project level.\n\nFor more information about machine type recommendations, see\n[Apply machine type recommendations for VMs](/compute/docs/instances/apply-machine-type-recommendations-for-instances).\n\nBefore you begin\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\nRequired roles\n\n\nTo get the permissions that\nyou need to modify machine type recommendations,\n\nask your administrator to grant you the\n\n\n[Compute Recommender Admin](/iam/docs/roles-permissions/recommender#recommender.computeAdmin) (`roles/recommender.computeAdmin`)\nIAM role on your project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains\n\nthe permissions required to modify machine type recommendations. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\nRequired permissions\n\nThe following permissions are required to modify machine type recommendations:\n\n- View the machine type recommendation configuration: `recommender.computeInstanceMachineTypeRecommenderConfig.get` on the project\n- Modify the machine type recommendation configuration: `recommender.computeInstanceMachineTypeRecommenderConfig.update` on the project\n\n\nYou might also be able to get\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nConfigure your recommendations\n\nTo configure your machine type recommendations, perform the following steps:\n\n1. [Get the current configuration](#get_current_configuration) to obtain the JSON file of the configuration.\n2. Edit the configuration file in JSON format.\n3. [Upload the new configuration file](#update_configuration) to apply the changes.\n\nGet the current configuration\n\nYou can obtain the current configuration for machine type recommendations for\nyour project by using the Google Cloud CLI. \n\ngcloud\n\nTo get the current configuration parameters, use the\n[`gcloud beta recommender recommender-config describe` command](/sdk/gcloud/reference/beta/recommender/recommender-config/describe)\nand use `google.compute.instance.MachineTypeRecommender` as the\nRecommender ID: \n\n```\ngcloud beta recommender recommender-config describe google.compute.instance.MachineTypeRecommender \\\n --project=PROJECT_ID \\\n --location=ZONE\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your project.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone for which you want to obtain the current configuration.\n\nThe command returns the recommender configuration, including the modifiable\nsubfields `preferred_machine_types` and `memory_metrics`. \n\n```\n{\n \"name\": \"projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.instance.MachineTypeRecommender/config\",\n \"recommenderGenerationConfig\": {\n \"params\": {\n \"preferred_machine_types\": \"STANDARD_AND_CUSTOM\",\n \"memory_metrics\": \"MONITORING_AGENT_ONLY\"\n }\n },\n \"etag\": \"\\\"2f3c9b65cda6a4ba\\\"\",\n \"updateTime\": \"2024-08-20T04:41:15.330351Z\"\n}\n```\n\nIf you want to save the configuration to a local file, so you can edit it\nand upload it later, run the following command: \n\n```\ngcloud beta recommender recommender-config describe \\\n google.compute.instance.MachineTypeRecommender \\\n --project=PROJECT_ID \\\n --location=ZONE \u003e LOCAL_FILE_PATH_AND_NAME\n```\n\nEdit the recommendation configuration\n\nThe configuration lets you customize the following parameters:\n\n- `preferred_machine_types`: The machine types recommendations that you receive.\n- `memory_metrics`: How memory metrics are used to generate recommendations.\n\nOptions for machine types recommendations\n\nYou can specify which machine types recommendations you get by changing\nthe `preferred_machine_types` setting to one of the following values:\n\n- `DEFAULT`: The default value is `STANDARD_AND_CUSTOM`.\n- `STANDARD_AND_CUSTOM`: Recommends the best match from standard and custom machine types.\n- `STANDARD_ONLY`: Recommends the best match from standard machine types only.\n\nOptions for memory recommendations\n\nFor the memory metrics used to generate the recommendations, you can set\nthe following values:\n\n- `MEMORY_METRICS_DEFAULT`: Use the default metrics to generate recommendations.\n- `MEMORY_METRICS_ALL`: Use all the available metrics to generate recommendations.\n- `MONITORING_AGENT_ONLY`: Use only metrics collected by the Cloud Monitoring Ops Agent.\n- If you don't use the Ops Agent, and prefer not to receive memory recommendations, use the `MEMORY_AGENT_ONLY` value to disable the recommendations.\n\nTo get more accurate recommendations about memory usage, use the\n[Ops Agent](/monitoring/agent/ops-agent).\n\nUpdate the configuration for a project\n\nTo update the configuration of your machine type recommendations, modify the\nconfiguration values and upload the new configuration for your project.\nYou can change the preferred machine types, the memory metrics used for\nrecommendations, or both values in the same request.\n\nAfter you upload the new configuration, it takes approximately 48 hours for it\nto take effect. Until that time, any generated recommendations use the previous\nconfiguration. \n\ngcloud\n\nTo update the configuration parameters, use the\n[`gcloud beta recommender recommender-config update` command](/sdk/gcloud/reference/beta/recommender/recommender-config/update)\nand use `google.compute.instance.MachineTypeRecommender` as the\nRecommender ID: \n\n```\ngcloud beta recommender recommender-config update google.compute.instance.MachineTypeRecommender\\\n --project=PROJECT_ID \\\n --location=ZONE \\\n --config-file=LOCAL_FILE_PATH_AND_NAME \\\n --etag=ETAG\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your project.\n- \u003cvar translate=\"no\"\u003eZONE\u003c/var\u003e: the zone for which you want to obtain the current configuration.\n- \u003cvar translate=\"no\"\u003eLOCAL_FILE_PATH_AND_NAME\u003c/var\u003e: the path to the JSON file with the current configuration.\n- \u003cvar translate=\"no\"\u003eETAG\u003c/var\u003e: the etag value of the current configuration. You can find this value in the output of the [previous command](#get_current_configuration).\n\nIn your configuration file, specify only the `recommenderGenerationConfig`\nobject with the updated configuration parameters. If you saved the\nconfiguration to a local file, make sure you copy the `etag` value, then\nremove all the fields except the `recommenderGenerationConfig` value.\n\nFor example, to get recommendations with standard machine types only,\nuse the following configuration file: \n\n```\n{\n \"params\": {\n \"preferred_machine_types\": \"STANDARD_ONLY\"\n }\n}\n```\n\nIf the command is successful, it returns a response body similar to the\nfollowing, showing the new configuration with the parameters you just\nmodified. \n\n```\n{\n \"name\": \"projects/PROJECT_ID/locations/ZONE/recommenders/google.compute.instance.MachineTypeRecommender/config\",\n \"recommenderGenerationConfig\": {\n \"params\": {\n \"preferred_machine_types\": \"STANDARD_ONLY\"\n }\n },\n \"etag\": \"\\\"1245f9435cd01ea8\\\"\",\n \"updateTime\": \"2024-08-20T05:00:05Z\"\n}\n```\n| **Note:** the `etag` value changes from the previous configuration. You must use the new value if you update the configuration again.\n\nWhat's next\n\n- Learn how to [Apply machine type recommendations to instances](/compute/docs/instances/apply-machine-type-recommendations-for-instances).\n- Learn how to [Apply machine type recommendations to managed instance groups](/compute/docs/instance-groups/apply-machine-type-recommendations-managed-instance-groups)."]]