-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23-usage-monitoring.sh
More file actions
executable file
·84 lines (69 loc) · 2.23 KB
/
23-usage-monitoring.sh
File metadata and controls
executable file
·84 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Example 23: API Usage Monitoring
# Demonstrates checking API character usage and quota
set -e # Exit on error
echo "=== DeepL CLI Example 23: API Usage Monitoring ==="
echo
# Check if API key is configured
if ! deepl auth show &>/dev/null; then
echo "❌ Error: API key not configured"
echo "Run: deepl auth set-key YOUR_API_KEY"
exit 1
fi
echo "✓ API key configured"
echo
# Example 1: Check initial API usage
echo "1. Check current API usage statistics"
deepl usage
echo
# Example 2: Perform some translations
echo "2. Perform sample translations"
echo " Translating texts..."
deepl translate "Hello, world!" --to es >/dev/null
deepl translate "Good morning" --to fr >/dev/null
deepl translate "How are you today?" --to de >/dev/null
deepl translate "This is a longer text that will consume more characters from the API quota." --to ja >/dev/null
echo " ✓ Translations completed"
echo
# Example 3: Check updated usage
echo "3. Check updated API usage (after translations)"
deepl usage
echo
# Example 4: Demonstrate usage monitoring in scripts
echo "4. Usage monitoring in automated scripts"
echo " Example: Check if quota is running low before batch operations"
echo
cat << 'EOF'
# Bash script snippet for quota checking:
if deepl usage 2>&1 | grep -q "80.*%"; then
echo "⚠️ Warning: API quota above 80%"
echo "Consider pausing translations or upgrading plan"
fi
EOF
echo
echo "5. Usage in JSON format (for scripting):"
deepl usage --format json
echo
echo "6. Usage in text format:"
deepl usage --format text
echo
echo "=== Usage monitoring example completed! ==="
echo
echo "💡 Usage monitoring benefits:"
echo " - Track character consumption"
echo " - Avoid exceeding quota limits"
echo " - Plan upgrades based on usage patterns"
echo " - Monitor API costs"
echo
echo "📊 Usage tips:"
echo " - Check usage regularly in production"
echo " - Set up alerts when usage exceeds 80%"
echo " - Use caching to reduce API calls"
echo " - Monitor usage before large batch operations"
echo
echo "⚠️ Account limits:"
echo " - Free tier: typically 500,000 chars/month"
echo " - Pro accounts: varies by subscription"
echo " - Usage resets monthly"
echo
echo "=== All examples completed successfully! ==="