

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Monitoraggio delle statistiche di utilizzo tramite l'API Amazon SES
<a name="monitor-sending-activity-api"></a>

L'API Amazon SES fornisce l'operazione `GetSendStatistics`, che restituisce informazioni sull'utilizzo del servizio. Ti consigliamo di controllare regolarmente le statistiche di invio, per poter apportare le necessarie modifiche.

Quando chiami l'operazione `GetSendStatistics`, ricevi un elenco di punti dati che rappresentano le ultime due settimane dell'attività di invio. Ogni punto dati in questo elenco rappresenta 15 minuti di attività e contiene le informazioni indicate di seguito per tale periodo:
+ numero di mancati recapiti permanenti;
+ numero di reclami;
+ numero di tentativi di consegna (corrispondente al numero di e-mail che hai inviato);
+ numero di tentativi di invio rifiutati;
+ timestamp per il periodo di analisi.

Per una descrizione completa dell'operazione `GetSendStatistics`, vedere la [Documentazione di riferimento per le API di Amazon Simple Email](https://docs.aws.amazon.com/ses/latest/APIReference/GetSendStatistics.html).

In questa sezione vengono trattati gli argomenti seguenti:
+ [Chiamata dell'operazione `GetSendStatistics` API utilizzando AWS CLI](#monitor-sending-activity-api-cli)
+ [Chiamata dell'operazione `GetSendStatistics` a livello di programmazione](#monitor-sending-activity-api-sdk)

## Chiamata dell'operazione `GetSendStatistics` API utilizzando AWS CLI
<a name="monitor-sending-activity-api-cli"></a>

Il modo più semplice per chiamare l'operazione API `GetSendStatistics` consiste nell'usare [AWS Command Line Interface](https://aws.amazon.com/cli) (AWS CLI).

**Per richiamare l'operazione `GetSendStatistics` API utilizzando il AWS CLI**

1. Se non lo hai già fatto, installa l' AWS CLI. Per ulteriori informazioni, vedere "[Installazione di AWS Command Line Interface" nella](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) *Guida AWS Command Line Interface per l'utente*.

1. Se non l'hai ancora fatto, configurali AWS CLI per utilizzare le tue AWS credenziali. Per ulteriori informazioni, vedere "[Configurazione di AWS CLI" nella](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html) Guida per l'*AWS Command Line Interface utente*.

1. Alla riga di comando esegui il comando riportato di seguito:

   ```
   aws ses get-send-statistics
   ```

   Se AWS CLI è configurato correttamente, viene visualizzato un elenco di statistiche di invio in formato JSON. Ogni oggetto JSON include le statistiche di invio aggregate per un periodo di 15 minuti.

## Chiamata dell'operazione `GetSendStatistics` a livello di programmazione
<a name="monitor-sending-activity-api-sdk"></a>

È inoltre possibile richiamare l'`GetSendStatistics`operazione utilizzando il AWS SDKs. Questa sezione include esempi di codice AWS SDKs per Go, PHP, Python e Ruby. Scegli uno dei collegamenti seguenti per visualizzare gli esempi di codice per ogni linguaggio:
+ [Esempio di codice per AWS SDK per Go](#code-example-getsendstatistics-golang)
+ [Esempio di codice per AWS SDK per PHP](#code-example-getsendstatistics-php)
+ [Esempio di codice per AWS SDK per Python (Boto)](#code-example-getsendstatistics-python)
+ [Esempio di codice per AWS SDK per Ruby](#code-example-getsendstatistics-ruby)

**Nota**  
Questi esempi di codice presuppongono che sia stato creato un file di credenziali AWS condiviso che contiene l'ID della chiave di AWS accesso, la chiave di accesso AWS segreta e la regione preferita. AWS Per ulteriori informazioni, consulta l'argomento relativo ai [file di configurazione e delle credenziali](https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html).

### Chiamata `GetSendStatistics` utilizzando il AWS SDK per Go
<a name="code-example-getsendstatistics-golang"></a>

```
 1. package main
 2.     
 3. import (
 4.     "fmt"
 5.     
 6.     //go get github.com/aws/aws-sdk-go/...
 7.     "github.com/aws/aws-sdk-go/aws"
 8.     "github.com/aws/aws-sdk-go/aws/session"
 9.     "github.com/aws/aws-sdk-go/service/ses"
10.     "github.com/aws/aws-sdk-go/aws/awserr"
11. )
12.     
13. const (
14.     // Replace us-west-2 with the AWS Region you're using for Amazon SES.
15.     AwsRegion = "us-west-2"
16. )
17.     
18. func main() {
19.     
20.     // Create a new session and specify an AWS Region.
21.     sess, err := session.NewSession(&aws.Config{
22.         Region:aws.String(AwsRegion)},
23.     )
24.     
25.     // Create an SES client in the session.
26.     svc := ses.New(sess)
27.     input := &ses.GetSendStatisticsInput{}
28.     
29.     result, err := svc.GetSendStatistics(input)
30.     
31.     // Display error messages if they occur.
32.     if err != nil {
33.         if aerr, ok := err.(awserr.Error); ok {
34.             switch aerr.Code() {
35.             default:
36.                 fmt.Println(aerr.Error())
37.             }
38.         } else {
39.             // Print the error, cast err to awserr.Error to get the Code and
40.             // Message from an error.
41.             fmt.Println(err.Error())
42.         }
43.         return
44.     }
45.     
46.     fmt.Println(result)
47. }
```

### Chiamata `GetSendStatistics` utilizzando il AWS SDK per PHP
<a name="code-example-getsendstatistics-php"></a>

```
 1. <?php
 2. 
 3. // Replace path_to_sdk_inclusion with the path to the SDK as described in 
 4. // http://docs.aws.amazon.com/aws-sdk-php/v3/guide/getting-started/basic-usage.html
 5. define('REQUIRED_FILE','path_to_sdk_inclusion');
 6.                                                   
 7. // Replace us-west-2 with the AWS Region you're using for Amazon SES.
 8. define('REGION','us-west-2'); 
 9. 
10. require REQUIRED_FILE;
11. 
12. use Aws\Ses\SesClient;
13. 
14. $client = SesClient::factory(array(
15.     'version'=> 'latest',     
16.     'region' => REGION
17. ));
18. 
19. try {
20.      $result = $client->getSendStatistics([]);
21. 	 echo($result);
22. } catch (Exception $e) {
23.      echo($e->getMessage()."\n");
24. }
25. 
26. ?>
```

### Chiamata `GetSendStatistics` utilizzando il AWS SDK per Python (Boto)
<a name="code-example-getsendstatistics-python"></a>

```
 1. import boto3 #pip install boto3
 2. import json
 3. from botocore.exceptions import ClientError
 4. 
 5. client = boto3.client('ses')
 6. 
 7. try:
 8.     response = client.get_send_statistics(
 9. )
10. except ClientError as e:
11.     print(e.response['Error']['Message'])
12. else:
13.     print(json.dumps(response, indent=4, sort_keys=True, default=str))
```

### Chiamata `GetSendStatistics` utilizzando il AWS SDK per Ruby
<a name="code-example-getsendstatistics-ruby"></a>

```
 1. require 'aws-sdk' # gem install aws-sdk
 2. require 'json'
 3. 
 4. # Replace us-west-2 with the AWS Region you're using for Amazon SES.
 5. awsregion = "us-west-2"
 6. 
 7. # Create a new SES resource and specify a region
 8. ses = Aws::SES::Client.new(region: awsregion)
 9. 
10. begin
11. 
12.   resp = ses.get_send_statistics({
13.   })
14.   puts JSON.pretty_generate(resp.to_h)
15. 
16. # If something goes wrong, display an error message.
17. rescue Aws::SES::Errors::ServiceError => error
18.   puts error
19. 
20. end
```