@@ -35,8 +35,12 @@ def _convert_candidates_to_upgrade_infos(candidates):
35
35
changes_dict = collections .defaultdict (lambda : collections .defaultdict (int ))
36
36
37
37
for candidate in candidates :
38
+ # The 'now' archive only shows that packages are not installed. We tend
39
+ # to filter the candidates on those kinds of conditions before reaching
40
+ # here so here we don't want to include this information in order to
41
+ # reduce noise in the data.
38
42
origins = sorted (
39
- {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins }
43
+ {f"{ o .origin } :{ o .codename } /{ o .archive } " for o in candidate .origins if o . archive != 'now' }
40
44
)
41
45
changes_dict ["," .join (origins )][candidate .architecture ] += 1
42
46
@@ -101,6 +105,17 @@ def _write_autoremove_pending(registry, cache):
101
105
g .set (len (autoremovable_packages ))
102
106
103
107
108
+ def _write_installed_packages_per_origin (registry , cache ):
109
+ installed_packages = {p .candidate for p in cache if p .is_installed }
110
+ per_origin = _convert_candidates_to_upgrade_infos (installed_packages )
111
+
112
+ if per_origin :
113
+ g = Gauge ('apt_installed_per_origin' , "Numberof ppt packages installed per origin." ,
114
+ ['origin' , 'arch' ], registry = registry )
115
+ for o in per_origin :
116
+ g .labels (o .labels ['origin' ], o .labels ['arch' ]).set (o .count )
117
+
118
+
104
119
def _write_cache_timestamps (registry ):
105
120
g = Gauge ('apt_package_cache_timestamp_seconds' , "Apt update last run time." , registry = registry )
106
121
apt_pkg .init_config ()
@@ -134,6 +149,7 @@ def _main():
134
149
_write_held_upgrades (registry , cache )
135
150
_write_obsolete_packages (registry , cache )
136
151
_write_autoremove_pending (registry , cache )
152
+ _write_installed_packages_per_origin (registry , cache )
137
153
_write_cache_timestamps (registry )
138
154
_write_reboot_required (registry )
139
155
print (generate_latest (registry ).decode (), end = '' )
0 commit comments